* @throws Exception
*/
public void createTable(DbConnection con) throws Exception {
HashConfig cstr = new HashConfig();
IConfig ctable = cstr.createConfig("table");
ctable.setProperty("name", tableNameOrg);
LinkedList<String> pk = new LinkedList<String>();
for (Field f : fList) {
IConfig cfield = ctable.createConfig("field");
cfield.setProperty(Dialect.K_NAME, f.createName);
cfield.setProperty(Dialect.K_TYPE, f.retDbType);
cfield.setProperty(Dialect.K_SIZE, String.valueOf(f.size));
cfield.setProperty(Dialect.K_DEFAULT, f.defValue);
cfield.setProperty(Dialect.K_NOT_NULL, f.nullable ? "no" : "yes");
LinkedList<String> cat = new LinkedList<String>();
if (!f.isPersistent()) cat.add(Dialect.C_VIRTUAL);
if (f.isPrimary) cat.add(Dialect.C_PRIMARY_KEY);
if (f.ret.isEnum()) cat.add(Dialect.C_ENUMERATION);
cfield.setProperty(Dialect.K_CATEGORIES, MString.join(cat.iterator(), ",") ); // add primary key
if (f.isPrimary && f.isPersistent()) pk.add(f.createName);
}
if (pk.size() > 0) {
String pkNames = MString.join(pk.iterator(), ",");
ctable.setProperty(Dialect.K_PRIMARY_KEY, pkNames);
}
// create index entries
for (Entry<String, LinkedList<Field>> item : iIdx.entrySet()) {
IConfig cindex = cstr.createConfig("index");
String n = item.getKey();
if (n.startsWith(DbIndex.UNIQUE)) {
cindex.setString(Dialect.I_TYPE, Dialect.I_UNIQUE);
}
cindex.setString(Dialect.I_NAME, "idx_" + n);
cindex.setString(Dialect.I_TABLE, tableNameOrg);
StringBuffer fields = new StringBuffer();
for (Field field : item.getValue()) {
if (fields.length() > 0) fields.append(",");
fields.append(field.createName);
}
cindex.setString(Dialect.I_FIELDS, fields.toString());
}
manager.getPool().getDialect().createStructure(cstr, con, manager.getCaoMetadata());
}