X-Git-Url: http://jaekl.net/gitweb/?a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fcfb%2Fdb%2FSchema.java;h=898687ee4db5fd65112c10d6c39663b1891b4765;hb=a1378c84c773511e4ffe99fb419da67af188aff7;hp=f802b58ca3cf71f89f7b5ef6c8b0f57c95382c66;hpb=3c10b6100c6035a65ce37dea846b027135289f67;p=cfb.git diff --git a/prod/net/jaekl/cfb/db/Schema.java b/prod/net/jaekl/cfb/db/Schema.java index f802b58..898687e 100644 --- a/prod/net/jaekl/cfb/db/Schema.java +++ b/prod/net/jaekl/cfb/db/Schema.java @@ -40,6 +40,22 @@ public class Schema { return false; } + if (!postCreationInit(con)) { + return false; + } + + return true; + } + + public void purge(Connection con) throws SQLException { + dropAllTables(con); + dropAllSequences(con); + } + + boolean postCreationInit(Connection con) throws SQLException { + // no-op + // Override this in a derived class if you need to initialize something + // after the tables and sequences are created. return true; } @@ -79,6 +95,17 @@ public class Schema { return true; } + void dropAllTables(Connection con) { + for (Table table : m_tables) { + try { + m_driver.dropTable(con, table); + } + catch (SQLException e) { + e.printStackTrace(); + } + } + } + boolean createAllSequences(Connection con) throws SQLException { for (Sequence seq : m_sequences) { if (!m_driver.createSequence(con, seq)) { @@ -88,6 +115,17 @@ public class Schema { return true; } + void dropAllSequences(Connection con) { + for (Sequence seq : m_sequences) { + try { + m_driver.dropSequence(con, seq); + } + catch (SQLException e) { + e.printStackTrace(); + } + } + } + void addTable(Table table) { m_tables.add(table); } @@ -98,14 +136,20 @@ public class Schema { // { table_name }, // { column_name, type, width (-1 for default), null/not_null } // } - void addTables(Object[][][] tables) + void addTables(Table[] tables) { - for (Object[][] table : tables) { - addTable(Table.construct(table)); + for (Table table : tables) { + addTable(table); } } void addSequence(Sequence seq) { m_sequences.add(seq); } + + void addSequences(Sequence[] sequences) { + for (Sequence sequence : sequences) { + addSequence(sequence); + } + } }