empire-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Richmond <crichm...@referentia.com>
Subject getting tables for completely dynamic databas
Date Fri, 31 Aug 2012 01:16:58 GMT
I have a database which starts with absolutely no schema when started.

I have made this simple class:

public class TestDB extends DBDatabase {

  public TestDB(){

  }

}

simply so that i may create tables completely on the fly for my embedded H2
database like so:

     TestDB db = new TestDB()

    config.init((args.length > 0 ? args[0] : "config.xml" ));
    Connection conn = getJDBCConnection();
    DBDatabaseDriver driver = getDatabaseDriver("h2");

    db.open(driver, conn);



    DBTable dbTable = new DBTable("MyNewTable", db);

    dbTable.addColumn("MyColumn", DataType.INTEGER, 32d, false);
    dbTable.addColumn("MyColumn2", DataType.INTEGER, 32d, false);
    dbTable.addColumn("MyColumn3", DataType.INTEGER, 1024d, false);
    dbTable.addColumn("MyColumn4", DataType.INTEGER, 1024d, false);


    DBSQLScript script = new DBSQLScript();

    db.getDriver().getDDLScript(DBCmdType.CREATE, db, script);

    System.err.println(script.toString());
    script.run(db.getDriver(), conn);

    db.close(conn);




This works fine, new tables are created in my H2 database.  My problem is
this. Since I have no static definition of the schema then things like

    db.getTable("TableNameLookingFor")

never returns any DBTables whatsoever.

When I create my db I need for it to find the tables that actually exist in
the database(all of which are created on the fly like above at runtime with
various names at various times, which I will never now when)



How can I go about this?  Or am I approaching this the wrong way?  Perhaps
I shouldn't be using a simple TestDB implementation of DBDatabase like
that?  Do I need to override some superclass methods to get it to load the
table schema from the on disk H2 database any time I construct it?  I am
not sure how to proceed.

Thanks

Mime
View raw message