Ejen Logo
 
 Project
                         
News
Download
Developer site
Browse CVS
License (GPL)
 
 Documentation
                         
Introduction
Requirements
Installation
Ejen doc
Ejen API
EJB 1.1 demo
EJB 1.1 doc
 
 Links
                         
Xerces-j
Xalan-j
Ant
JavaCC
JBoss
 
 Contact
                         
Author
 
   
 EJB design concepts
                         
The Ejen EJB 1.1 demonstration produces BMP (Bean Managed Persistence) Entity Beans. It is not only a tool that synchronizes dependent interfaces (home and remote) with existing, written by hands, bean classes. Ejen generates everything, including the full implementation of the bean (see generated classes).

I beleive that the generated beans are very classical (except the use of "values objects"). Fell free to email me any comment or improvement related to this implementation: I will be happy to maintain a set of standard implementation templates (for the JBoss server at least).


 
 Generation process design concepts
                         
Beside this EJB design question, the generation process itself is organized as follow:
  1. A very short configuration file (ejen.xml) gives the names of the tables for which Entity Beans have to be generated. This is the source of the generation process (initial DOM tree used by following filters and templates).

  2. From this configuration file, an XSL stylesheet filter (xsl/fill-metadata.xsl) is used in order to fill all database table metadata (detailled description of the columns, primary-key, indexes). This filter uses, of course, a Java extension (BasicMetaDataConnection) to connect the database and get those matadata.

  3. Using an XSL stylesheet include (xsl/type-mappings.xsl), the above filter fills also HSQLDB specific "SQL to Java" type mappings. If you intend to use another database, this file must be obviously adapted.


  4. For each table mentioned in this filled DOM tree, three XSL stylesheet templates are successively called: xsl/EJB_TABLE_PK.xsl, xsl/EJB_TABLEBean.xsl and xsl/TABLEValues.xsl. Those templates respectively produce a primary key class, a bean class and a "values object" class. Then, for all mentioned tables, the ejb-jar.xml descriptor file is generated, using the xsl/ejb-jar.xsl template. Note that the three above templates use an XSL stylesheet include (xsl/helpers.xsl) for various purposes.


  5. In order to generate home and remote interfaces, the initial source file (ejen.xml) is reloaded and, instead of metadata descriptions, an XSL stylesheet filter (xsl/fill-bean-defintion.xsl) fills, for each table, DOM tree representations of the previoulsy generated beans (only method descriptions). This is acheived by the mean of a special extension (JavaSourceToXML).

  6. Two XSL stylesheet templates are then successively called: xsl/EJB_TABLE.xsl and xsl/EJB_TABLEHome.xsl. They respectively produce a remote interface class and a home interface class. The important thing here is: even if the bean is modified by hands, those two steps may be used in order to synchronized the interfaces with the bean.


  7. Everything is then compiled and archived into a server jar file and a client jar file (same as the server one, without the bean classes and the deployment descriptor). Note that two additional source files are also used here: src/org/ejb/test/EJB_TABLEAbstractBean.java and src/org/ejb/test/JDBCCommand.java. Those two files are not generated but used, without modifications, by the generated beans (only included in the server jar).

The JSP generation (only for testing purposes) is not at all documented here...

Separation lines above represent Ant target separations: "prepare", "generate1", "generate2" and "build" (see the generate.xml file). If you have made important modifications in the generated beans (new or removed findBy methods, for example), you may use the two last targets to synchronized the dependent interfaces and rebuild the jars.

Very important note:
  • If you run again the full generation process, all modifications are just lost: everything will be re-generated (overwriting existing files) without any warning ! This should be obviously improved in the future...


 
 Editing filters and templates
                         
You must, of course, have a good knowledge of XSL. Another tricky thing is just to find a good (and free) editor. You may use, for example, whatever is your system, Jext, Jedit or even JBuilder 6. For Unix systems, Nedit 5.2 is very good and fast and, of course, the famous XEmacs should do it. For Windows systems, I couldn't find anything good except the above Java, platform independent, editors (let me know).

All XML/XSL files used in this demonstration should be carefully documented. I don't have time to do that (and, maybe, I'm definitively to lazy). You will have to learn by yourself: this shouldn't be very difficult with this overview and a good knowledge of XSLT, Java, Ant and the Ejen API documentation. You may also have a look to Ejen sources as well (see Download).


 
 HSQLDB reset (dangerous but useful)
                         
You may want to destroy all created tables: a very fast (but dangerous) way to do that is simply to go to the <JBOSS_HOME>/db/hypersonic directory and delete all default.* files. WARNING: you will "drop" EVERYTHING, even tables that have nothing to do with this demonstration !


 
 Using PostgreSQL instead of the default HSQLDB database (Joseph Rajkumar)
                         
Tested on Platform: Mandrake-Linux-8.0/8.1 and Solaris-2.8 with JBoss-2.4.4_Tomcat-4.0.1 and JBoss-2.4.4_Jetty-3.1.3-1.

Note: there is no sequence support in this PostgreSQL demonstration !

Hopefully you have got ejen to work with the default HSQLDB and you are interested in using PostgreSQL, then this is the document you need to read.

Hopefully you have PostgreSQL server running and you started the "postmaster" with the "-i" option and have a username who is authorised to create databases, tables and add data to the tables.


  1. If you have obtained the sources for PostgreSQL and compiled it yourself after running configure with the --with-java option then you will need to look for a file called "postgresql.jar", in the following directory: under a couple of levels:- postgresql-7.2/src/interfaces/jdbc/jars/postgresql.jar

    You need to copy this file to this directory: <JBOSS_HOME>/jboss/lib/ext/postgresql.jar

  2. Create a database called ejenDB using the command "createdb"

  3. Go to the <EJEN_HOME>/examples/ejb-1.1/bmp-jboss-postgres directory and load the file "db.sql" into your database using:

    psql ejenDB < db.sql

  4. Look under this directory for a file called jboss.jcml.example.

    Make sure that you have the correct database name, database user name and the PostgreSQL server port number. I have just used the default port used by postgreSQL.

    Use this example to modify the actual jboss.jcml used by your JBoss distribution.

  5. Fix xsl/type-settings.xml if you use data types like Date etc.

  6. Then you should be able to do the regular things you did to get ejen to run. Use generate[.bat], and that will create an ear file and drop it into JBOSS's deploy directory.


If you have problems, check the following:

  • Did I put postgresql.jar in the correct directory ?

  • Did I use a recent version of the PostgreSQL JDBC driver ?

  • Do I have the postgres username and password correct ?


 

SourceForge.net Logo