Currently, the only way to start Middlegen is from Ant. The middlegen.jar file contains an Ant task you should use to run Middlegen. A variety of attributes and nested elements are available for this task, and they have an impact on what Middlegen generates and how it behaves. Additional configurations can also be done interactively if the gui attribute is set to true. Since the Middlegen task is not a standard Ant task, it must first be defined:
<taskdef name="middlegen" classname="middlegen.MiddlegenTask" classpathref="some.class.path" />
All classes required by Middlegen have to be defined in the classpath you pass to the taskdef (unless they are on the system CLASSPATH). This includes the middlegen.jar file, any middlegen-plugin jar files you wish to use, the JDBC driver and the dependent jars.
Middlegen provides two optional mechanisms to obtain a database connection so it can read the meta data:
| Attribute | Description | Required |
|---|---|---|
| appname | A global name identifying the application. This name will be used to store preferences for the application. It may also be used in various parts of the generated code (the plugins might want to use it). | Yes. |
| prefsdir |
The directory where Middlegen will stor the prefs file. This file contains extra
information that can be modified in the gui, so that the state (such as
cardinality, directionality and java types) is preserverd between subsequent
invocations of Middlegen. The prefs file will be stored in
${prefsdir}/${appname}-prefs.xml|properties. (The extension
depends on the value of xmlprefs).
|
No. Defaults to .middlegen under current user's home directory. |
| xmlprefs | If true, an XML file (based on the java.util.prefs API) will be used to store preferences. Requires JDK 1.4+ | No. Defaults to false. (A properties will be used). |
| gui |
If true, a window will show where you can perform various configurations.
Ant will block until this window is closed. Legal values for this attribute are true and false.
|
No. Defaults to false. |
| includeViews |
If true, views will be read from the database in the same way regular tables are.
Legal values for this attribute are true and false.
|
No. Defaults to false. |
| sortColumns |
Sort the columns in the table. Comma separated list of criteria for sorting columns. Valid values are pk, fk, indexed, nullable, mandatory, unique, name (always with the lowset priory). Example: pk,indexed,name. |
No. |
| databaseurl | The URL used by Middlegen to connect to the database. If both databaseurl and datasourceJNDIName are specified, the databaseurl will be used to connect to the database, as that is the fastest way to connect. |
No, unless
datasourceJNDIName,
initialContextFactory and
providerURL are not specified. |
| driver | The fully qualified class name of the JDBC driver to use when connecting to the database. This driver must be on the task's classpath. | |
| username | Username for the database. Used in conjunction with databaseurl | No. |
| password | Password for the database. Used in conjunction with databaseurl | No. |
| datasourceJNDIName | The JNDI name of a datasource that can provide a connection to the database. If databaseurl is not specified, Middlegen will try to connect to the database via this datasource. Note: If you're using the cmp20 plugin, you have to set this attribute because its value will be written to various app-server specific data-source @tags in the produced sources. (Refer to XDoclet's documentation for further details). The value will eventually end up in your beans' app-server specific deployment descriptor (when XDoclet is run). The datasource doesn't have to exist when Middlegen is run, it's only required in order to generate correct deployment descriptors for EJBs. |
No, unless databaseurl and driver are not specified or some of the plugins require it. |
| initialContextFactory | The javax.naming.spi.InitialContextFactory implementation to use. | |
| providerURL | The URL where the JNDI datasource can be found. | |
| schema | A schema name. Must match the schema name as it is stored in the database. "" retrieves tables without a schema. If you don't specify this attribute it means that the schema name should not be used to narrow the search. | No. |
| catalog | A catalog name. Must match the catalog name as it is stored in the database. "" retrieves tables without a catalog. If you don't specify this attribute it means that the catalog name should not be used to narrow the search. | No. |
| singularize |
If true, Middlegen will try to singularize the table names.
Legal values for this attribute are true and false.
|
No. Default is true. |
<middlegen
appname="shop"
prefsdir="some/directory"
gui="true"
databaseurl="jdbc:mysql://somewhere/airline"
initialContextFactory="${java.naming.factory.initial}"
providerURL="${java.naming.provider.url}"
datasourceJNDIName="shop.database"
driver="org.gjt.mm.mysql.Driver"
username="top"
password="secret"
>
<!-- Optionally declare table elements -->
<!-- Optionally declare many2many elements -->
<!-- One or more plugins -->
</middlegen>