How To create and update Databases using SchemaManager and SchemaUpdateSnippets

Version 1.1 by 5fbc055b7cc103006957e1ae on 2012-06-14 12.59:26

Preliminary

The SchemaManager and SchemaEngine give you an abstracted access to the database schema of your application, allowing you to add and delete tables, fields and relations with application updates. It uses a designated table to keep track of the current schema status, which it will check whenever it is run, and update the database if it is not at the correct version.

SchemaManager (org.clazzes.jdbc2xml.schema.SchemaManager) will create a table called SCHEMA_HISTORY if it can not find it the first time it is run. This table contains the following columns:

VERSION:varchar(10), not null, primary key
DESCRIPTION:varchar(512), nullable
CREATION_DATE:date, nullable
SERIALNR:integer(5), not null

It will also take a list of TableInfo (org.clazzes.jdbc2xml.schema.TableInfo) Objects and create a database from them, if it finds an empty database when it starts.

 

Using OSGi and Blueprint

After adding a dependency to the org.clazzes.jdbc2xml library with your favourite package management system, add the following to your blueprint services.xml configuration:

<bp:reference id="dialectFactory" interface="org.clazzes.jdbc2xml.schema.IDialectFactory">
</bp:reference>
 
<bp:reference id="schemaEngineFactory" interface="org.clazzes.jdbc2xml.schema.ISchemaEngineFactory">
</bp:reference>
 
<bp:bean id="sqlDialect" factory-ref="dialectFactory" factory-method="newDialect">
<bp:argument ref="jdbcUrl"> <!-- JDBC URL -->
</bp:argument>
</bp:bean>
 
<bp:bean id="schemaEngine" factory-ref="schemaEngineFactory" factory-method="newSchemaEngine">
<bp:property name="dialect" ref="sqlDialect">
</bp:property>
</bp:bean>
 
<bp:bean id="databaseSetup" class="org.clazzes.jdbc2xml.schema.SchemaManager"
init-method="start">
<bp:property name="dataSource" ref="dataSource"></bp:property>
<bp:property name="schemaEngine" ref="schemaEngine"></bp:property>
<bp:property name="baseVersion" value="0.1.00" />
<bp:property name="baseTables">
<bp:bean factory-ref="tableDefinitions" factory-method="getSetup" />
</bp:property>
<bp:property name="upateSnippets">
<!-- Add Update-Snippets here -->
</bp:property>
</bp:bean>

The SchemaManager takes a map of