cdbimport is a Maven 2 mojo that that uses Cayenne to generate a DataMap based on an existing database schema. By default, it is bound to the generate-sources phase. This allows you to generate your DataMap prior to building your project, which may be necessary if you are also using the cgen task.
Parameters (as XML elements)
Attribute | Description | Required |
---|---|---|
map | DataMap XML file to use as a schema descriptor. | Yes |
overwriteExisting | Indicates whether existing DB and object entities should be overwritten. This is an all-or-nothing setting. If you need finer granularity, please use the Cayenne Modeler. Default is true. | No |
schemaName | Database schema to use for importing. | No |
tablePattern | Pattern to match tables against for import. Default is to match all tables. | No |
importProcedures | Indicates whether stored procedures should be imported. Default is false. | No |
procedurePattern | Pattern to match stored procedures against for import. Default is to match all stored procedures. This value is only meaningful if importProcedures is true. | No |
meaningfulPk | Indicates whether primary keys should be mapped as attributes of the object entity. Default is false. | No |
namingStrategy | The naming strategy used for mapping database names to object entity names. Default is org.apache.cayenne.map.naming.SmartNamingStrategy. | No |
adapter | Java class name implementing org.apache.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 |
Examples
Load the Maven 2 plugin and configure the cdbimport mojo:
<build> <plugins> <plugin> <groupId>org.apache.cayenne.plugins</groupId> <artifactId>maven-cayenne-plugin</artifactId> <executions> <execution> <id>cdbimport</id> <configuration> <!-- Configuration items go in here. See table, above. --> </configuration> <goals> <goal>cdbimport</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Here is an example of using cdbimport to create DB schema objects on a local HSQLDB database named "bookmarker" from a DataMap located in "main/resources/datamap.map.xml":
<build> <plugins> <plugin> <groupId>org.apache.cayenne.plugins</groupId> <artifactId>maven-cayenne-plugin</artifactId> <executions> <execution> <id>cdbimport</id> <configuration> <map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map> <adapter>org.apache.cayenne.dba.hsqldb.HSQLDBAdapter</adapter> <driver>org.hsqldb.jdbcDriver</driver> <url>jdbc:hsqldb:hsql://localhost/bookmarker</url> <username>sa</username> </configuration> <goals> <goal>cdbimport</goal> </goals> </execution> </executions> </plugin> </plugins> </build>