use of com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo in project cubrid-manager by CUBRID.
the class ERXmlContainer method createSchemaInfo.
/**
* parse the entity attribute to create the table schema info.
* <Attribute_Groups>
*
* @param childNodes
*/
private void createSchemaInfo() {
for (String tableName : tableSchemas.keySet()) {
ERWinSchemaInfo schemaInfo = new ERWinSchemaInfo();
schemaInfo.setType("user");
schemaInfo.setClassname(tableName);
schemaInfos.put(tableName, schemaInfo);
}
initCache();
parseKeyGroupGroups();
parseEntityProps();
parseRelationGroups();
parseAttributes();
createSchemaDDL();
}
use of com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo in project cubrid-manager by CUBRID.
the class ERXmlContainer method parseEntityProps.
/**
* parse the <EntityProps> node
*
* @param schema
* @param database
* @param property
*/
private void parseEntityProps() {
NodeList entityProps = doc.getElementsByTagName("EntityProps");
for (int i = 0; i < entityProps.getLength(); i++) {
Node node = entityProps.item(i);
Node childNode = node.getFirstChild();
Node pNode = findPNode(childNode, "Entity");
if (pNode == null) {
continue;
}
String name = pNode.getAttributes().getNamedItem("Name").getNodeValue().trim();
if (name != null) {
name = name.trim();
}
String pId = pNode.getAttributes().getNamedItem("id").getNodeValue().trim();
String physicalName = physicalNameMap.get(pId);
int type = 0;
while (childNode != null) {
if (childNode.getNodeName().equals("Type")) {
if (childNode.getFirstChild().getNodeValue().trim() != null) {
type = Integer.parseInt(childNode.getFirstChild().getNodeValue().trim());
}
if (type == ERXmlModelConstant.ENTITYTYPE_VIEW_INT) {
ViewModel model = new ViewModel();
model.setViewName(name);
viewModelMap.put(name, model);
}
} else if (childNode.getNodeName().equals("Physical_Name")) {
physicalName = childNode.getFirstChild().getNodeValue().trim();
} else if (childNode.getNodeName().equals("View_With_Check")) {
ViewModel model = viewModelMap.get(name);
model.setWithCheck(true);
} else if (childNode.getNodeName().equals("View_Where")) {
ViewModel model = viewModelMap.get(name);
model.setWhereSql(childNode.getFirstChild().getNodeValue().trim());
} else if (childNode.getNodeName().equals("View_Distinct")) {
ViewModel model = viewModelMap.get(name);
model.setDistinct(Boolean.parseBoolean(childNode.getFirstChild().getNodeValue().trim()));
} else if (childNode.getNodeName().equals("View_Group_By")) {
ViewModel model = viewModelMap.get(name);
model.setGroupBySql(childNode.getFirstChild().getNodeValue().trim());
} else if (childNode.getNodeName().equals("View_Having")) {
ViewModel model = viewModelMap.get(name);
model.setHavingSql(childNode.getFirstChild().getNodeValue().trim());
}
childNode = childNode.getNextSibling();
}
if (physicalName != null) {
if (type == ERXmlModelConstant.ENTITYTYPE_VIEW_INT) {
ViewModel model = viewModelMap.get(name);
model.setViewName(physicalName);
viewModelMap.remove(name);
viewModelMap.put(physicalName, model);
}
} else {
physicalName = name;
}
ERWinSchemaInfo schema = schemaInfos.get(physicalName);
schema.setVirtual((type != ERXmlModelConstant.ENTITYTYPE_VIEW_INT) ? ClassType.NORMAL.getText() : ClassType.VIEW.getText());
schema.setLogicalName(name);
}
}
use of com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo 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.ERWinSchemaInfo in project cubrid-manager by CUBRID.
the class ERXmlContainer method createSchemaDDL.
private void createSchemaDDL() {
DatabaseInfo info = database.getDatabaseInfo();
if (info == null) {
LOGGER.error("The databaseInfo is a null.");
return;
}
WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info.getDbName(), info.getServerInfo());
ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
Map<String, SchemaInfo> dbSchemaInfos = new HashMap<String, SchemaInfo>();
Collection<ERWinSchemaInfo> erwinSchemas = schemaInfos.values();
for (ERWinSchemaInfo erwinSchema : erwinSchemas) {
SchemaInfo schemaInfo = (SchemaInfo) erwinSchema;
dbSchemaInfos.put(schemaInfo.getClassname(), schemaInfo);
}
wrappedDatabaseInfo.addSchemaInfos(dbSchemaInfos);
wrappedDatabaseInfo.addTableSchemas(tableSchemas);
SchemaDDL ddl = new SchemaDDL(null, wrappedDatabaseInfo);
for (String tableName : tableSchemas.keySet()) {
TableSchema tableSchema = tableSchemas.get(tableName);
SchemaInfo schemaInfo = schemaInfos.get(tableName);
if (schemaInfo == null) {
continue;
}
String strDDL = "";
if (schemaInfo.getVirtual().equals(ClassType.VIEW.getText())) {
strDDL = createViewSchema(schemaInfo);
} else {
strDDL = ddl.getSchemaDDL(schemaInfo);
}
tableSchema.setSchemaInfo(strDDL);
}
}
use of com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo in project cubrid-manager by CUBRID.
the class ImportERwinAction method createCompareModel.
/**
*
* @param tableSchema
* @param schemaInfos
*/
private void createCompareModel(final String modelName, final Map<String, TableSchema> tableSchema, final Map<String, ERWinSchemaInfo> schemaInfos) {
final List<TableSchemaCompareModelInputLazy> input = new ArrayList<TableSchemaCompareModelInputLazy>();
ITask reportBugTask = new AbstractUITask() {
private boolean success = false;
public void cancel() {
}
public void finish() {
}
public boolean isCancel() {
return false;
}
public boolean isSuccess() {
return success;
}
public void execute(IProgressMonitor monitor) {
List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(database);
final CubridDatabase virtualDb = new CubridDatabase(modelName, modelName);
virtualDb.setVirtual(true);
DatabaseInfo info = database.getDatabaseInfo();
virtualDb.setDatabaseInfo(info);
WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info);
Map<String, SchemaInfo> dbSchemaInfos = new HashMap<String, SchemaInfo>();
Collection<ERWinSchemaInfo> erwinSchemas = schemaInfos.values();
for (ERWinSchemaInfo erwinSchema : erwinSchemas) {
SchemaInfo schemaInfo = (SchemaInfo) erwinSchema;
dbSchemaInfos.put(schemaInfo.getClassname(), schemaInfo);
}
wrappedDatabaseInfo.addSchemaInfos(dbSchemaInfos);
wrappedDatabaseInfo.addTableSchemas(tableSchema);
ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
TableSchemaModel leftModel = TableSchemaCompareUtil.createTableSchemaModel(leftDbTableInfoList);
TableSchemaModel rightModel = new TableSchemaModel();
rightModel.getTableSchemaMap().putAll(tableSchema);
TableSchemaComparator comparator = new TableSchemaComparator(database, virtualDb);
TableSchemaCompareModel model = comparator.compare(leftModel, rightModel);
model.setSourceDB(database);
model.setTargetDB(virtualDb);
// TODO rename class to ErwinCompareModelInput
input.add(new TableSchemaCompareModelInputLazy(model));
success = true;
}
};
TaskExecutor taskExecutor = new CommonTaskExec(Messages.titleSchemaComparison);
taskExecutor.addTask(reportBugTask);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input.get(0), TableSchemaCompareInfoPart.ID);
} catch (Exception e) {
}
}
}
Aggregations