After being harassed for so many years by more or less dynamic SQL statements of all sizes contained in harmless string variables and hitting hardest when not expected, I am now prepared to fight back.
After dealing with DSLs for quite a time theoretically by now one week ago I discussed some of the recurring problems of string based SQL (that even lingers after refactoring the surrounding code) with a colleague and left for my free day.
During the spare spare time I started writing a Java embedded SQL expression language, which I call Jequel. After the first day the foundations were laid. I spend some night hours of the following week refining the language and constantly testing, refactoring and deleting stuff. Now the result is quite concise and I can start showing it to the public. It is far from done but already quite useful.
How does it look like? Not unsurprisingly: Like SQL :)
public void testWhereSql() {
final SqlString sql =
Select(ARTICLE.OID)
.from(ARTICLE, ARTICLE_COLOR)
.where(ARTICLE.OID.eq(ARTICLE_COLOR.ARTICLE_OID)
.and(ARTICLE.ARTICLE_NO.is_not(NULL)));
assertEquals("select ARTICLE.OID" +
" from ARTICLE, ARTICLE_COLOR" +
" where ARTICLE.OID = ARTICLE_COLOR.ARTICLE_OID" +
" and ARTICLE.ARTICLE_NO is not NULL", sql.toString());
}
Having an embedded DSL even in Java which by far not the best fit for it help a lot. You can keep your familiar development environment and get all the stuff you'll never get with plain old SQL strings. I quote from the Advantages list on the project site:
Syntax highlighting
Code completion for tables, fields and keywords
Spell and error checking for tables, fields and keywords
Refactoring participation of fables and fields, through the whole codebase (single source)
On the fly spell checking and error highlighting
Generate table definition during build (CI) process. All code not matching the database schema will fail to compile
Generate Javadoc and other documentation from the enhanced Java schema definition code
and much more.
I set up a
website for the project. Documentation, Source and runtime jars are available. I'd like to ask for comments and feedback on this (fourth) child of mine.
Just have a look and tell me.
After writing the code I saw that there is something similiar in the ruby space (ruby-sequel) but by now I haven't found a comparable project in the Java space.