use of com.cubrid.common.core.common.model.DBAttribute 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.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableSchemaCompareComposite method getTableSchema.
private String getTableSchema(CubridDatabase db, Map<String, SchemaInfo> schemas, String tableName) {
// FIXME logic code move to core module
String tableSchemaInfo = "";
try {
SchemaInfo schemaInfo = schemas.get(tableName);
if (schemaInfo == null) {
return "";
}
if (schemaInfo.getVirtual().equals(ClassType.VIEW.getText())) {
GetAllClassListTask getAllClassListTask = new GetAllClassListTask(db.getDatabaseInfo());
getAllClassListTask.setTableName(tableName);
getAllClassListTask.getClassInfoTaskExcute();
ClassInfo classInfo = getAllClassListTask.getClassInfo();
GetAllAttrTask getAllAttrTask = new GetAllAttrTask(db.getDatabaseInfo());
getAllAttrTask.setClassName(tableName);
getAllAttrTask.getAttrList();
List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
List<Map<String, String>> viewColListData = GetInfoDataUtil.getViewColMapList(attrList);
/*Get view column*/
GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(db.getDatabaseInfo());
getAllDBVclassTask.setClassName(tableName);
getAllDBVclassTask.getAllVclassListTaskExcute();
/*Get query list*/
List<String> vclassList = getAllDBVclassTask.getAllVclassList();
List<Map<String, String>> queryListData = new ArrayList<Map<String, String>>();
for (String sql : vclassList) {
Map<String, String> map = new HashMap<String, String>();
map.put("0", sql);
queryListData.add(map);
}
tableSchemaInfo = GetInfoDataUtil.getViewCreateSQLScript(true, db, classInfo, tableName, viewColListData, queryListData);
} else {
SchemaDDL schemaDDL = null;
schemaDDL = new SchemaDDL(null, db.getDatabaseInfo());
tableSchemaInfo = schemaDDL.getSchemaDDL(schemaInfo);
}
} catch (Exception e) {
LOGGER.error("", e);
return "";
}
return tableSchemaInfo;
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableSchemaCompareUpdateDDL method setPositionAlterDDL.
/**
* Compare table Attributes Positions
*/
public void setPositionAlterDDL() {
// FIXME logic code move to core module
List<DBAttribute> targetDBAttributes = targetTableSchema.getAttributes();
List<DBAttribute> sourceDBAttributes = sourceTableSchema.getAttributes();
for (DBAttribute targetAttr : targetDBAttributes) {
String targetAttrName = targetAttr.getName();
int targetPosition = targetDBAttributes.indexOf(targetAttr);
DBAttribute sourceAttr = sourceTableSchema.getDBAttributeByName(targetAttrName, false);
int sourcePosition = sourceDBAttributes.indexOf(sourceAttr);
if (sourceAttr != null && sourcePosition != targetPosition) {
changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceAttr.getName(), targetAttr.getName(), SchemeInnerType.TYPE_POSITION));
}
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableSchemaCompareUpdateDDL method setAttributesAlterDDL.
/**
* Compare table attributes
*/
public void setAttributesAlterDDL() {
// FIXME logic code move to core module
List<DBAttribute> sourceDBAttributes = sourceTableSchema.getAttributes();
List<DBAttribute> targetDBAttributes = targetTableSchema.getAttributes();
for (DBAttribute targetAttr : targetDBAttributes) {
String targetAttrName = targetAttr.getName().toLowerCase();
DBAttribute sourceAttr = sourceTableSchema.getDBAttributeByName(targetAttrName, false);
if (sourceAttr != null) {
if (!targetAttr.equals(sourceAttr)) {
changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceAttr.getName(), targetAttrName, SchemeInnerType.TYPE_ATTRIBUTE));
changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceAttr.getName(), targetAttrName, SchemeInnerType.TYPE_POSITION));
}
} else {
changeManager.addSchemeChangeLog(new SchemaChangeLog(null, targetAttrName, SchemeInnerType.TYPE_ATTRIBUTE));
changeManager.addSchemeChangeLog(new SchemaChangeLog(targetAttrName, targetAttrName, SchemeInnerType.TYPE_POSITION));
}
}
for (DBAttribute sourceAttr : sourceDBAttributes) {
String sourceAttrName = sourceAttr.getName();
DBAttribute targetAttr = targetTableSchema.getDBAttributeByName(sourceAttrName, false);
if (targetAttr == null) {
changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceAttrName, null, SchemeInnerType.TYPE_ATTRIBUTE));
}
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class FileToTableMappingComposite method parseData.
@SuppressWarnings("unchecked")
private void parseData(final Map<String, String> tableToFile) throws Exception {
allTableList = (List<ICubridNode>) treeViewer.getInput();
final List<ICubridNode> newMappedNodeList = new ArrayList<ICubridNode>();
final ImportConfig importConfig = importSettingPage.getImportDataWizard().getImportConfig();
ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
progress.setCancelable(true);
progress.run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
monitor.beginTask(Messages.taskParsingData, tableToFile.size());
for (Entry<String, String> entry : tableToFile.entrySet()) {
// FIXME move this logic to core module
String tableName = entry.getKey();
String filePath = entry.getValue();
File file = new File(filePath);
String fileName = file.getName();
monitor.subTask(Messages.bind(Messages.taskParsingFile, fileName));
List<String> fileColumnList = new ArrayList<String>();
List<String> firstRowColsLst = new ArrayList<String>();
List<String> colNameList = new ArrayList<String>();
List<String> colTypeList = new ArrayList<String>();
int totalLine = 0;
List<Integer> itemsNumberOfSheets = null;
/*Find the class node*/
ICubridNode classNode = getTableNode(tableName);
/*Process file*/
ImportFileHandler importFileHandler = ImportFileHandlerFactory.getHandler(file.getAbsolutePath(), importConfig);
ImportFileDescription ifd = getFileDescription(importFileHandler);
firstRowColsLst.addAll(ifd.getFirstRowCols());
totalLine = ifd.getTotalCount();
itemsNumberOfSheets = ifd.getItemsNumberOfSheets();
boolean isFirstLineAsColumnName = isFirstLineAsColumnName(tableName);
fillInFromList(fileColumnList, firstRowColsLst, isFirstLineAsColumnName);
if (isFirstLineAsColumnName) {
handleSelectEventForFirstRowAsColBtn(itemsNumberOfSheets, fileColumnList, firstRowColsLst, totalLine, isFirstLineAsColumnName);
}
if (classNode != null) {
Object isNew = classNode.getData(ImportObjectLabelProvider.IS_NEW);
if (isNew == null || !(Boolean) isNew) {
SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
List<DBAttribute> attributes = schemaInfo == null ? null : schemaInfo.getAttributes();
if (attributes == null) {
return;
}
for (DBAttribute attr : attributes) {
String column = attr.getName();
String dataType = attr.getType();
colNameList.add(column);
colTypeList.add(dataType);
}
} else {
removeClassNode(classNode);
classNode = createClassNode(tableName, isFirstLineAsColumnName(tableName), firstRowColsLst, colNameList, colTypeList);
}
} else if (importConfig.isCreateTableAccordingData()) {
classNode = createClassNode(tableName, isFirstLineAsColumnName(tableName), firstRowColsLst, colNameList, colTypeList);
} else {
failedFileList.add(file.getAbsolutePath());
continue;
}
if (fileColumnList.size() == colNameList.size()) {
classNode.setData(ImportObjectLabelProvider.IS_MAPPED, true);
classNode.setData(ImportObjectLabelProvider.FILE_PAHT, fileName);
classNode.setData(ImportObjectLabelProvider.ROW_COUNT, totalLine);
List<PstmtParameter> parameterList = new ArrayList<PstmtParameter>();
for (int i = 0; i < fileColumnList.size(); i++) {
PstmtParameter pstmtParameter = new PstmtParameter(colNameList.get(i), i + 1, colTypeList.get(i), String.valueOf(i));
pstmtParameter.setFileColumnName(fileColumnList.get(i));
parameterList.add(pstmtParameter);
}
TableConfig tableConfig = new TableConfig(classNode.getName());
tableConfig.setPstmList(parameterList);
tableConfig.setFilePath(file.getAbsolutePath());
tableConfig.setInsertDML(getInsertDML(classNode, colNameList, colTypeList));
tableConfig.setLineCount(totalLine);
tableConfig.setMapped(true);
Object isNew = classNode.getData(ImportObjectLabelProvider.IS_NEW);
if (isNew != null && (Boolean) isNew) {
tableConfig.setCreateDDL(classNode.getData(ImportObjectLabelProvider.CREATE_DDL).toString());
}
importConfig.addTableConfig(tableConfig);
newMappedNodeList.add(classNode);
} else {
classNode.setData(ImportObjectLabelProvider.IS_MAPPED, false);
classNode.setData(ImportObjectLabelProvider.FILE_PAHT, fileName);
classNode.setData(ImportObjectLabelProvider.ROW_COUNT, totalLine);
TableConfig tableConfig = importConfig.getSelectedMap().get(classNode.getName());
if (tableConfig != null) {
tableConfig.setMapped(false);
tableConfig.setFilePath(filePath);
tableConfig.setLineCount(totalLine);
tableConfig.getPstmList().clear();
tableConfig.setInsertDML("");
}
failedFileList.add(fileName);
}
monitor.worked(1);
if (monitor.isCanceled()) {
return;
}
}
}
});
for (ICubridNode node : allTableList) {
if (newMappedNodeList.contains(node)) {
treeViewer.setChecked(node, true);
}
}
treeViewer.refresh();
}
Aggregations