01: package simpleorm.examples;
02:
03: import simpleorm.core.*; // .* OK, all classes prefixed with "S".
04: import java.io.File;
05: import java.io.FileOutputStream;
06: import java.io.PrintStream;
07:
08: /** Creates the createdb.sql script (Not necessary to run tests).
09: This test creates temp/createdb.sql which contains DROP and CREATE
10: TABLE statments that can recreate the tables in the given
11: database. This should be used if SimpleORM is to be made the
12: single source of truth for database definitions.<p>
13:
14: Note that this is not actually required to run the other tests as
15: they each explicitly create any tables that they need using
16: <code>executeUpdate</code>.
17: */
18: public class CreateDBTest implements SConstants {
19: // ### Provide an E-R diagram of the schema.
20:
21: public static void main(String[] argv) throws Exception {
22: System.setErr(System.out); // Tidy up any stack traces.
23: // SLog.level = 20; //Uncomment to reduce trace output.
24: TestUte.initializeTest(CreateDBTest.class);
25: createTables();
26: SConnection.detachAndClose();
27: }
28:
29: /** Creates the createdb.sql script file for the
30: database. This is referenced as part of the build process.<p>
31:
32: Take a look at the generated file to see how the foreign key
33: propagation works.<p>*/
34: static void createTables() throws Exception {
35:
36: File file = new File("../temp/createdb.sql");
37: FileOutputStream fis = new FileOutputStream(file);
38: PrintStream out = new PrintStream(fis);
39: out.println("-- Warning Generated file\n");
40:
41: out.println("DROP TABLE XX_PSLIP_DETAIL;");
42: out.println("DROP TABLE XX_PAY_SLIP;");
43: out.println("DROP TABLE XX_PAY_PERIOD;");
44: out.println("DROP TABLE XX_EMPLOYEE;");
45: out.println("DROP TABLE XX_DEPARTMENT;\n");
46:
47: out.println(Department.meta.createTableSQL() + ";");
48: out.println(Employee.meta.createTableSQL() + ";");
49: out.println(Payroll.Period.meta.createTableSQL() + ";");
50: out.println(Payroll.PaySlip.meta.createTableSQL() + ";");
51: out.println(Payroll.PaySlipDetail.meta.createTableSQL() + ";");
52:
53: out.close();
54: }
55:
56: }
|