Tigerstripe Persistence Layer Generator

JOSIF Main Page | TIP Platform | Tigerstripe Persistence Layer Generator

TIP Eclipse Tigerstripe JPA Persistence Layer Generator

Note: This is an experimental project being built for review in cgallen's sand box

I have created the plugins and maven projects for a maven built Tigerstripe persistence framework which is generated from a tigerstripe model. For more information on Tigestripe see http://www.eclipse.org/tigerstripe/

This is a pre-requisite for automatically generating TIP reference implementations. I am sure you have something like this internally as a Hibernate plugin but this is completely open source and targets JPA rather than just hibernate. The framework generates Data Access objects as EJB3 objects which are tested using OpenEJB as part of the build. Simple test classes are also generated for all of the entities. It is of course a work in progress and still has some rough edges. however enough of it works to show the viability of the project. The main focus of this work has been on getting the basic framework in place. Having done that it should be fairly easy to go back and improve the efficiency of the generated code.

Unfortunately I still have to produce documentation but the following should get you going. The project is in subversion on sourceforge. https://openoss.svn.sourceforge.net/svnroot/openoss/tip/sandbox/cgallen/codegen2/

To guarantee it works, check out all the following modules _separately_ into a new eclipse workspace called C:/ws-ts6 (the links in the maven build are set to this C:/ws-ts6 - you can change them but no guarantees - I need to make it more generic...)

Tigerstripe Plugins

TIPjvtSpecPlugin - Generates java interfaces against the model
TIPejbImplPlugin - Generates a basic JPA persistance layer (data access objects ) and implementation classes for the model along with basic junit tests of each generated DAO EJB.
TIPxmlSpecPlugin - Generates very basic XML - just a placeholder for the TIP WSDL plugin

All of these plugins use Velocity macros as the primary code builders. I decided to stick with Velocity and not go down the route of using external Java classes since it actually proved easier to debug because all of the logic was in one place. We may want to revisit this in a future version of the plugins.

Maven projects for a maven build. Check out each of the following projects separately from the repository and then run mvn eclipse:eclipse in each project directory to allow eclipse to reference the maven library dependencies. N.B. you also need to set M2_REPO in your workspace java path variables (see http://maven.apache.org/guides/mini/guide-ide-eclipse.html).

TIPTestModelBaseProject

Base project - run eclipse clean and eclipse install here to build the overall project. I have used a flat directory structure rather than a hierarchy so that the base project pom can be editied from within eclipse ( see Flat Project Layout description in http://maven.apache.org/guides/mini/guide-ide-eclipse.html )

TIPTestModel

Simple test model used to run tigerstripe and exercise all the features of the plugins within a maven build.
The tigerstripe profile for this project is in /src/TIPImplimentationProfile.wbp and should be loaded before generating the model.
The model contains field references, associations and association classes. Multiplicity is implemented by default using the java Collections framework which can be persisted using JPA. (There is also an option to select Arrays for multiplicity - but this does not work with JPA and only partially with hibernate).

You will see that classes in the test model have names beginning 'Annotated'xxx and 'Unannotated'xxx. The plugins will automatically generate default JPA annotations for the 'Unannotated'xxx artefacts. These have no stereotypes applied. The Annotated artifacts in the test model have stereotypes applied beginning with AT_ xxx which modify the default JPA settings. The main purpose of this feature is to allow JPA anotations to be used to tie the generated object persistence code to a pre existing database which is very important if we are trying to create an implementation tool set for creating production interfaces.
A full set of JPA and EJB stereotypes are provided for in the profile manually generating javax.persistence and javax.ejb @annotations for artifacts in a tigerstripe model. (Note this currently only uses stereotypes and not the Tigerstripe Annotation framework). An AT_ stereotype manually applied to an artifact will always override the default JPA settings. However note that for stereotypes which require a targetEntity (e.g. the AT_ManyToOne stereotype = @ManyToOne annotation ) , the targetEntity must be manually set to match the fully qualified name of the target generated class and this will not change with changes to the model. Normally it is safer not to override the default generation settings until the model is stable since the defaults follow the object names in the model as it changes.

TIPejbImplBaseClasses - Base classes which are extended by the plugin - Currently contains a simple generic DAO based on a design by Christian Bauer see http://blog.hibernate.org/Bloggers/GenericDAOPatternWithJDK50. Having the generic DAO in a seperate package with it's own tests means that it could be easily extended or replaced with a more unsophisticated alternative later. (such as http://code.google.com/p/generic-dao/ or http://code.google.com/p/krank/ ). Also users of the framework may want to link in an existing DAO in their product.

TIPTestModelJvtSpecPackage
maven project to package output from a maven build of the model with the TIPjvtSpecPlugin. The packaging of the interfaces must happen before the packaging of the implementation classes as these are dependencies for the implementation

TIPTestModelEjbImplGenSrcPackage
maven project to package output from a maven build of the model with the TIPejbImplPlugin. This compiles the code and runs the junit tests before packaging in a maven jar in the local m2 repo

TIPTestModelEjbImplTestGenSrcPackage - NOT Used ( placeholder for M1 plugin )

TIPTestModelXmlSpecPackage
maven project to package output from a maven build of the model with the TIPxmlSpecPlugin.

TIPTestModelEjbImplProject - NOT used placeholder for a project which uses and extends the generated library

Hopefully this is enough to get you going.