/entitygen

Start of a List-Detail App Generator for JSF and JPA.

Primary LanguageJavaBSD 2-Clause "Simplified" LicenseBSD-2-Clause

entitygen

This is an attempt to re-create some of the functionality of seam-gen; It consists of two main classes, FromDB and JenGen.

FromDB

FromDB reads the database metadata and writes a skeleton of the Entity POJO.

JenGen

JenGen reads the entity POJO and generates the five artifacts needed for a single-entity JSF list-detail application:

  • ${Entity}Home.java

  • ${Entity}List.java

  • ${Entity}List.xhtml

  • ${Entity}View.xhtml # the Detail page

  • ${Entity}Edit.xhtml

HOWTO

  • Build everything: mvn package assembly:single

  • Install it somplace handy: cp entitygen-0.0.1-SNAPSHOT-jar-with-dependencies.jar ~/lib/entitygen-0.0.1-SNAPSHOT.jar

  • Change directory to where your entity is to be built: cd ~/workspace/myproject

  • Create ~/.db.properties with the details of the JDBC connection;

  • Run FromDB: java -classpath ~/lib/entitygen*.jar entitygen.FromDB dbConnName tableName [ClassName] (or via the fromdb script in my scripts repo)

  • Compile the generated Java classes

  • Run JenGen: java -jar ~/lib/entitygen*.jar target/classes model.MyEntity (or via the entitygen script in my scripts repo)

  • Examine ../entitygenoutput/*

Limitations/TODOs:

  • JenJen assumes you have already coded the Java Entity and it’s on your classpath; if not, use FromDB to generate it.

  • Should have better integration of FromDB and JenGen so you could do it all in one pass. Could use the compiler API to compile FromDB’s output?

  • Uses Field annotations rather than Accessor annotations; should be settable.

  • assumes a single level of inheritance for entities

  • assumes you want to use PrimeFaces UI.

  • assumes you don’t mind having the output stuck in ../entitygenoutput/

  • Does not yet handle relationships

  • Does not yet handle Enums

  • FromDB could do more work analyzing the table.

  • Whatever else I didn’t think of yet.

Some of these limitations will be easier or harder to remove than others. UTSL. Pull Requests welcome.

Pre-requisite for building

Apache Maven for building.

APIs used by this generator:

  • Code generation is done using Apache Velocity; you can edit the templates.

  • If using FromDB ensure your db driver is listed in pom.xml

APIs used by the generated pages at runtime:

  • darwinsys-ee API for EntityHome Another repo of mine; not in Central yet; clone it and do "mvn install" to install in your .m2/repository

  • Apache DeltaSpike Data for EntityList.

Alternative!

The existing Hibernate Tools probably does a better job of some of this, but it’s tied to Ant and/or Eclipse, and mine is a simpler, lower-startup approach. But see http://docs.jboss.org/tools/4.1.x.Final/en/hibernatetools/html_single/index.html and decide before you start.

As a completely alternative way of building the UI part of your application, consider use of MetaWidget, which builds a UI dynamically. It should be a good fit with the DeltaSpike Data UI layer.