atom feed5 messages in org.codehaus.groovy.user[groovy-user] Sql/DataSet - missing s...
FromSent OnAttachments
Witold SzczerbaJan 29, 2009 3:41 pm 
Witold SzczerbaJan 30, 2009 12:30 am.java
Witold SzczerbaJan 30, 2009 12:35 am 
Witold SzczerbaJan 30, 2009 12:57 am 
Paul KingJan 31, 2009 5:27 am 
Subject:[groovy-user] Sql/DataSet - missing support for batch inserts/updates
From:Witold Szczerba (pljo@gmail.com)
Date:Jan 29, 2009 3:41:37 pm
List:org.codehaus.groovy.user

Hi there,

I am evaluating Groovy and it's Sql/DataSet classes for a Java EE application. I found that it was designed without any performance considerations (same applies to JPA). Yes, I saw most recent 1.6 RC2 version of Sql with cached statements, but implementations shows clearly it was an afterthought. The Sql class is growing (code smell), DataSet (which inherits from Sql) is unable to take advantage of that new cache and the performance is still not that good (for example: to reuse cache, Sql's methods have to rebuild the query (a String) from scratch on every method call and only after that statement can be looked up in the cache).

Ok, back to DataSet, for example: when I create: def person = sql.dataSet('person') and in loop issue: person.add(....) then for every single iteration, the DataSet object creates preparedStatement from scratch! It has REALLY COOL solutions for building JDBC PreparedStatements (finally no more stupid SQL syntax with collections of column names and question marks), but there is no way for such a statemnt to be reused, not to mention about no way of using addbatch() and executebatch() methods of preparedStatements.

The bad thing is that DataSet is created without extensibility in mind, so there is no simple way to encapsulate or subclass it to add extra/missing features (like to ask DataSet to create and setup a statement and give it back, so I could batch/execute it by my own).

Are you guys satisfied with DataSet? For me it looks like that was created to make a good impression on newcomers. However as far as I am concerned, there would be no big deal refactoring it, so it could be used in many more circumstances (like for single/batch inserts, updates/removes). Now all I can do is to create a new "my" DataSet class by copying the original one and reimplementing it so I could add new features.

Another cool feature could be to add an option for using JavaBeans (for example cool "GroovyBeans" implementation) instead of Map for passing arguments.

What do you think?