Wednesday, May 7, 2008
Middlegen is an open source code generation framework that provides a general-purpose database-driven engine using various tools such as JDBC, Velocity, Ant and XDoclet.
Create a working directory where you install and store all related files. In this tutorial we'll use C:\Java as working directory. If you want to store it somewhere else, then you'll have to replace every occurrence of "C:\Java" throughout the tutorial by the desired directory.
What is Ant?
Apache Ant is a Java-based build tool.Currently, the only way to start Middlegen is from Ant. The middlegen.jar file contains an Ant task you should use to run Middlegen.
Download and install Ant
1.Surf to the Ant download page.
2.Pick the Ant binary (For this tutorial apache-ant-1.6.2 is used)
3.Unzip Ant binary to C:\Java
4.Rename apache-ant-1.6.2 to ant (C:\Java\ant)
5.Install Ant on Windows
Assume Ant is installed in c:\Java\ant\. The following sets up the environment:
6.Run ant in command prompt
Type ant, you should get a msg 'build.xml does not exist!' This means you are ready to use ANT now.
What is the relationship to Hibernate?
The Middlegen design includes a plug-in architecture which facilitates particular aspects of a target system. Existing plugins include, simple java classes, EJB, JDO and now (close to) complete support for Hibernate. The hibernate plugin focuses on the generation of the mapping configuration files. Hibernates' excellent native hbm2java tool can be used to generated the domain classes.
Download and install Middlegen-Hibernate plugin
1.Surf to Middlegen-Hibernate plugin download page
3 Unzip to C:\Java Now it is C:\Java\Middlegen-Hibernate-r5
4.Using command prompt change directory to C:\Java\Middlegen-Hibernate-r5 and type ant
5.A gui opens to show tables in hsqldb
6.Click Generate to generate metadata-mapping files
Middlegen-Hibernate plugin directory structure
The Middlegen-Hibernate plugin consists of the following directory layout:
+--- build // contains the generated source
| +--- gen-src // contains the built mapping-metadata files
+--- lib // contains necessary dependencies
+--- config // contains database mapping
| +--- database // contains various database mapping xml files
+---- middlegen-lib // contains Middlegen-Hibernate plugin jars
| +--- sql // contains SQL scripts
|--- build.xml // Ant build file
|--- build.properties // defines build properties
Configuring Middlegen-Hibernate plugin
1.On iSeries build a test Schema HMP.
2.Place jt400.jar in lib.
3.Build database mapping file as db2_as400.xml
4.Build SQL script file as airline-db2_as400.sql
5.1 Replace db2_as400.xml in doctype declaration
5.2 Remove catalog
6.Rename build.properties.sample to build.properties
7.Uncomment database.script.file and replace
Running Middlegen-Hibernate plugin
1.Open command prompt as C:\Java\Middlegen-Hibernate-r5 and type ant create-table
2.A message SQL statements executed successfully is shown.
3.Now type ant.
2.A gui is shown listing tables.
3.Click Generate to generate metadata-mapping.
4.Mapped-metadata files are generated under C:\Java\Middlegen-Hibernate-r5\build\gen-src.
DB2 UDB for AS/400 05.04.0000 V5R4m0
Hibernate Core hibernate-2.1.7c
Hibernate Extension hibernate-extensions-2.1.3
Play with Middlegen
Friday, May 2, 2008
Hibernate version : 3.2.6 GA
Implementation-Version: JTOpen 3.3
properties naming=system;libraries=QTEMP ASDB ASDBA SFG
libraries=QTEMP ASDB ASDBA SFG;translate binary=true;prompt=false;user=GUEST;
Note : properties are separated by ';'.
A list of supporting dialect
Play with iseries........!