I work with jQuery+Spring+Hibernate stack a lot. Usually I find myself developing complex interfaces and integrating them all the way down to the complete stack, but sometimes I only have to make simple interfaces that allow CRUD operations on a simple database table. Developing these CRUD interfaces table-wise usually becomes a repetitive mechanical job which could be easily generated by a script as well. Ideally I would like to give table name to the script and it should generate every necessary class from Hibernate entity to the front-end controller (including JSPs).
So here are my questions:
- Is it a good idea to write script in this case? Would it involve too much complexity (apparently I don’t see much of it but may be I am missing some point)?
- What language should be used to write such scripts? (Java seems too heavy for this, I guess a dynamic language should suite better)
P.S. I know Spring Roo does reverse engineering, but I found couple of bottlenecks there.
Lisp-based languages are very popular choices for this kind of code generation because they are dynamic,homoiconic languages that follow the principle that “code is data”.
As a result generating the code according to a specific template to complete a task is generally not difficult – you just write a macro that expands to whatever code you need. A macro is just a regular function with the exception that it runs at compile-time (to generate the required code) rather than at runtime so you don’t even have to learn a different macro language.
For a Java-based stack I’d strongly suggest taking a look at Clojure, which is a great langauge for code generation and “glue code” on the JVM.
Here’s an example of the kind of data DSL that you can create with Clojure : Korma
As you can see, a fairly simple DSL can be used to script pretty complex database interactions. All the necessary boilerplate code gets generated for you behind the scenes: you only need to focus on the business logic.