01: package com.completex.objective.persistency.examples.ex002;
02:
03: import com.completex.objective.components.persistency.OdalPersistencyException;
04: import com.completex.objective.components.persistency.core.adapter.DefaultPersistencyAdapter;
05: import com.completex.objective.components.persistency.transact.Transaction;
06: import com.completex.objective.tools.generators.PersistentDescriptorGenerator;
07: import com.completex.objective.tools.generators.PersistentObjectGenerator;
08: import com.completex.objective.util.PropertyMap;
09: import com.completex.objective.persistency.examples.ExamplesHelper;
10:
11: import java.io.FileInputStream;
12: import java.io.IOException;
13: import java.sql.SQLException;
14: import java.util.Properties;
15:
16: /**
17: * @author Gennady Krizhevsky
18: */
19: public class GenObjects {
20: // public static String configPath = "examples/src/config/hsql.properties";
21: // public static String objectConfigPath = "examples/src/config/persistent-object.sdl";
22: public static String configPath = ExamplesHelper
23: .pdConfigPath(GenObjects.class);
24: public static String objectConfigPath = ExamplesHelper
25: .poConfigPath(GenObjects.class);
26: // public static String outPath = "examples/src/java/com/completex/objective/persistency/examples/ex002";
27: static final String CREATE_PERSON = "CREATE CACHED TABLE EXPL_PERSON( "
28: + "PERSON_ID BIGINT NOT NULL, "
29: + "FIRST_NAME VARCHAR (40) NOT NULL, "
30: + "LAST_NAME VARCHAR (40) NOT NULL, "
31: + "BIRTH_DATE DATE, "
32: + "LAST_UPDATED DATE, "
33: + "CREATION_DATE DATE, "
34: + "PRIMARY KEY (PERSON_ID) " + ")";
35: static final String DROP_PERSON = "DROP TABLE EXPL_PERSON";
36: static final String CREATE_SEQ = "CREATE SEQUENCE EXPL_PERSON_SEQ AS INTEGER START WITH 1";
37: static final String DROP_SEQ = "DROP SEQUENCE EXPL_PERSON_SEQ";
38:
39: public static void main(String[] args) throws Exception,
40: SQLException, IllegalAccessException,
41: InstantiationException, ClassNotFoundException {
42: ExamplesHelper.resetDatabase();
43:
44: Properties properties = createTables(args);
45:
46: generateDesriptors(properties);
47:
48: generateObjects();
49:
50: }
51:
52: static void generateObjects() throws Exception {
53: PersistentObjectGenerator objectGenerator = new PersistentObjectGenerator();
54: PropertyMap objectProperties = PropertyMap
55: .toPropertyMap(objectGenerator
56: .extractProperties(objectConfigPath));
57: objectGenerator.process(objectProperties);
58: }
59:
60: private static void generateDesriptors(Properties properties)
61: throws Exception {
62: PropertyMap descProperties = PropertyMap
63: .toPropertyMap(properties);
64: // descProperties.put(PersistentDescriptorGenerator.TAG_OUT_DIR, outPath);
65: PersistentDescriptorGenerator descriptorGenerator = new PersistentDescriptorGenerator(
66: descProperties);
67: descriptorGenerator.generate();
68: descriptorGenerator.dispose();
69: }
70:
71: private static Properties createTables(String[] args)
72: throws IOException, SQLException {
73: if (args.length > 0) {
74: GenObjects.configPath = args[0];
75: }
76:
77: Properties properties = new Properties();
78: properties.load(new FileInputStream(GenObjects.configPath));
79: DefaultPersistencyAdapter persistency = new DefaultPersistencyAdapter(
80: properties);
81: Transaction transaction = persistency.getTransactionManager()
82: .begin();
83: try {
84: persistency.executeUpdate(DROP_PERSON);
85: } catch (OdalPersistencyException e) {
86: // Ignore
87: }
88: try {
89: persistency.executeUpdate(DROP_SEQ);
90: } catch (OdalPersistencyException e) {
91: // Ignore
92: }
93: persistency.executeUpdate(CREATE_PERSON);
94: persistency.executeUpdate(CREATE_SEQ);
95: persistency.getTransactionManager().commit(transaction);
96: return properties;
97: }
98:
99: }
|