XML Configuration File Reference
In the normal use case, Abator is driven by an XML configuration file.
The configuration file tells Abator:
- How to connect to the database
- What objects to generate, and how to generate them
- What tables should be used for object generation
At this point, the best reference for the XML configuration file is the annotated DTD. The following
is an example abator configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE abatorConfiguration
PUBLIC "-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN"
"http://ibatis.apache.org/dtd/abator-config_1_0.dtd">
<abatorConfiguration>
<abatorContext id="DB2Tables">
<jdbcConnection driverClass="COM.ibm.db2.jdbc.app.DB2Driver"
connectionURL="jdbc:db2:JGBTEST"
userId="db2admin"
password="db2admin">
<classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" />
</jdbcConnection>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" /> <!-- default is false -->
</javaTypeResolver>
<javaModelGenerator targetPackage="test.model" targetProject="Abator Test Project">
<property name="enableSubPackages" value="true" /> <!-- default is false -->
<property name="trimStrings" value="true" /> <!-- default is false -->
</javaModelGenerator>
<sqlMapGenerator targetPackage="test.xml" targetProject="Abator Test Project">
<property name="enableSubPackages" value="true" /> <!-- default is false -->
</sqlMapGenerator>
<daoGenerator type="IBATIS" targetPackage="test.dao" targetProject="Abator Test Project">
<property name="enableSubPackages" value="true" /> <!-- default is false -->
</daoGenerator>
<table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" >
<property name="useActualColumnNames" value="true"/> <!-- default is false -->
<generatedKey column="ID" sqlStatement="DB2" identity="true" />
<columnOverride column="DATE_FIELD" property="startDate" />
<ignoreColumn column="FRED" />
<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />
</table>
</abatorContext>
</abatorConfiguration>
Important notes about this file follow:
- The file specifies that the legacy DB2 CLI driver will be used to connect to the database,
and also specifies where the driver can be found.
- The Java Type Resolver should not force the use of Bigdecimal fields - this means that
integral types (Short, Integer, Long, etc.) will be substituted if possible. This feature
is an attempt to make database DECIMAL and NUMERIC columns easier to deal with.
- The Java model generator should use sub-packages. This means that the generated model
objects will be placed in a package called "test.model.db2admin" in this case (because the table
is in the "DB2ADMIN" schema). If the "enableSubPackages" attribute was set to "false",
then the package would be "test.model". The Java model generator should also trim strings.
This means that the setters for any String property will call the "trim" function -
this is useful if your database will return blank characters at the end of character
columns.
- The SQL Map generator should use sub-packages. This means that the generated XML files
will be placed in a package called "test.xml.db2admin" in this case (because the table
is in the "DB2ADMIN" schema). If the "enableSubPackages" attribute was set to "false",
then the package would be "test.xml".
- The DAO generator should use sub-packages. This means that the generated DAO classes
will be placed in a package called "test.dao.db2admin" in this case (because the table
is in the "DB2ADMIN" schema). If the "enableSubPackages" attribute was set to "false",
then the package would be "test.dao". The DAO generator should generate DAO classes
that conform to the iBATIS DAO framework. The DAO generator can generate
DAO classes in the following formats:
- IBATIS - for the iBATIS DAO Framework
- SPRING - for the Spring Framework
- GENRIC-CI - for DAOs that only depend on iBATIS' SQL Map API. The SQL map is
supplied through constructor injection
- GENRIC-SI - for DAOs that only depend on iBATIS' SQL Map API. The SQL map is
supplied through setter injection
- The file specifies only one table will be introspected, but many more could be specified.
Important note about that table are as follows:
- The generated objects will be based on the name "Customer" (CustomerKey, Customer,
CustomerDAO, etc.) - rather than on the table name.
- Actual column names will be used as properties. If this property were set to
"false" (or not specified), then Abator would attempt to camel case the column
names. In either case, the name can be overridden by the <columnOverride>
element
- The column has a generated key, it is an identity column, and the database type is DB2.
This will cause
Abator to generate the proper <selectKey> element in the generated <insert>
statement so that the newly generated key can be returned. Valid values for the
sqlStatement
attribute include DB2, MYSQL, and SQLSERVER (only if the column
is an identity column). Or
you can specify the proper statement for other databases.
- The column "DATE_FIELD" will be mapped to a property called "startDate". This will
override the default property which would be "DATE_FIELD" in this case, or "dateField"
if the "useActualColumnNames" property was set to "false".
- The column "FRED" will be ignored. No SQL will list the field, and no Java property will
be generated.
- The column "LONG_VARCHAR_FIELD" will be treated as a VARCHAR field, regardless of the
actual datatype.