01: package com.completex.objective.tools.generators;
02:
03: import com.completex.objective.components.persistency.meta.MetaModel;
04: import com.completex.objective.tools.SqlCmdTool;
05: import com.completex.objective.util.PropertyMap;
06:
07: import java.io.IOException;
08: import java.io.InputStream;
09: import java.sql.SQLException;
10:
11: /**
12: * Args[0]: persistent-descriptor-config.properties
13: *
14: * @author Gennady Krizhevsky
15: */
16: public class InMemPersistentDescriptorGenerator extends
17: PersistentDescriptorGenerator {
18:
19: /**
20: * Comma separated script paths to create in-memory database schema: file1,file2, ...
21: */
22: public static final String TAG_SCRIPTS = "scripts";
23: private String[] scripts;
24: private SqlCmdTool sqlCmdTool;
25:
26: public InMemPersistentDescriptorGenerator() {
27: }
28:
29: public InMemPersistentDescriptorGenerator(String propertiesPath)
30: throws IOException, IllegalAccessException,
31: ClassNotFoundException, InstantiationException,
32: SQLException {
33: super (propertiesPath);
34: }
35:
36: public InMemPersistentDescriptorGenerator(PropertyMap propertyMap)
37: throws IOException, IllegalAccessException,
38: ClassNotFoundException, InstantiationException,
39: SQLException {
40: super (propertyMap);
41: }
42:
43: public InMemPersistentDescriptorGenerator(InputStream inputStream)
44: throws IOException, IllegalAccessException,
45: InstantiationException, ClassNotFoundException,
46: SQLException {
47: super (inputStream);
48: }
49:
50: public void setup(PropertyMap propertyMap) throws IOException,
51: ClassNotFoundException, InstantiationException,
52: IllegalAccessException, SQLException {
53: super .setup(propertyMap);
54: String scriptsProperty = propertyMap.getProperty(TAG_SCRIPTS,
55: true);
56: scripts = scriptsProperty.split(",");
57: for (int i = 0; i < scripts.length; i++) {
58: if (!scripts[i].startsWith(SqlCmdTool.SCRIPT_PREFIX)) {
59: scripts[i] = SqlCmdTool.SCRIPT_PREFIX + scripts[i];
60: }
61: }
62: sqlCmdTool = new SqlCmdTool(propertyMap);
63: }
64:
65: public MetaModel generate() throws Exception {
66: for (int i = 0; i < scripts.length; i++) {
67: String script = scripts[i];
68: sqlCmdTool.processScript(script);
69: }
70:
71: return super .generate();
72: }
73:
74: public static void main(String[] args) throws Exception {
75: if (args.length < 1) {
76: System.out
77: .println("ERROR: Generator must have one command line parameter - <persistent-descriptor-config.properties> ");
78: System.exit(1);
79: }
80:
81: InMemPersistentDescriptorGenerator generator = new InMemPersistentDescriptorGenerator(
82: args[0]);
83: generator.generate();
84: generator.dispose();
85: }
86: }
|