cdbgen is an Ant task that uses Cayenne DataMap to drop and/or generate schema objects of a specified database.

Parameters

Attribute Description Required
map DataMap XML file to use as a schema descriptor. Yes
adapter Java class implementing org.objectstyle.cayenne.dba.DbAdapter. While this attribute is optional (a generic JdbcAdapter is used if not set), it is highly recommended to specify correct target adapter. No (but strongly recommended)
driver A class of JDBC driver to use for the target database. Yes
url JDBC connection URL of a target database. Yes
username Database user name. No
password Database user password. No
droptables Defines whether cdbgen should drop the tables before attempting to create new ones. Default is "No". No
droppk Defines whether cdbgen should drop Cayenne primary key support objects. Default is "No". No
createtables Defines whether cdbgen should create new tables. Default is "Yes". No
createpk Defines whether cdbgen should create Cayenne-specific auto PK objects. Default is "Yes". No
createfk Defines whether cdbgen should create foreign key copnstraints. Default is "Yes". No
Driver Classpath
Support for "classpath" or "classpathref" attributes is pending. To work around this limitation, JDBC driver (and custom DbAdapter) classpath can be appended to the classpath used to load the task via "taskdef".

Example

Here is an example of using cdbgen to create DB schema objects on a local HSQLDB.

<taskdef name="cdbgen" classname="org.objectstyle.cayenne.tools.DbGeneratorTask">
    <classpath refid="classpath"/>
</taskdef>

<cdbgen map="${context.dir}/WEB-INF/DefaultMap.map.xml" 
    adapter="org.objectstyle.cayenne.dba.hsqldb.HSQLDBAdapter"
    driver="org.hsqldb.jdbcDriver" 
    url="jdbc:hsqldb:hsql://localhost/bookmarker" 
    username="sa"/>