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

Hide last authors
5fbc055b7cc103006957e1ae 1.1 1 === {{id name="HowTocreateandupdateDatabasesusingSchemaManagerandSchemaUpdateSnippets-Preliminary"/}}Preliminary ===
2
3 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.
4
5 SchemaManager ({{code language="none"}}org.clazzes.jdbc2xml.schema.SchemaManager{{/code}}) 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:
6
7 {{code language="none"}}
8 VERSION:varchar(10), not null, primary key
9 DESCRIPTION:varchar(512), nullable
10 CREATION_DATE:date, nullable
11 SERIALNR:integer(5), not null
12 {{/code}}
13
14 It will also take a list of TableInfo ({{code language="none"}}org.clazzes.jdbc2xml.schema.TableInfo{{/code}}) Objects and create a database from them, if it finds an empty database when it starts.
15
16
17
18 === {{id name="HowTocreateandupdateDatabasesusingSchemaManagerandSchemaUpdateSnippets-UsingOSGiandBlueprint"/}}Using OSGi and Blueprint ===
19
20 After adding a dependency to the {{code language="none"}}org.clazzes.jdbc2xml{{/code}} library with your favourite package management system, add the following to your blueprint {{code language="none"}}services.xml{{/code}} configuration:
21
22 {{code language="none"}}
23 <bp:reference id="dialectFactory" interface="org.clazzes.jdbc2xml.schema.IDialectFactory">
24 </bp:reference>
25  
26 <bp:reference id="schemaEngineFactory" interface="org.clazzes.jdbc2xml.schema.ISchemaEngineFactory">
27 </bp:reference>
28  
29 <bp:bean id="sqlDialect" factory-ref="dialectFactory" factory-method="newDialect">
30 <bp:argument ref="jdbcUrl"> <!-- JDBC URL -->
31 </bp:argument>
32 </bp:bean>
33  
34 <bp:bean id="schemaEngine" factory-ref="schemaEngineFactory" factory-method="newSchemaEngine">
35 <bp:property name="dialect" ref="sqlDialect">
36 </bp:property>
37 </bp:bean>
38  
39 <bp:bean id="databaseSetup" class="org.clazzes.jdbc2xml.schema.SchemaManager"
40 init-method="start">
41 <bp:property name="dataSource" ref="dataSource"></bp:property>
42 <bp:property name="schemaEngine" ref="schemaEngine"></bp:property>
43 <bp:property name="baseVersion" value="0.1.00" />
44 <bp:property name="baseTables">
45 <bp:bean factory-ref="tableDefinitions" factory-method="getSetup" />
46 </bp:property>
47 <bp:property name="upateSnippets">
48 <!-- Add Update-Snippets here -->
49 </bp:property>
50 </bp:bean>
51 {{/code}}
52
53 The SchemaManager takes a map of