use of com.cubrid.common.ui.cubrid.database.erwin.model.ERWinDBAttribute in project cubrid-manager by CUBRID.
the class ERXmlContainer method parseAttributes.
private void parseAttributes() {
NodeList attributes = doc.getElementsByTagName("Attribute");
for (int i = 0; i < attributes.getLength(); i++) {
Node attribute = attributes.item(i);
ERWinDBAttribute erwinAttribute = new ERWinDBAttribute();
String attrId = attribute.getAttributes().getNamedItem("id").getNodeValue().trim();
//logical name
String attrName = attribute.getAttributes().getNamedItem("Name").getNodeValue().trim();
erwinAttribute.setLogicalName(attrName);
attributeMap.put(attrId, erwinAttribute);
String physicalName = "";
String fkAttrName = "";
int attributeType = -1;
boolean duplicate = false;
Node pNode = findPNode(attribute, "Entity");
if (pNode == null) {
continue;
}
String pId = pNode.getAttributes().getNamedItem("id").getNodeValue().trim();
String tableName = physicalNameMap.get(pId);
if (tableName == null) {
tableName = pNode.getAttributes().getNamedItem("Name").getNodeValue().trim();
}
ERWinSchemaInfo schemaInfo = schemaInfos.get(tableName);
for (int ii = 0; ii < attribute.getChildNodes().getLength(); ii++) {
Node tempNode = attribute.getChildNodes().item(ii);
if (tempNode.getNodeName().equals("AttributeProps")) {
physicalName = handler.getChildValueByProperty(tempNode, "Physical_Name");
if (physicalName == null) {
physicalName = attrName;
}
DBAttribute duplicateAttr = schemaInfo.getDBAttributeByName(physicalName, false);
if (duplicateAttr != null) {
duplicate = true;
break;
}
erwinAttribute.setName(physicalName);
columnIdMap.put(attrId, physicalName);
Node attributePropsChild = tempNode.getFirstChild();
while (attributePropsChild != null) {
String attributeName = attributePropsChild.getNodeName();
if (attributeName.equals("Datatype")) {
String dataType = attributePropsChild.getFirstChild().getNodeValue().trim();
if (dataType.startsWith(DataType.getUpperEnumType())) {
//convert to show type
dataType = dataType.replaceFirst(DataType.getUpperEnumType(), DataType.getLowerEnumType());
}
String enumeration = DataType.getEnumeration(dataType);
if (!StringUtil.isEmpty(enumeration)) {
dataType = DataType.getUpperEnumType();
erwinAttribute.setEnumeration(enumeration);
}
erwinAttribute.setType(dataType);
erwinAttribute.setDefault(updateData(dataType, erwinAttribute.getDefault()));
} else if (attributeName.equals("Type")) {
attributeType = Integer.parseInt(attributePropsChild.getFirstChild().getNodeValue().trim());
} else if (attributeName.equals("Null_Option")) {
int value = Integer.parseInt(attributePropsChild.getFirstChild().getNodeValue().trim());
switch(value) {
case 1:
case 8:
erwinAttribute.setNotNull(true);
break;
default:
break;
}
} else if (attributeName.equals("Default")) {
String id = attributePropsChild.getFirstChild().getNodeValue().trim();
Node defaultValueNode = getNodeById(id, "Default_Value");
if (defaultValueNode == null) {
attributePropsChild = attributePropsChild.getNextSibling();
continue;
}
String value = handler.getChildValueByProperty(defaultValueNode, "Default_ValueProps.Server_Value");
if (erwinAttribute.getType() != null) {
value = updateData(erwinAttribute.getType(), value);
}
erwinAttribute.setDefault(value);
} else if (attributeName.equals("Identity_Seed")) {
SerialInfo serialInfo = new SerialInfo();
serialInfo.setIncrementValue(attributePropsChild.getFirstChild().getNodeValue().trim());
erwinAttribute.setAutoIncrement(serialInfo);
} else if (attributeName.equals("Parent_Domain")) {
String id = attributePropsChild.getFirstChild().getNodeValue();
String value = handler.getNodeChildValueById("Domain", id, "DomainProps.Datatype");
if (value == null) {
// if it has reference-id (DomainProps.Parent_Domain)
String refId = handler.getNodeChildValueById("Domain", id, "DomainProps.Parent_Domain");
value = handler.getNodeChildValueById("Domain", refId, "DomainProps.Datatype");
}
if (StringUtil.isEmpty(erwinAttribute.getType())) {
erwinAttribute.setType(DataType.getRealType(StringUtil.toUpper(value)));
}
} else if (attributeName.equals("Parent_Relationship")) {
String id = attributePropsChild.getFirstChild().getNodeValue().trim();
Constraint relType = foreignKeyMap.get(id);
if (relType != null) {
boolean isPk = relType.getType().equals(Constraint.ConstraintType.PRIMARYKEY.getText());
boolean isFk = relType.getType().equals(Constraint.ConstraintType.FOREIGNKEY.getText());
if (isPk || isFk) {
erwinAttribute.setNotNull(true);
erwinAttribute.setUnique(true);
}
}
} else if (attributeName.equals("Physical_Name")) {
physicalName = attributePropsChild.getFirstChild().getNodeValue().trim();
} else if (attributeName.equals("Logical_Datatype")) {
String logicalDataType = attributePropsChild.getFirstChild().getNodeValue().trim();
erwinAttribute.setLogicalDataType(logicalDataType);
} else if (attributeName.equals("Parent_Attribute")) {
String id = attributePropsChild.getFirstChild().getNodeValue().trim();
Node fkAttrNode = getNodeById(id, "Attribute");
if (fkAttrNode == null) {
attributePropsChild = attributePropsChild.getNextSibling();
continue;
}
fkAttrName = handler.getChildValueByProperty(fkAttrNode, "AttributeProps.Physical_Name");
if (fkAttrName == null) {
fkAttrName = fkAttrNode.getAttributes().getNamedItem("Name").getNodeValue().trim();
}
Node fkTableNode = findPNode(fkAttrNode, "Entity");
String fkTableId = fkTableNode.getAttributes().getNamedItem("id").getNodeValue().trim();
String fkTableName = physicalNameMap.get(fkTableId);
erwinAttribute.setInherit(fkTableName);
// SchemaInfo schemaInfo = schemaInfos.get(tName);
// schemaInfo.addSuperClass(tableName);
} else if (attributeName.equals("View_Expression")) {
fkAttrName = attributePropsChild.getFirstChild().getNodeValue().trim();
}
attributePropsChild = attributePropsChild.getNextSibling();
}
}
}
if (duplicate) {
continue;
}
if (attributeType != ERXmlModelConstant.ATTRIBUTE_TYPE_VIEW) {
if (attributeType == ERXmlModelConstant.ATTRIBUTE_TYPE_PK) {
erwinAttribute.setUnique(true);
erwinAttribute.setNotNull(true);
}
erwinAttribute.setInherit(tableName);
schemaInfo.addAttribute(erwinAttribute);
} else {
String viewName = tableName;
if (viewName == null) {
viewName = pNode.getAttributes().getNamedItem("Name").getNodeValue().trim();
}
ViewModel model = viewModelMap.get(viewName);
String pTable = erwinAttribute.getInherit();
if (pTable == null) {
pTable = "DEFAULT";
}
model.addTableColumnAlias(pTable, fkAttrName, erwinAttribute.getName());
}
}
}
use of com.cubrid.common.ui.cubrid.database.erwin.model.ERWinDBAttribute in project cubrid-manager by CUBRID.
the class CubridTableParser method appendLogicalInfo.
/**
* After build physical info to ERTable, append logical info to success
* tables.
*
* @param schemaInfos
* @return void
*/
public void appendLogicalInfo(Map<String, ERWinSchemaInfo> schemaInfos) {
for (ERTable table : successTables) {
String physicalTName = table.getName();
ERWinSchemaInfo erwinSchemaInfo = schemaInfos.get(physicalTName);
String logicalTableName = erwinSchemaInfo.getLogicalName();
if (StringUtil.isEmpty(logicalTableName)) {
logicalTableName = physicalTName;
}
table.setName(logicalTableName, false);
if (!logicalTableName.equals(physicalTName)) {
table.setDescription(logicalTableName);
}
List<ERWinDBAttribute> erwinAttrList = erwinSchemaInfo.getERWinAttributes();
for (ERWinDBAttribute attr : erwinAttrList) {
String physicalColName = attr.getName();
ERTableColumn column = table.getColumn(physicalColName);
String logicalColName = attr.getLogicalName();
if (StringUtil.isEmpty(logicalColName)) {
logicalColName = physicalColName;
}
column.setName(logicalColName, false);
if (!logicalColName.equals(physicalColName)) {
column.setDescription(logicalColName);
}
String logicType = attr.getLogicalDataType();
if (StringUtil.isEmpty(logicType)) {
String physicalRealType = column.getRealType();
logicType = column.getERSchema().convert2LogicalShowType(physicalRealType);
}
column.setShowType(logicType, false);
}
}
}
use of com.cubrid.common.ui.cubrid.database.erwin.model.ERWinDBAttribute in project cubrid-manager by CUBRID.
the class ImportERwinDataController method buildERDSchema.
private void buildERDSchema(ERSchema erSchema, Map<String, ERWinSchemaInfo> schemaInfos) {
String message = "";
CubridTableParser tableParser = new CubridTableParser(erSchema);
Set<SchemaInfo> dbSchemaInfos = new HashSet<SchemaInfo>();
Collection<ERWinSchemaInfo> erwinSchemas = schemaInfos.values();
for (ERWinSchemaInfo erwinSchema : erwinSchemas) {
SchemaInfo schemaInfo = (SchemaInfo) erwinSchema;
dbSchemaInfos.add(schemaInfo);
}
tableParser.buildERTables(dbSchemaInfos, -1, -1, true);
tableParser.appendLogicalInfo(schemaInfos);
List<ERTable> successTables = tableParser.getSuccessTables();
for (ERTable table : successTables) {
ERWinSchemaInfo savedTable = schemaInfos.get(table.getName());
table.setLogicalName(savedTable.getLogicalName());
List<ERTableColumn> columns = table.getColumns();
for (ERTableColumn column : columns) {
String colName = column.getName();
ERWinDBAttribute savedDBAttr = savedTable.getERWinDBAttr(colName);
column.setLogicalName(savedDBAttr.getLogicalName());
column.setLogicalType(savedDBAttr.getLogicalDataType());
}
}
erSchema.FireAddedTable(successTables);
Map<String, Exception> failedTables = tableParser.getFailedTables();
Map<String, List<Constraint>> removedFKs = tableParser.getRemovedFKConstraints();
if (failedTables.size() > 0) {
message = Messages.bind(com.cubrid.common.ui.er.Messages.errorAddTables, failedTables.keySet());
}
if (removedFKs.size() > 0) {
if (!message.equals("")) {
message += "\n";
}
message += Messages.bind(com.cubrid.common.ui.er.Messages.cannotBeBuiltFK, tableParser.getOneRemovedFK().getName());
if (tableParser.getRemovedFKCount() > 1) {
message += ", ...";
}
}
if (!message.equals("")) {
CommonUITool.openErrorBox(message);
}
}
Aggregations