The meta-data files that accompany persistable classes define how a class maps across to a persistent store (e.g database). Database tables can be created by JPOX automatically by using the org.jpox.autoCreateSchema property. They can also be created manually by the user. In addition, JPOX provides a tool for creation/deletion/validation of these tables up front of actually running your JPOX enabled application -- called SchemaTool. SchemaTool has 3 modes of operation.
If you wish to call SchemaTool manually, it can be called as follows
java [-cp classpath] [system_props] org.jpox.SchemaTool [options] [jdo-files]
where options can be
-create : Create the tables specified by the jdo-files
-delete : Delete the tables specified by the jdo-files
-validate : Validate the tables specified by the jdo-files
where system_props should include
-Djavax.jdo.option.ConnectionDriverName=db_driver_name
-Djavax.jdo.option.ConnectionURL=db_url
-Djavax.jdo.option.ConnectionUserName=db_username
-Djavax.jdo.option.ConnectionPassword=db_password
and system_props could optionally include
-Dlog4j.configuration=file:log4j_configuration_file.lcf
The classes and JDO MetaData files must be present in the CLASSPATH, and you should set the system properties above with your own values. You should only specify one of the [options] above.
If you are using Maven to build your system, you will need the JPOX Maven plugin. This provides 3 goals representing the different modes of SchemaTool. You can use the goals jpox:schema-create, jpox:schema-delete, jpox:schema-validate depending on whether you want to create, delete or validate the database tables. To use the JPOX Maven plugin you will need to set properties for the plugin (in your project.properties). For example
maven.jpox.database.driver=com.mysql.jdbc.Driver
maven.jpox.database.url=jdbc:mysql://localhost/jpox
maven.jpox.database.user=mysql
maven.jpox.database.password=
maven.jpox.log4j.configuration=file:log4j.lcf
So with these example properties I am setting the Maven plugin to use a MySQL database called "jpox", using a login of "mysql", etc. I am also specifying a log4j configuration file defining the logging for the SchemaTool process.
An Ant task is provided for using SchemaTool. It has classname org.jpox.SchemaToolTask, and accepts the following parameters
In addition to the parameters that the Ant task accepts, you will need to set up your CLASSPATH to include the classes and JDO MetaData files, and to define the following system properties via the sysproperty parameter
So you could define something like the following, setting up the parameters schematool.classpath, javax.jdo.option.ConnectionDriverName, javax.jdo.option.ConnectionURL, javax.jdo.option.ConnectionUserName, and javax.jdo.option.ConnectionPassword to suit your situation. You define the jdo files to create the tables using fileset.
<taskdef name="schematool" classname="org.jpox.SchemaToolTask" />
<schematool
failonerror="true"
fork="true"
verbose="true"
mode="create">
<classpath>
<path refid="schematool.classpath"/>
</classpath>
<fileset dir="${classes.dir}">
<include name="**/*.jdo"/>
</fileset>
<sysproperty key="javax.jdo.option.ConnectionDriverName" value="${javax.jdo.option.ConnectionDriverName}"/>
<sysproperty key="javax.jdo.option.ConnectionURL" value="${javax.jdo.option.ConnectionURL}"/>
<sysproperty key="javax.jdo.option.ConnectionUserName" value="${javax.jdo.option.ConnectionUserName}"/>
<sysproperty key="javax.jdo.option.ConnectionPassword" value="${javax.jdo.option.ConnectionPassword}"/>
</schematool>
|