}
public void testStructure() throws Exception {
DbPool pool = createPool().getPool("test");
DbConnection con = pool.getConnection();
try {
con.getStatement("cleanup").execute(null);
con.commit();
} catch (ClassNotFoundException e1) {
System.out.println("testStructure: sql driver not found - skip test");
return;
} catch (SQLException e2) {
if (e2.getMessage().startsWith("Communications link failure")) {
System.out.println("testStructure: mysql db not found - skip test");
return;
} else {
throw e2;
}
}
con.getStatement("dropblub").execute(null);
HashConfig cstr = new HashConfig();
IConfig ctable = cstr.createConfig("table");
ctable.setProperty("name", "blub");
IConfig cfield = ctable.createConfig("field");
cfield.setProperty("name", "t_string");
cfield.setProperty("type", "string");
cfield.setProperty("size", "200");
cfield.setProperty("default", "aloa");
Dialect dialect = pool.getDialect();
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
dialect.createStructure(cstr, con, null);
cfield = ctable.createConfig("field");
cfield.setProperty("name", "t_int");
cfield.setProperty("type", "int");
cfield.setProperty("default", "10");
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
dialect.createStructure(cstr, con, null);
cfield.setProperty("type", "float");
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
dialect.createStructure(cstr, con, null);
cfield.setProperty("default", "20");
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
dialect.createStructure(cstr, con, null);
cfield.removeProperty("default");
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
dialect.createStructure(cstr, con, null);
cfield.setProperty("default", "15");
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
dialect.createStructure(cstr, con, null);
cfield.setProperty("notnull", "yes");
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
dialect.createStructure(cstr, con, null);
ctable.setProperty("primary_key", "t_int");
dialect.createStructure(cstr, con, null);
dialect.createStructure(cstr, con, null);
ctable.setProperty("primary_key", "t_int,t_string");
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
dialect.createStructure(cstr, con, null);
ctable.removeProperty("primary_key");
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
dialect.createStructure(cstr, con, null);
// index
IConfig cindex = cstr.createConfig("index");
cindex.setString("name", "blub_idx");
cindex.setString("table", "blub");
cindex.setString("fields", "t_string");
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
dialect.createStructure(cstr, con, null);
cindex.setString("fields", "t_string,t_int");
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
dialect.createStructure(cstr, con, null);
// data
IConfig cdata = cstr.createConfig("data");
IConfig cexec = cdata.createConfig("execute");
String tName = pool.getDialect().normalizeTableName("blub");
cexec.setProperty("sql", "insert into " + tName + " (t_string,t_int) values ('aaa',1)");
cexec = cdata.createConfig("execute");
cexec.setProperty("sql", "insert into " + tName + " (t_string,t_int) values ('bbb',2)");
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
cdata.setProperty("select", "select * from " + tName + " where t_string='ccc'");
cdata.setProperty("condition", "not found");
cexec = cdata.createConfig("execute");
cexec.setProperty("sql", "insert into " + tName + " (t_string,t_int) values ('ccc',3)");
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
System.out.println("--------------------------------------------------");
dialect.createStructure(cstr, con, null);
con.commit();
con.close();
}