-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Java Code Generation (some ideas from serial generator)
PostPosted: Thu Aug 28, 2003 7:51 pm 
Beginner
Beginner

Joined: Thu Aug 28, 2003 7:05 pm
Posts: 20
Currently I do a large amount of java code generation at work. We use Velocity
as the engine for the generation. All we did was write a simple java wrapper
around it.

In the last few days, I have started playing with Hibernate and had (a very
quick) look at the (java) code generation program.
Here are some of the ideas for the next version:

* Use velocity and templates. Most organizations have their own java standards.
Generated files need headers, javadoc, adhere to company code standards,
etc. With templates, you can easily change them to suite your needs.

* 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.

* Separate parser, data and template. The generator should be split into
a parser which parses the xml and builds up a data model. This is then placed
in the context and merged into the template. This separation allows for
easy modification and extension of the generator.

* 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.

* 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.

* 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.  

* texen seems a good starting point for a generator (see velocity web
site)

* 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.

* 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)

Let me know what you think about the above ideas.

Gavin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 8:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Most of these ideas are good, and I and Max and others have discussed similar things before.

However, there is quite a lot of work there.

If you want to implement something like this, you are very welcome.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 9:31 pm 
Beginner
Beginner

Joined: Thu Aug 28, 2003 7:05 pm
Posts: 20
Hello,

I have started playing around with the code and refactoring it. I will keep you posted. I was wondering what work is being done at the moment (as I do not want to duplicate effort).

Cheers


Top
 Profile  
 
 Post subject: Re: Java Code Generation (some ideas from serial generator)
PostPosted: Fri Aug 29, 2003 4:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Quote:
* Use velocity and templates. Most organizations have their own java standards.
Generated files need headers, javadoc, adhere to company code standards,
etc. With templates, you can easily change them to suite your needs.


I would love to see this one, but it has been hold back since it requires quite a bit of work to keep up with the core hibernate model - at a period Gavin was putting in new golden features every day.....so until I (or someone else) found a way/time to find a method to keep the codegenerator's model uptodate with features nothing is happening in this area :(

The main problem is to find a good model that can embrace the need for a codegenerator as opposed to the hibernate core. I would e.g. love to use the hibernate parser (or a variant of) it that could run in non-reflection mode so we would could keep the two parsing "modes" easily in sync.

Quote:
* Separate parser, data and template. The generator should be split into
a parser which parses the xml and builds up a data model. This is then placed
in the context and merged into the template. This separation allows for
easy modification and extension of the generator.

* texen seems a good starting point for a generator (see velocity web
site)
Quote:

Ofcourse - this is the main reasons why I would like to have Velocity introduced in hbm2java.

Quote:
* 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. &nbsp;
[/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






_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Java Code Generation (some ideas from serial generator)
PostPosted: Fri Aug 29, 2003 5:23 am 
Newbie

Joined: Fri Aug 29, 2003 5:12 am
Posts: 2
Hello all,
I have a very basic velocity renderer.
It's a kind of hack of hbm2java.
didier


Top
 Profile  
 
 Post subject: Re: Java Code Generation (some ideas from serial generator)
PostPosted: Fri Aug 29, 2003 5:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
dgirard wrote:
Hello all,
I have a very basic velocity renderer.
It's a kind of hack of hbm2java.
didier


Please submit a patch ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Java Code Generation (some ideas from serial generator)
PostPosted: Wed Sep 03, 2003 12:47 pm 
Newbie

Joined: Thu Aug 28, 2003 11:49 am
Posts: 15
Location: Calgary, Alberta, Canada
max wrote:
hbm2java already has an ant target.

What does this look like and where would I find it?


Top
 Profile  
 
 Post subject: Re: Java Code Generation (some ideas from serial generator)
PostPosted: Wed Sep 03, 2003 2:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
schuldar wrote:
max wrote:
hbm2java already has an ant target.

What does this look like and where would I find it?


It is part of the hibernatext - only available in cvs at the moment.
net\sf\hibernate\tool\hbm2java\Hbm2JavaTask

Just use standard ant way of including it in your build files
<hbm2java config="xxx-config.xml">
<classpath ...>

<fileset ...>
</hbm2java>

Just the way you should expect - i think ;)

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.