Search in sources :

Example 46 with Constraint

use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.

the class AttributeCellModifier method replaceNewConstraintAttributeName.

/**
	 * Replace new constraint attribute name
	 */
private void replaceNewConstraintAttributeName(SchemaInfo schemaInfo, String oldAttr, String newAttr) {
    // FIXME move this logic to core module
    for (Constraint constraint : schemaInfo.getConstraints()) {
        constraint.replaceAttribute(oldAttr, newAttr);
        constraint.replaceClassAttribute(oldAttr, newAttr);
        /*Replace the rule*/
        if (!Constraint.ConstraintType.FOREIGNKEY.equals(constraint.getType())) {
            List<String> rulesList = constraint.getRules();
            for (int i = 0; i < rulesList.size(); i++) {
                String rule = rulesList.get(i);
                int index = rule.indexOf(" ");
                String attrName = rule.substring(0, index);
                String rulePart = rule.substring(index);
                if (StringUtil.isEqualNotIgnoreNull(attrName, oldAttr)) {
                    rulesList.set(i, newAttr + rulePart);
                }
            }
        }
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 47 with Constraint

use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.

the class TableEditorPart method init.

public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    TableEditorInput tableInfoEditorInput = (TableEditorInput) input;
    this.database = tableInfoEditorInput.getDatabase();
    this.editedTableNode = tableInfoEditorInput.getEditedTableNode();
    this.isNewTableFlag = tableInfoEditorInput.isNewTableFlag();
    this.dbUserList = tableInfoEditorInput.getDbUserList();
    this.showDefaultType = tableInfoEditorInput.getType();
    this.collationList = tableInfoEditorInput.getCollationList();
    if (collationList != null) {
        Collation emptyCollation = new Collation();
        emptyCollation.setCharset("");
        emptyCollation.setName("");
        collationList.add(0, emptyCollation);
    }
    this.oldSchemaInfo = tableInfoEditorInput.getSchemaInfo();
    this.supportCharset = CompatibleUtil.isSupportCreateDBByCharset(database.getDatabaseInfo());
    if (isNewTableFlag) {
        newSchemaInfo = new SchemaInfo();
        //$NON-NLS-1$
        newSchemaInfo.setClassname("");
        newSchemaInfo.setOwner(database.getUserName());
        newSchemaInfo.setDbname(database.getName());
        newSchemaInfo.setType(Messages.userSchema);
        newSchemaInfo.setVirtual(Messages.schemaTypeClass);
        if (database.getDatabaseInfo() != null) {
            newSchemaInfo.setCollation(database.getDatabaseInfo().getCollation());
        }
    } else {
        newSchemaInfo = null;
        if (tableInfoEditorInput.getSchemaInfo() != null) {
            newSchemaInfo = tableInfoEditorInput.getSchemaInfo().clone();
            originalConstraints.addAll(newSchemaInfo.getConstraints());
        }
    }
    if (supportCharset) {
        columnProperites = new String[] { IAttributeColumn.COL_EMPTY, IAttributeColumn.COL_FLAG, IAttributeColumn.COL_NAME, IAttributeColumn.COL_DATATYPE, IAttributeColumn.COL_DEFAULT, IAttributeColumn.COL_AUTO_INCREMENT, IAttributeColumn.COL_NOT_NULL, IAttributeColumn.COL_PK, IAttributeColumn.COL_UK, IAttributeColumn.COL_SHARED, IAttributeColumn.COL_COLLATION, IAttributeColumn.COL_MEMO };
    } else {
        columnProperites = new String[] { IAttributeColumn.COL_EMPTY, IAttributeColumn.COL_FLAG, IAttributeColumn.COL_NAME, IAttributeColumn.COL_DATATYPE, IAttributeColumn.COL_DEFAULT, IAttributeColumn.COL_AUTO_INCREMENT, IAttributeColumn.COL_NOT_NULL, IAttributeColumn.COL_PK, IAttributeColumn.COL_UK, IAttributeColumn.COL_SHARED, IAttributeColumn.COL_MEMO };
    }
    Connection conn = null;
    try {
        conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
        IDatabaseSpec dbSpec = database.getDatabaseInfo();
        isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
        database.getDatabaseInfo().setSupportTableComment(isSupportTableComment);
        if (isSupportTableComment && !isNewTableFlag && newSchemaInfo != null) {
            Map<String, SchemaComment> map = SchemaCommentHandler.loadDescription(dbSpec, conn, newSchemaInfo.getClassname());
            for (DBAttribute attr : newSchemaInfo.getAttributes()) {
                SchemaComment schemaComment = SchemaCommentHandler.find(map, newSchemaInfo.getClassname(), attr.getName());
                if (schemaComment != null) {
                    attr.setDescription(schemaComment.getDescription());
                }
            }
            // get description for index
            for (Constraint cons : newSchemaInfo.getConstraints()) {
                if (CompatibleUtil.isCommentSupports(dbSpec)) {
                    String indexName = cons.getName();
                    SchemaComment indexComment = SchemaCommentHandler.loadObjectDescription(dbSpec, conn, indexName, CommentType.INDEX);
                    if (indexComment != null) {
                        cons.setDescription(indexComment.getDescription());
                    }
                }
            }
            SchemaComment schemaComment = SchemaCommentHandler.find(map, newSchemaInfo.getClassname(), null);
            if (schemaComment != null) {
                newSchemaInfo.setDescription(schemaComment.getDescription());
            }
        }
    } catch (SQLException e) {
        LOGGER.error("", e);
    } catch (Exception e) {
        LOGGER.error("", e);
    } finally {
        QueryUtil.freeQuery(conn);
    }
    schemaChangeMgr = new SchemaChangeManager(database.getDatabaseInfo(), isNewTableFlag);
    schemaDDL = new SchemaDDL(schemaChangeMgr, database.getDatabaseInfo());
    if (database != null) {
        isSupportChange = CompatibleUtil.isSupportChangeColumn(database.getDatabaseInfo());
    }
    setSite(site);
    setInput(input);
    setPartName(input.getName());
    setTitleToolTip(input.getName());
    setTitleImage(CommonUIPlugin.getImage("icons/navigator/schema_table.png"));
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) SQLException(java.sql.SQLException) SchemaChangeManager(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeManager) Connection(java.sql.Connection) Collation(com.cubrid.cubridmanager.core.cubrid.database.model.Collation) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 48 with Constraint

use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.

the class TableEditorPart method changeForEditAttribute.

/**
	 * Make a change log for editing attribute
	 *
	 * @param attrName
	 * @param lastAttr attribute previous changed by the user
	 * @param editAttr attribute to be changed by the user
	 * @param origAttr attribute on a server
	 * @return
	 */
public boolean changeForEditAttribute(String attrName, DBAttribute editAttr, DBAttribute origAttr) {
    // FIXME move this logic to core module
    if (database == null || editAttr == null) {
        return false;
    }
    String tableName = newSchemaInfo.getClassname();
    editAttr.setInherit(tableName);
    String newAttrName = editAttr.getName();
    // new attribute
    if (origAttr == null) {
        if (!StringUtil.isEmpty(attrName) && newSchemaInfo.replaceDBAttributeByName(attrName, editAttr)) {
            // replace
            addDropAttrLog(attrName, false);
            addNewAttrLog(newAttrName, false);
        }
    } else {
        // existed attribute to changed with a name
        addEditAttrLog(attrName, newAttrName, false);
    }
    if (origAttr == null) {
        origAttr = new DBAttribute();
    }
    if (!origAttr.isUnique() && newSchemaInfo.getUniqueByAttrName(editAttr.getName()) == null && editAttr.isUnique()) {
        Constraint unique = new Constraint(true);
        unique.setType(Constraint.ConstraintType.UNIQUE.getText());
        unique.addAttribute(newAttrName);
        unique.addRule(newAttrName + " ASC");
        unique.setName(ConstraintNamingUtil.getUniqueName(tableName, unique.getRules()));
        newSchemaInfo.addConstraint(unique);
        addNewUniqueLog(unique);
    } else if (origAttr.isUnique() && !editAttr.isUnique()) {
        if (oldSchemaInfo != null) {
            Constraint unique = oldSchemaInfo.getUniqueByAttrName(origAttr.getName());
            addDelUniqueLog(unique);
        }
        newSchemaInfo.removeUniqueByAttrName(attrName);
    } else if (!origAttr.isUnique() && !editAttr.isUnique()) {
        Constraint unique = newSchemaInfo.getUniqueByAttrName(attrName);
        if (unique != null) {
            addDelUniqueLog(unique);
        }
        newSchemaInfo.removeUniqueByAttrName(attrName);
    }
    indexTableView.setInput(newSchemaInfo);
    fkTableView.setInput(newSchemaInfo);
    if (database != null && database.getDatabaseInfo() != null && newSchemaInfo != null) {
        SuperClassUtil.fireSuperClassChanged(database.getDatabaseInfo(), oldSchemaInfo, newSchemaInfo, newSchemaInfo.getSuperClasses());
    }
    attrLabelProvider.setSchema(newSchemaInfo);
    loadColumnData();
    columnTableView.setSelection(new StructuredSelection(editAttr), true);
    columnsTable.setFocus();
    handleSelectionChangeInColumnTable();
    return true;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 49 with Constraint

use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.

the class TableEditorPart method openEditIndexDialog.

/**
	 * Open the index edit dialog with the constraint object
	 *
	 * @param editedIndex Constraint
	 */
private void openEditIndexDialog(Constraint editedIndex) {
    boolean isNewConstraint = true;
    for (int i = 0, len = originalConstraints.size(); i < len; i++) {
        if (originalConstraints.get(i) == editedIndex) {
            isNewConstraint = false;
        }
    }
    AddIndexDialog dlg = new AddIndexDialog(getSite().getShell(), newSchemaInfo, database, editedIndex, isNewConstraint);
    int returnCode = dlg.open();
    if (returnCode == AddIndexDialog.OK) {
        Constraint newIndex = dlg.getIndexConstraint();
        if (newIndex == null) {
            return;
        }
        newSchemaInfo.removeConstraintByName(editedIndex.getName(), editedIndex.getType());
        newSchemaInfo.addConstraint(newIndex);
        // For bug TOOLS-2394 Unique index can't be added again
        if (Constraint.ConstraintType.UNIQUE.getText().equals(newIndex.getType()) && newIndex.getAttributes().size() == 1) {
            DBAttribute attr = newSchemaInfo.getDBAttributeByName(newIndex.getAttributes().get(0), false);
            attr.setUnique(true);
            loadColumnData();
        }
        boolean modifiedUK = Constraint.ConstraintType.UNIQUE.getText().equals(editedIndex.getType()) && editedIndex.getAttributes().size() == 1;
        boolean noNewUK = !Constraint.ConstraintType.UNIQUE.getText().equals(newIndex.getType()) || newIndex.getAttributes().size() != 1;
        if (modifiedUK && noNewUK) {
            String attrName = editedIndex.getAttributes().get(0);
            DBAttribute attr = newSchemaInfo.getDBAttributeByName(attrName, false);
            if (attr != null) {
                attr.setUnique(false);
                loadColumnData();
            }
        }
        String key1 = editedIndex.getDefaultName(newSchemaInfo.getClassname()) + "$" + editedIndex.getName();
        String key2 = newIndex.getDefaultName(newSchemaInfo.getClassname()) + "$" + newIndex.getName();
        SchemaChangeLog changeLog = new SchemaChangeLog(key1, key2, SchemeInnerType.TYPE_INDEX);
        schemaChangeMgr.addSchemeChangeLog(changeLog);
        indexTableView.setInput(newSchemaInfo);
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) AddIndexDialog(com.cubrid.common.ui.cubrid.table.dialog.AddIndexDialog) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)

Example 50 with Constraint

use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.

the class ExportSchemaTask method execute.

public void execute() {
    // FIXME logic code move to core module
    entityMap.clear();
    relationshipMap.clear();
    entityAttrMap.clear();
    ERwin4 root = new ERwin4();
    Model model = new Model();
    // DEFUALT database type "ODBC" "194"
    model.setTargetServer("194");
    model.setDbmsVersion("3");
    model.setModelProps(new Model.ModelProps());
    model.getModelProps().setDbmsVersion(new DBMSVersion());
    model.getModelProps().getDbmsVersion().setValue("3");
    model.getModelProps().setTargetServer(new TargetServer());
    model.getModelProps().getTargetServer().setValue("194");
    model.setId(getUUID());
    root.setModel(model);
    RelationshipGroups relationShipGroups = new RelationshipGroups();
    model.setRelationshipGroups(relationShipGroups);
    model.setDefaultValueGroups(new DefaultValueGroups());
    EntityGroups groups = new EntityGroups();
    model.setEntityGroups(groups);
    for (Entry<String, SchemaInfo> entry : allSchemaInfos.entrySet()) {
        String physicalTableName = entry.getKey();
        String logicalTableName = physicalTableName;
        if (tablePLMap != null) {
            String logical = tablePLMap.get(physicalTableName);
            logicalTableName = StringUtil.isEmpty(logical) ? physicalTableName : logical;
        }
        SchemaInfo schemaInfo = entry.getValue();
        if (schemaInfo.isSystemClass()) {
            continue;
        }
        Entity entity = new Entity();
        groups.getEntity().add(entity);
        entity.setId(getUUID());
        entity.setName(logicalTableName);
        entityMap.put(physicalTableName, entity);
        entityAttrMap.put(physicalTableName, new HashMap<String, Attribute>());
        EntityPropsList entityPropsList = new EntityPropsList();
        entity.setEntityProps(entityPropsList);
        entityPropsList.setPhysicalName(new EntityPropsList.PhysicalName());
        entityPropsList.getPhysicalName().setValue(physicalTableName);
        Type type = new Type();
        if (schemaInfo.getVirtual().equals(ClassType.NORMAL.getText())) {
            type.setValue(ERXmlModelConstant.ENTITYTYPE_TABLE_STR);
        } else {
            type.setValue(ERXmlModelConstant.ENTITYTYPE_VIEW_STR);
        }
        entityPropsList.setType(type);
        Name nameEntityProps = new Name();
        nameEntityProps.setValue(logicalTableName);
        entityPropsList.setName(nameEntityProps);
        List<DBAttribute> attributes = schemaInfo.getAttributes();
        AttributeGroups attributeGroups = new AttributeGroups();
        entity.setAttributeGroups(attributeGroups);
        Map<String, Attribute> schemaAttrMap = new HashMap<String, Attribute>();
        int attrOrder = 1;
        for (DBAttribute dbAttr : attributes) {
            Attribute attribute = new Attribute();
            attributeGroups.getAttribute().add(attribute);
            attribute.setId(getUUID());
            String logicalAttrName = getLogicalAttrName(physicalTableName, dbAttr.getName());
            if (StringUtil.isEmpty(logicalAttrName)) {
                logicalAttrName = dbAttr.getName();
            }
            attribute.setName(logicalAttrName);
            schemaAttrMap.put(dbAttr.getName(), attribute);
            AttributePropsList attributePropsList = new AttributePropsList();
            attribute.setAttributeProps(attributePropsList);
            attributePropsList.setPhysicalName(new PhysicalName());
            attributePropsList.getPhysicalName().setValue(dbAttr.getName());
            com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.Type attrType = new com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.Type();
            attributePropsList.setType(attrType);
            if (dbAttr.isNotNull() && dbAttr.isUnique()) {
                attrType.setValue("" + ERXmlModelConstant.ATTRIBUTE_TYPE_PK);
            } else {
                attrType.setValue("100");
            }
            Datatype dataType = new Datatype();
            String typeValue = dbAttr.getType();
            if (!StringUtil.isEmpty(dbAttr.getEnumeration())) {
                typeValue += dbAttr.getEnumeration();
            }
            dataType.setValue(typeValue);
            attributePropsList.setDataType(dataType);
            com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.Name propName = new com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.Name();
            propName.setValue(logicalAttrName);
            attributePropsList.setName(propName);
            LogicalDataType logicalDataType = new LogicalDataType();
            String logicalAttrType = getLogicalAttrType(physicalTableName, dbAttr.getName());
            if (StringUtil.isEmpty(logicalAttrType)) {
                logicalAttrType = typeValue;
            }
            logicalDataType.setValue(logicalAttrType);
            attributePropsList.setLogicalDataType(logicalDataType);
            if (dbAttr.isNotNull()) {
                NullOption nullOption = new NullOption();
                nullOption.setValue("" + 1);
                attributePropsList.setNullOption(nullOption);
            }
            Order order = new Order();
            attributePropsList.setOrder(order);
            order.setValue("" + attrOrder++);
            if (dbAttr.getDefault() != null) {
                String defaultNameStr = handleSpace(dbAttr.getDefault());
                String defaultName = "default_" + defaultNameStr;
                Default defaultValue = null;
                attributePropsList.setDefaultValue(new AttributePropsList.DefaultValue());
                if (defaultNodeMap.containsKey(defaultName)) {
                    defaultValue = defaultNodeMap.get(defaultName);
                    attributePropsList.getDefaultValue().setValue(defaultValue.getId());
                    continue;
                }
                String defaultId = getUUID();
                DefaultValueGroups defaultValueGroups = model.getDefaultValueGroups();
                attributePropsList.getDefaultValue().setValue(defaultId);
                defaultValue = new Default();
                defaultValue.setId(defaultId);
                defaultValue.setName("default_" + defaultNameStr);
                defaultValueGroups.getDefault().add(defaultValue);
                defaultNodeMap.put(defaultValue.getName(), defaultValue);
                DefaultPropsList defaultPropsList = new DefaultPropsList();
                defaultValue.setDefaultProps(defaultPropsList);
                defaultPropsList.setName(new DefaultPropsList.Name());
                defaultPropsList.getName().setValue(defaultValue.getName());
                defaultPropsList.setServerValue(new ServerValue());
                defaultPropsList.getServerValue().setValue(dbAttr.getDefault());
                defaultPropsList.setLogicalDefaultValue(new LogicalDefaultValue());
                defaultPropsList.getLogicalDefaultValue().setValue(dbAttr.getDefault());
            }
        }
        entityAttrMap.put(physicalTableName, schemaAttrMap);
    }
    List<String> relIds = new ArrayList<String>();
    for (Entry<String, SchemaInfo> entry : allSchemaInfos.entrySet()) {
        Entity entity = entityMap.get(entry.getKey());
        if (entity == null)
            continue;
        SchemaInfo schemaInfo = entry.getValue();
        Map<String, Attribute> schemaAttrMap = entityAttrMap.get(schemaInfo.getClassname());
        KeyGroupGroups keyGroups = new KeyGroupGroups();
        entity.setKeyGroupGroups(keyGroups);
        // counter for index
        int fk = 1;
        int idx = 1;
        int uidx = 1;
        List<Constraint> constraints = schemaInfo.getConstraints();
        for (Constraint constraint : constraints) {
            if (!isValid(constraint)) {
                continue;
            }
            KeyGroup keyGroup = new KeyGroup();
            keyGroups.getKeyGroup().add(keyGroup);
            keyGroup.setId(getUUID());
            keyGroup.setName(constraint.getName());
            KeyGroupPropsList keyGroupPropsList = new KeyGroupPropsList();
            keyGroup.setKeyGroupProps(keyGroupPropsList);
            KeyGroupMemberGroups keyGroupMemberGroups = new KeyGroupMemberGroups();
            keyGroup.setKeyGroupMemberGroups(keyGroupMemberGroups);
            KeyGroupType keyGrouptype = new KeyGroupType();
            keyGroupPropsList.setKeyGroupType(keyGrouptype);
            if (constraint.getType().equals(ConstraintType.PRIMARYKEY.getText())) {
                keyGrouptype.setValue("PK");
                List<String> keyAttr = constraint.getAttributes();
                int order = 1;
                for (String keyName : keyAttr) {
                    KeyGroupMember keyGroupMember = new KeyGroupMember();
                    keyGroupMemberGroups.getKeyGroupMember().add(keyGroupMember);
                    keyGroupMember.setId(getUUID());
                    keyGroupMember.setName("" + order);
                    KeyGroupMemberPropsList propList = new KeyGroupMemberPropsList();
                    keyGroupMember.setKeyGroupMemberProps(propList);
                    KeyGroupPosition position = new KeyGroupPosition();
                    propList.setKeyGroupPosition(position);
                    position.setValue("" + order++);
                    KeyGroupMemberColumn column = new KeyGroupMemberColumn();
                    Attribute attrTemp = schemaAttrMap.get(keyName);
                    column.setValue(attrTemp.getId());
                    propList.setKeyGroupMemberColumn(column);
                }
            } else if (constraint.getType().equals(ConstraintType.FOREIGNKEY.getText())) {
                keyGrouptype.setValue("IF" + fk++);
                String relId = getUUID();
                keyGroupPropsList.setKeyGroupRelationPointer(new KeyGroupRelationPointer());
                keyGroupPropsList.getKeyGroupRelationPointer().setValue(relId);
                relIds.add(relId);
                List<String> keyAttr = constraint.getAttributes();
                String inherit = constraint.getReferencedTable();
                Entity pEntity = entityMap.get(inherit);
                if (pEntity == null) {
                    continue;
                }
                Map<String, Attribute> tempAttrMap = entityAttrMap.get(schemaInfo.getClassname());
                Map<String, Attribute> parentAttrMap = entityAttrMap.get(inherit);
                Relationship relationShip = new Relationship();
                relationShip.setId(relId);
                relationshipMap.put(relId, relationShip);
                relationShip.setName("R/" + fk);
                model.getRelationshipGroups().getRelationship().add(relationShip);
                RelationshipPropsList relationShipPropsList = new RelationshipPropsList();
                relationShip.setRelationshipProps(relationShipPropsList);
                relationShipPropsList.setName(new RelationshipPropsList.Name());
                relationShipPropsList.getName().setValue(relationShip.getName());
                // type == 7 : non-identify fk
                relationShipPropsList.setType(new RelationshipPropsList.Type());
                relationShipPropsList.getType().setValue("2");
                relationShipPropsList.setRelationshipNoNulls(new RelationshipNoNulls());
                relationShipPropsList.getRelationshipNoNulls().setValue("101");
                relationShipPropsList.setRelationshipSequence(new RelationshipSequence());
                relationShipPropsList.getRelationshipSequence().setValue("1");
                relationShipPropsList.setRelationshipParentInsertRule(new RelationshipParentInsertRule());
                relationShipPropsList.getRelationshipParentInsertRule().setValue("0");
                relationShipPropsList.setRelationshipParentUpdateRule(new RelationshipParentUpdateRule());
                relationShipPropsList.setRelationshipParentDeleteRule(new RelationshipParentDeleteRule());
                relationShipPropsList.setRelationshipChildInsertRule(new RelationshipChildInsertRule());
                relationShipPropsList.getRelationshipChildInsertRule().setValue("0");
                relationShipPropsList.setRelationshipChildUpdateRule(new RelationshipChildUpdateRule());
                relationShipPropsList.getRelationshipChildUpdateRule().setValue("0");
                relationShipPropsList.setRelationshipChildDeleteRule(new RelationshipChildDeleteRule());
                relationShipPropsList.getRelationshipChildDeleteRule().setValue("0");
                List<String> rules = constraint.getRules();
                for (String rule : rules) {
                    if (rule.indexOf("ON UPDATE") != -1) {
                        int tmp = rule.replace("ON UPDATE ", "").hashCode();
                        RelationshipParentUpdateRule updateRule = relationShipPropsList.getRelationshipParentUpdateRule();
                        if (tmp == "CASCADE".hashCode()) {
                            updateRule.setValue("10001");
                        } else if (tmp == "NO ACTION".hashCode()) {
                            updateRule.setValue("9998");
                        } else if (tmp == "RESTRICT".hashCode()) {
                            updateRule.setValue("10000");
                        }
                    } else if (rule.indexOf("ON DELETE") != -1) {
                        int tmp = rule.replace("ON DELETE ", "").hashCode();
                        RelationshipParentDeleteRule deleteRule = relationShipPropsList.getRelationshipParentDeleteRule();
                        if (tmp == "CASCADE".hashCode()) {
                            deleteRule.setValue("10005");
                        } else if (tmp == "NO ACTION".hashCode()) {
                            deleteRule.setValue("9999");
                        } else if (tmp == "RESTRICT".hashCode()) {
                            deleteRule.setValue("10004");
                        }
                    }
                }
                relationShipPropsList.setRelationshipParentEntity(new RelationshipParentEntity());
                relationShipPropsList.getRelationshipParentEntity().setValue(pEntity.getId());
                relationShipPropsList.setRelationshipChildEntity(new RelationshipChildEntity());
                relationShipPropsList.getRelationshipChildEntity().setValue(entityMap.get(schemaInfo.getClassname()).getId());
                LinkedList<String> pkAttr = new LinkedList<String>();
                SchemaInfo parentTable = allSchemaInfos.get(inherit);
                for (Constraint con : parentTable.getConstraints()) {
                    if (con.getType().equals(ConstraintType.PRIMARYKEY.getText())) {
                        pkAttr.addAll(con.getAttributes());
                        break;
                    }
                }
                int order = 1;
                for (String keyName : keyAttr) {
                    KeyGroupMember keyGroupMember = new KeyGroupMember();
                    keyGroupMemberGroups.getKeyGroupMember().add(keyGroupMember);
                    keyGroupMember.setId(getUUID());
                    keyGroupMember.setName("" + order);
                    KeyGroupMemberPropsList propList = new KeyGroupMemberPropsList();
                    keyGroupMember.setKeyGroupMemberProps(propList);
                    KeyGroupPosition position = new KeyGroupPosition();
                    propList.setKeyGroupPosition(position);
                    position.setValue("" + order++);
                    KeyGroupMemberColumn column = new KeyGroupMemberColumn();
                    String parentPkAttr = pkAttr.remove();
                    Attribute attrTemp = tempAttrMap.get(keyName);
                    column.setValue(attrTemp.getId());
                    propList.setKeyGroupMemberColumn(column);
                    // Attribute parent part
                    Attribute schemaAttr = schemaAttrMap.get(keyName);
                    AttributePropsList schemaPropList = schemaAttr.getAttributeProps();
                    Attribute parentPkAttrNode = parentAttrMap.get(parentPkAttr);
                    ParentAttribute pAttribute = new ParentAttribute();
                    pAttribute.setValue(parentPkAttrNode.getId());
                    schemaPropList.setParentAttribute(pAttribute);
                    schemaAttr.getAttributeProps().setParentRelationship(new ParentRelationship());
                    schemaAttr.getAttributeProps().getParentRelationship().setValue(relId);
                }
            } else if (constraint.getType().equals(ConstraintType.INDEX.getText()) || constraint.getType().equals(ConstraintType.REVERSEINDEX.getText())) {
                keyGrouptype.setValue("IE" + idx++);
                List<String> keyAttr = constraint.getAttributes();
                int order = 1;
                for (String keyName : keyAttr) {
                    KeyGroupMember keyGroupMember = new KeyGroupMember();
                    keyGroupMemberGroups.getKeyGroupMember().add(keyGroupMember);
                    keyGroupMember.setId(getUUID());
                    keyGroupMember.setName("" + order);
                    KeyGroupMemberPropsList propList = new KeyGroupMemberPropsList();
                    keyGroupMember.setKeyGroupMemberProps(propList);
                    for (String rule : constraint.getRules()) {
                        if (rule.toLowerCase().startsWith(keyName.toLowerCase())) {
                            if (rule.toLowerCase().indexOf(" desc") != -1) {
                                propList.setKeyGroupSortOrder(new KeyGroupSortOrder());
                                propList.getKeyGroupSortOrder().setValue("DESC");
                            }
                        }
                    }
                    KeyGroupPosition position = new KeyGroupPosition();
                    propList.setKeyGroupPosition(position);
                    position.setValue("" + order++);
                    KeyGroupMemberColumn column = new KeyGroupMemberColumn();
                    Attribute attrTemp = schemaAttrMap.get(keyName);
                    column.setValue(attrTemp.getId());
                    propList.setKeyGroupMemberColumn(column);
                }
            } else if (constraint.getType().equals(ConstraintType.UNIQUE.getText()) || constraint.getType().equals(ConstraintType.REVERSEUNIQUE.getText())) {
                keyGrouptype.setValue("AK" + uidx++);
                List<String> keyAttr = constraint.getAttributes();
                int order = 1;
                for (String keyName : keyAttr) {
                    KeyGroupMember keyGroupMember = new KeyGroupMember();
                    keyGroupMemberGroups.getKeyGroupMember().add(keyGroupMember);
                    keyGroupMember.setId(getUUID());
                    keyGroupMember.setName("" + order);
                    KeyGroupMemberPropsList propList = new KeyGroupMemberPropsList();
                    keyGroupMember.setKeyGroupMemberProps(propList);
                    KeyGroupPosition position = new KeyGroupPosition();
                    propList.setKeyGroupPosition(position);
                    position.setValue("" + order++);
                    KeyGroupMemberColumn column = new KeyGroupMemberColumn();
                    Attribute attrTemp = schemaAttrMap.get(keyName);
                    column.setValue(attrTemp.getId());
                    propList.setKeyGroupMemberColumn(column);
                    KeyGroupSortOrder sortOrder = new KeyGroupSortOrder();
                    propList.setKeyGroupSortOrder(sortOrder);
                    for (String rule : constraint.getRules()) {
                        if (rule.toLowerCase().startsWith(keyName.toLowerCase())) {
                            String orderStr = rule.replace(keyName.toLowerCase(), "").replaceAll(" ", "");
                            sortOrder.setValue(orderStr);
                        }
                    }
                }
            }
        }
    }
    setDrawData(model);
    FileOutputStream fout = null;
    try {
        File f = new File(filename);
        if (!f.exists()) {
            try {
                f.createNewFile();
            } catch (IOException e) {
                CommonUITool.openErrorBox(Messages.bind(Messages.errCreateFile, filename));
                return;
            }
        }
        fout = new FileOutputStream(f);
        marshaller.marshal(root, fout);
        fout.close();
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        isSuccess = false;
    } finally {
        try {
            if (fout != null) {
                fout.flush();
                fout.close();
            }
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    isSuccess = true;
}
Also used : RelationshipParentEntity(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList.RelationshipParentEntity) RelationshipChildEntity(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList.RelationshipChildEntity) ReferencedEntity(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.SubjectAreaProps.ReferencedEntity) DrawingObjectEntity(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.DrawingObjectEntity) Entity(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.Entity) KeyGroupMember(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroupMember) RelationshipChildInsertRule(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList.RelationshipChildInsertRule) HashMap(java.util.HashMap) Constraint(com.cubrid.common.core.common.model.Constraint) ArrayList(java.util.ArrayList) NullOption(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.NullOption) LogicalDataType(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.LogicalDataType) Name(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.EntityPropsList.Name) PhysicalName(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.PhysicalName) Datatype(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.Datatype) AttributeGroups(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.Entity.AttributeGroups) RelationshipChildEntity(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList.RelationshipChildEntity) LogicalDefaultValue(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.DefaultPropsList.LogicalDefaultValue) KeyGroupMemberPropsList(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroupMemberPropsList) RelationshipPropsList(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList) AttributePropsList(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) KeyGroupPropsList(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroupPropsList) EntityPropsList(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.EntityPropsList) DefaultPropsList(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.DefaultPropsList) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) KeyGroupSortOrder(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroupMemberPropsList.KeyGroupSortOrder) Order(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.Order) KeyGroupMemberColumn(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroupMemberPropsList.KeyGroupMemberColumn) KeyGroupPropsList(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroupPropsList) LinkedList(java.util.LinkedList) RelationshipSequence(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList.RelationshipSequence) KeyGroupMemberGroups(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroup.KeyGroupMemberGroups) RelationshipParentUpdateRule(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList.RelationshipParentUpdateRule) FileOutputStream(java.io.FileOutputStream) RelationshipChildDeleteRule(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList.RelationshipChildDeleteRule) DrawingObjectRelationshipGroups(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.StoredDisplay.DrawingObjectRelationshipGroups) RelationshipGroups(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.Model.RelationshipGroups) Map(java.util.Map) HashMap(java.util.HashMap) ParentAttribute(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.ParentAttribute) File(java.io.File) RelationshipNoNulls(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList.RelationshipNoNulls) AttributePropsList(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList) PhysicalName(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.PhysicalName) KeyGroupGroups(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.Entity.KeyGroupGroups) Attribute(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.Attribute) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ParentAttribute(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.ParentAttribute) RelationshipChildUpdateRule(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList.RelationshipChildUpdateRule) DrawingObjectEntityGroups(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.StoredDisplay.DrawingObjectEntityGroups) EntityGroups(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.Model.EntityGroups) KeyGroupMemberPropsList(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroupMemberPropsList) KeyGroupType(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroupPropsList.KeyGroupType) DefaultValueGroups(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.Model.DefaultValueGroups) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) DefaultPropsList(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.DefaultPropsList) KeyGroupSortOrder(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroupMemberPropsList.KeyGroupSortOrder) RelationshipParentInsertRule(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList.RelationshipParentInsertRule) KeyGroupPosition(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroupMemberPropsList.KeyGroupPosition) ServerValue(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.DefaultPropsList.ServerValue) KeyGroup(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroup) DBMSVersion(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.DBMSVersion) TargetServer(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.TargetServer) RelationshipParentDeleteRule(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList.RelationshipParentDeleteRule) IOException(java.io.IOException) Default(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.Default) Constraint(com.cubrid.common.core.common.model.Constraint) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) KeyGroupRelationPointer(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroupPropsList.KeyGroupRelationPointer) RelationshipPropsList(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList) ClassType(com.cubrid.cubridmanager.core.utils.ModelUtil.ClassType) ConstraintType(com.cubrid.common.core.common.model.Constraint.ConstraintType) LogicalDataType(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.LogicalDataType) KeyGroupType(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.KeyGroupPropsList.KeyGroupType) Type(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.EntityPropsList.Type) RelationshipParentEntity(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.RelationshipPropsList.RelationshipParentEntity) ParentRelationship(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.ParentRelationship) ParentRelationship(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.AttributePropsList.ParentRelationship) Relationship(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.Relationship) Model(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.Model) ERwin4(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.ERwin4) EntityPropsList(com.cubrid.common.ui.cubrid.database.erwin.xmlmodel.EntityPropsList)

Aggregations

Constraint (com.cubrid.common.core.common.model.Constraint)90 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)47 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)37 ArrayList (java.util.ArrayList)27 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)11 TableItem (org.eclipse.swt.widgets.TableItem)10 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)9 List (java.util.List)9 SchemaChangeLog (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)7 HashMap (java.util.HashMap)6 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)5 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 Node (org.w3c.dom.Node)4 DBResolution (com.cubrid.common.core.common.model.DBResolution)3 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)3 ERSchema (com.cubrid.common.ui.er.model.ERSchema)3 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 NodeList (org.w3c.dom.NodeList)3