Showing posts with label groovy. Show all posts
Showing posts with label groovy. Show all posts

Tuesday, February 3, 2009

Simplifying JDBC in DSL fashion

I like these libs, which are way simpler to understand and learn (at least, for simple queries) and much more lightweight than full-blown ORM tools like Hibernate:
  • JaQu, though I can't figure out if it could be downloaded without H2
  • LIQUidFORM, which does its best to look like LINQ
  • And some other LINQ-inspired implementations for Java
To understand what I'm talking about, consider this simple example replacing all that verbose JDBC stuff:
Product p = new Product();
List soldOutProducts =
db.from(p).where(p.unitsInStock).is(0).select();
And yes, I wish you good luck, because I'm afraid, some cool features (closures, etc) which can improve DSL implementation in Java won't be included in JSE 7. That's why I'm looking at Groovy with increasing interest and can't wait to see good IDE support for it.

Update: they actually will include closures in JSE 7! Not looking at Groovy anymore :)

Thursday, January 29, 2009

Cool Groovy feature 2

I can't stop surprising by all that cool language features Groovy provides. I like learning them by example. This time it is calling methods asynchronously in Groovy, part two - using Categories. This is not that easy to implement (though it's easy enough) compared to methodMissing approach, however it lacks all that disadvantages of overriding handlers.

Briefly, it uses closures, and functionality provided by use keyword. I guess it could be improved to make the whole thing less verbose, but right now I have no time to think about it. Tried to do something similar in Java using AspectJ, but stuck due to Java syntax limitations due to absence of closures. Using anonymous classes here and there looks ugly and is not less verbose nor easier to understand than straightforward approach.

I wonder if some kind of closures can be implemented in Java using aspects. Haven't found the solution yet.

Friday, January 23, 2009