In the most common use case, Abator is driven by an XML configuration file. The configuration file tells Abator:
The following is an example abator configuration file. See the individual pages for each element for more information about the elements and the values of the attributes.
<?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" generatorSet="Java2"> <jdbcConnection driverClass="COM.ibm.db2.jdbc.app.DB2Driver" connectionURL="jdbc:db2:TEST" userId="db2admin" password="db2admin"> <classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" /> </jdbcConnection> <javaTypeResolver > <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <javaModelGenerator targetPackage="test.model" targetProject="\AbatorTestProject\src"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <sqlMapGenerator targetPackage="test.xml" targetProject="\AbatorTestProject\src"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <daoGenerator type="SPRING" targetPackage="test.dao" targetProject="\AbatorTestProject\src"> <property name="enableSubPackages" value="true" /> </daoGenerator> <table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" > <property name="useActualColumnNames" value="true"/> <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:
Java2
generator set to generate code. This generator set
is more powerful then the original generator set shipped with early versions of
Abator.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 properties will call the trim
function -
this is useful if your database might return blank characters at the end of character
columns.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
.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 Spring framework.
CustomerKey
,
Customer
,
CustomerDAO
, etc.) - rather than on the table name.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<selectKey>
element in the generated
<insert>
statement so that the newly generated key can be returned (using DB2 specific SQL).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
.FRED
will be ignored. No SQL will list the field,
and no Java property will be generated.LONG_VARCHAR_FIELD
will be treated as a
VARCHAR
field, regardless of the actual data type.