db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject [Proposal] A general-purpose code generation framework for torque 4
Date Sun, 08 Nov 2009 18:56:05 GMT

This is a proposal to replace the current torque 3.3 code generator with a
general purpose code generator, which would be developed inside the torque
project.

The torque 3.3 code generator has, in my eyes, the following shortcomings:
- It is not possible to modify the templates locally (i.e. in one place)
and re-use the rest of the template.
- It is very specialized for the torque code. No other code can be
generated using the code generator.

These shortcomings could be overcome if a general-purpose code generator
would be used which supports the exchange of templates, and if the
templates were re-organized such that they are split into smaller pieces.

The proposal includes an own code generator because I did not find one to
fit the needs. Of course, there is the OpenArchitecturware [1] code
generators, but they are rather eclipse-centric and offer no convincing
concept of exchanging templates in a given templates set. For small
code-generation purposes, they are also to heavy-weight in my opinion,
because one has to define a corresponding metamodel for each generation
process.
Also, I've seen quite a few projects who have set up a code generator from
scratch, e.g. myfaces[2]. So there seems to be a need for a easy-to-use
quick-to-setup code-generation solution.

To explore what such a code generator could look like and whether it can be
implemented at all, I have developed such a code generator, with the
intention to include it into torque. The code proposal and a site with the
features and a short introduction can be found here [3]. There is an
associated maven 2 plugin [4].
To prove that this also works for such large templates as the torque,
templates, I have adapted part of the templates to the new generator [5].
And finally, there is a test project [6] to see what is working.

So what would be the ups and downs for the new generator ?
Pro:
- replacement of templates is possible, reusing other not modified
templates (needs to be documented)
- general-purpose, can be used for other code generation tasks
- see the features list in
http://people.apache.org/~tfischer/proposal_torque4_generator/torque-gf/site/
Con
- The "strong coupling" between schema.xml and generator disappears; there
is no explicit model (as in the package
org.apache.torque.engine.database.model in the torque 3.3 generator) which
represents the structure of a schema.xml
- To replace the logic which was in the model, a transformation step was
introduced between reading the model and applying the templates. This
transformation step is quite involved and  would need a good documentation
to be understood.

Of course, it would be possible to achieve the template replacement feature
in the current generator. It just is a lot of work.

What else would the proposal mean
- There would be a replacement for the parts of the generator which are not
code generation: reading schema from the database, executing sql etc.
- A lot of work is still to be done. Currently only mysql/native and
oracle/native work with the standard test cases from the old test project.
External schemata do not work at all.

To try the code, create 4 directories torque-gf, maven-torque-gf-plugin,
templates and test-project and get the respective pom and the source zips
from http://people.apache.org/~tfischer/proposal_torque4_generator/ .Unpack
the zips in all directories and run "maven install" in the first three
directories in the above order. Then modify the file profiles.xml in the
test project and insert the correct info for either mysql or oracle. Run
either "mvn -Poracle test" or "mvn -Pmysql test" in the test project to run
the test project. This will generate the sql and classe, but the tests will
fail the first time because the generated sql files in target/generated-sql
must be executed by hand for now, sorry. Execute these files in the correct
db schema and re-run the test project, now it should work.

If there are problems, please contact me. If there is anything else I could
provide (e.g. a showcase for replacing a template would be nice ?), or if
you have any other comments, please e-mail.

After a discussion, I'll call a vote on this. The choice is either to
incorporate this into torque or this will become a sourceforge project.
There is already too much work in it to throw it away.

        Looking forward to your comments,

             Thomas

[1] http://www.openarchitectureware.org/
[2]
http://svn.apache.org/repos/asf/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-faces-plugin/pom.xml
[3]
http://people.apache.org/~tfischer/proposal_torque4_generator/torque-gf/
[4]
http://people.apache.org/~tfischer/proposal_torque4_generator/maven-torque-gf-plugin/
[5]
http://people.apache.org/~tfischer/proposal_torque4_generator/templates/
[5]
http://people.apache.org/~tfischer/proposal_torque4_generator/templates/


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message