//
public static Property[] createPropertiesFromTable(DatasourceConnection dc, String tableName) {
Struct properties = CommonUtil.createStruct();
try {
DatabaseMetaData md = dc.getConnection().getMetaData();
String dbName=DataSourceUtil.getDatabaseName(dc);
Collection.Key name;
// get all columns
ResultSet res = md.getColumns(dbName, null, tableName, null);
while(res.next()) {
name=CommonUtil.createKey(res.getString("COLUMN_NAME"));
properties.setEL(
name,
CommonUtil.createProperty(name.getString(),res.getString("TYPE_NAME")));
}
// ids
res = md.getPrimaryKeys(null, null, tableName);
Property p;
while(res.next()) {
name=CommonUtil.createKey(res.getString("COLUMN_NAME"));
p=(Property) properties.get(name,null);
if(p!=null) p.getDynamicAttributes().setEL(CommonUtil.FIELDTYPE, "id");
}
// MUST foreign-key relation
}
catch(Throwable t){
return new Property[0];
}
Iterator<Object> it = properties.valueIterator();
Property[] rtn=new Property[properties.size()];
for(int i=0;i<rtn.length;i++){
rtn[i]=(Property) it.next();
}
return rtn;