CROM prevSibling,
TreeItem<DbTranRelations.Relation> item,
boolean isFlat,
DbColumnInfoCreator.ColumnInfo column_info,
boolean isManualSqlStatement) {
CROM node=null;
String sTable_ = item.getName();
boolean bIgnoredDbColumnDefaultValue = false;
List<DbTranRelations.Relation> relations = item.getData();
DbTranRelations.Relation relation = null;
if (relations.size() > 0)
relation = relations.get(0);
if (sTable_ != null) {
boolean bFolder=true;
node=new CROM(parent, bFolder, sTable_, -1, CromType.CROM_t_DB);
String sSchema=map_Schema.get(sTable_);
if(sSchema!=null)node.setDBSchema(sSchema);
String sTable = map_TableAlias.get(sTable_);
if (sTable == null)sTable = sTable_;
node.setSqlTableName(map_sqlTableName.get(sTable));
String sTable2=(sSchema!=null && sSchema.length()>0)?sTable.substring(sSchema.length()+1):sTable; // Remove Schema from table name
List<String> dbUpdateKeys=map_UpdateKeys.get(sTable2);
boolean hasUserDefinedUpdateKeys=dbUpdateKeys!=null && dbUpdateKeys.size()>0;
// for the time being we store the join type in the child table
// it should be the property of the Foreign key column
boolean isOneToOne = false, isOuterJoin = true;
if (relation != null) {
isOneToOne = relation.isOneToOne();
isOuterJoin = relation.isOuterJoin();
}
if(isOneToOne){
if(isOuterJoin)node.setOptionalNode();
}
else {
if(isOuterJoin)node.setCollectionNode();
else node.setAtLeastOneNode();
}
List<String> pk_list = new ArrayList<String>();
for (TreeItem<DbTranRelations.Relation> child : item.getChildren()) {
List<DbTranRelations.Relation> relation_list = child.getData();
for (DbTranRelations.Relation r : relation_list) {
pk_list.add(r.getParentField());
}
}
List<DatabaseColumn> lstColumn = column_info.getTableColumnInfo(sTable, isManualSqlStatement);
log("Table \""+sTable+"\" has "+(lstColumn==null? 0: lstColumn.size())+" columns.");
if (lstColumn != null){
for (DatabaseColumn column : lstColumn) {
CROM attr;
boolean isFolder=false;
boolean bIsFK = false;
String COLUMN_DEF = "";
String PRIMARY_KEY=null;
String COLUMN_NAME = column.getName();
StringBuilder typeName = new StringBuilder(column.getDataTypeString());
int DbColType=column.getSqlDataType();
if (!bIgnoredDbColumnDefaultValue)
COLUMN_DEF = column.getDefaultValueString();
boolean bIsOptional = column.isNullable();
boolean bIsPK = false;
int DbColSize=column.getColumnSize();
int DbDecimalDigits=column.getDecimalDigits();
String display = COLUMN_NAME;
for (String pk : pk_list) {
if (COLUMN_NAME.equals(pk)) {
bIsPK = true;
break;
}
}
boolean bIsUpdateKey = checkIfUpdateKey(dbUpdateKeys, hasUserDefinedUpdateKeys, COLUMN_NAME, bIsPK);
for (DbTranRelations.Relation r : relations) {
String childField=r.getChildField(), parentField=r.getParentField();
if ( beginQuote != null && endQuote != null && !beginQuote.isEmpty() && !endQuote.isEmpty() ) {
if( (childField.startsWith(beginQuote) && childField.endsWith(endQuote) && childField.length()>2) ){
childField=childField.substring(1,childField.length()-1);
}
if( (parentField.startsWith(beginQuote) && parentField.endsWith(endQuote) && parentField.length()>2) ){
parentField=parentField.substring(1,parentField.length()-1);
}
}
if (COLUMN_NAME.equals(childField)) {
bIsFK = true;
typeName.append(" [Join on ").append(parentField).append("]");
PRIMARY_KEY=parentField;
}
}
attr=new CROM(node, isFolder, display, -1, CromType.CROM_t_DB);
if(bIsOptional)attr.setOptionalNode();
if(bIsPK)attr.setPrimaryKey();
if(bIsUpdateKey)attr.setUpdateKey();
CROM_ext ext=attr.getExtension();
if(bIsFK){
attr.setLinkKey();
attr.setLinkToPrimaryKey(PRIMARY_KEY);
}
ext.setValueType(typeName.toString());
ext.setDbColType(DbColType);
ext.setDbColSize(DbColSize);
ext.setDbDecimalDigits(DbDecimalDigits);
ext.setDefaultValue(COLUMN_DEF);
}
}
}
CROM child_node=null;
for (TreeItem<DbTranRelations.Relation> child : item.getChildren()) {
child_node = createCromTreeForTable(node, child_node, child, isFlat, column_info, isManualSqlStatement);
}
return node;
}