Ofcourse - this is the main reasons why I would like to have Velocity introduced in hbm2java.
* Use a two layered approach. Generate an (abstract) base object (which
never gets changed) and a subclass object (which gets extended with business
logic). This allows easy regeneration while preserving custom changes. One
simple way of integrating this into the development process is for the generator
to check to see if a file is read-only. If it is, it gets replaced. That
way, generated files get replaced and custom files are preserved.
[/qoute]
This is already possible in hbm2java. Remember that this should most definitly not be the default for codegeneration - it should only be needed to introduce the abstract class if extra biz-logic is needed. Look at the <meta> support.
[qoute]
* Allow use plugins. Velocity can use any java class as a generation tool.
This allows users to extend templates very easily. For example, you can
register a tool as follows:
$pluginUtil.addPlugin("myplugin","au.com....MyPlugin")
and then call a method on it as follows:
$myplugin.convertString("AaAaAa")
You can also get the tools to manipulate the data model.
[/qoute]
hbm2java already has some support for this. You can register you own render - actually you could make a VelocityRender and use the current "less nice" data model.
Quote:
* Use ant to start the generator (either as a task or as a target). This
solves many classpath problems, etc and removes the need for (ugly) .bat
files.
hbm2java already has an ant target.
Quote:
* Create a clean data model. For example, instead of generating imports
on the fly, create a list of imports and store the in a list. Then the template
designer can simply iterate thru them. They can sort them, replace them,
add to them, etc.
[/qoute]
The model needs a refactor for sure - but I'm still considering how it should be - It would again be great if we somehow could utilize the core's model....but that is probably hard, so we should probably instead think how we can make a model that is highly adaptable to new features.
Quote:
* Uses may want to implement hashcode, equals, toString, etc in their
own way and with their own rules. Templates and a simple data model allow
them to do this.
Quote:
Own equals()/hashcode() method is biz-logic ;) Just use the current features of generating an abstract base class.
hbm2java furthermore has some direct support (via <meta>) to let you specify what and what is not included in the equals generation.
Quote:
* Using existing software reduces the maintenance costs, increases the
development skill base, and speeds up development.
* You also get logiing, event listeners, etc when generating (all for
free)
[/qoute]
Completely true - also the reason I really would like we could keep improve the hbm2java tool and utilize that in the complete toolset (middlegen, schemaexport, xdoclet etc.)
And all improvements above is welcome.
/max