5.5. Schema Manipulation

Kodo JDO stores persistent objects in relational database tables. As you add, remove, or modify your persistent classes, these tables must be updated to reflect the current object model.

To facilitate this process, Kodo JDO provides the schematool. This command-line tool can create, refresh, or drop the relational schema for any persistent types, relieving you from database administration tasks. You can invoke the tool through the included schematool script or via its java class, com.solarmetric.kodo.impl.jdbc.schema.SchemaTool . It accepts the standard set of command-line arguments defined by the configuration framework. It also accepts the following flags:

Any additional arguments to the schematool will be interpreted as persistent types whose schema should be modified. Just as with the appidtool, each of the arguments can be either a full class name, a .class file, or a .jdo file. If no classes are given, the action will be performed on all known persistent types.

Important

When acting on a persistent type, the schematool automatically extends the action to all known subclasses of the type.

Example 5.4. Using the Kodo JDO Schematool

Refresh the schema for all known persistent classes:

schematool -action refresh
			

Drop the schema for the Company and any types listed in the package.jdo file.

schematool -properties hsql.properties -action drop com.solarmetric.examples.Company ../package.jdo
    		
Note

It is possible to bypass the schematool step by specifying the com.solarmetric.kodo.impl.jdbc.SynchronizeSchema Kodo property to true. This should never be used on a production database, since automatic schema migration can result in columns being dropped, and thus in data loss. See the Configuration Framework chapter for more details.