Wednesday 1 August 2012

Using a template engine to create DAOs, SQL maps

I am a fan of iBatis / MyBatis but no one likes creating these CRUD based artifacts by hand for each table in their database!  Tools exist which code generate the CRUD stuff for you such as iBator, which I personally don't like, as you have no control over what the actual generator content looks like.

Something which could be quite nice would be to have code which parses a database schema, creates a small in memory model and using a template engine such as FreeMarker / Velocity etc generates your application DAO source files etc.  I did a quick search on google and it seems I'm not the only one who has done this ...

http://dhartford.blogspot.co.uk/2008/07/freemarker-camelcase-to-underscore.html

This could be programmed fairly quickly from scratch, a better solution may be to extend the existing iBator code generator...

No comments: