The Jodd SQL Generator


On the jOOQ blog, we never grow tired of comparing ourselves with other free or commercial SQL builders. One of the most interesting ones that we’ve seen in the past was the MyBatis SQL Statement Builder. The funny thing about some of these approaches is the fact that “typesafety” is understood in terms of merely offering a fluent API.
Jodd is a platform claiming to offer the The Unbearable Lightness of Java. That’s actually a very nice claim that we can only support. So let’s have a look at the unbearable lightness of SQL query building with Jodd’s SQL Generator:

Boy bb = new Boy();
Girl bg = new Girl();

DbSqlBuilder dsb = sql()
     ._("select")      // "select"
     .columnsAll("bb") // "bb.ID, bb.GIRL_ID, bb.NAME"
     .columnsIds("bg") // "bb.NAME, bg.ID"
     ._(" from")       // " from" (hardcoded string)
     .table(bb, "bb")  // "BOY bb"
     .table(bg, "bg")  // ", GIRL bg"
     ._()              // " " (single space)
     .match("bb", bb)  // "(1=1)"  since all bb fields are null
     ._(" and ")       // " and "
     .match("bg", bg); // "(1=1)" since all bg fields are null.

I must say, I’m intrigued! What is your take on Jodd’s SQL building?

Tags: , , ,

5 responses to “The Jodd SQL Generator”

  1. Samuel Rutishauser says :

    It does have a fancy banner web page. But probably it illustrates the point that while sometimes less is more, too little is indeed not enough.

  2. jodder173 says :

    Much better example would be usage of SQL templates (http://jodd.org/doc/db/template-sql.html), not a builder. While builder serves it purpose, it is much, much more developer friendly to use SQL templates. SQL Templates are just convenient string where you can eg refer entities and not real tables etc. It is worth to mention that this is part of DbOom – a mapping tool, so it is not just a simple sql generator. And it happened to be quite enough in real world (when you target one, specific db): you have mapping, and build relations in runtime, and have that all mapped. Similar to iBatis.

    • lukaseder says :

      Hi there, and thanks for the authoritative feedback! Right, I missed the templating functionality in Jodd. I’ll fix that with a follow-up blog post by the end of the year. Is there anything else you’d like me to mention?

      • jodder173 says :

        Depends how long you want to write about it :) Maybe its worth it to mention that the idea behind the template sql (TSql) is to ‘extend’ the sql and introduce entities and shorten some common code. So you still write sql for target database, just easier :)

        Thanx for working on this, let me know if you need more :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,236 other followers

%d bloggers like this: