Search in sources :

Example 1 with ERWinSchemaInfo

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();
}
Also used : ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)

Example 2 with ERWinSchemaInfo

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);
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 3 with ERWinSchemaInfo

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());
        }
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERWinDBAttribute(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinDBAttribute) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo) ERWinDBAttribute(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinDBAttribute) SerialInfo(com.cubrid.common.core.common.model.SerialInfo) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 4 with ERWinSchemaInfo

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);
    }
}
Also used : TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) HashMap(java.util.HashMap) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)

Example 5 with ERWinSchemaInfo

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) {
        }
    }
}
Also used : TableSchemaCompareModelInputLazy(com.cubrid.common.ui.compare.schema.control.TableSchemaCompareModelInputLazy) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) HashMap(java.util.HashMap) TableSchemaComparator(com.cubrid.common.ui.compare.schema.TableSchemaComparator) ArrayList(java.util.ArrayList) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) TableSchemaModel(com.cubrid.common.ui.compare.schema.model.TableSchemaModel) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)

Aggregations

ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)8 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)3 ERWinDBAttribute (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinDBAttribute)3 Constraint (com.cubrid.common.core.common.model.Constraint)2 TableSchema (com.cubrid.common.ui.compare.schema.model.TableSchema)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 HashMap (java.util.HashMap)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)1 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)1 TableDetailInfo (com.cubrid.common.core.common.model.TableDetailInfo)1 AbstractUITask (com.cubrid.common.core.task.AbstractUITask)1 ITask (com.cubrid.common.core.task.ITask)1 TableSchemaComparator (com.cubrid.common.ui.compare.schema.TableSchemaComparator)1 TableSchemaCompareModelInputLazy (com.cubrid.common.ui.compare.schema.control.TableSchemaCompareModelInputLazy)1 TableSchemaCompareModel (com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel)1 TableSchemaModel (com.cubrid.common.ui.compare.schema.model.TableSchemaModel)1 ERXmlContainer (com.cubrid.common.ui.cubrid.database.erwin.ERXmlContainer)1