Search in sources :

Example 1 with SchemaChangeLog

use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog 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));
        }
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)

Example 2 with SchemaChangeLog

use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog 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));
        }
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)

Example 3 with SchemaChangeLog

use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog in project cubrid-manager by CUBRID.

the class EditVirtualTableDialog method makeChangeLogForIndex.

public boolean makeChangeLogForIndex(String attrName, DBAttribute editAttr, DBAttribute origAttr) {
    // FIXME move this logic to core module
    List<Constraint> constrainList = newERTable.getSchemaInfo().getConstraints();
    if (constrainList.size() == 0 || StringUtil.isEmpty(attrName)) {
        return false;
    }
    List<Constraint> removedConstrainList = new ArrayList<Constraint>();
    List<Constraint> addedConstrainList = new ArrayList<Constraint>();
    for (Constraint cons : constrainList) {
        if (cons == null) {
            continue;
        }
        if (ConstraintType.INDEX.getText().equals(cons.getType()) || ConstraintType.REVERSEINDEX.getText().equals(cons.getType()) || ConstraintType.UNIQUE.getText().equals(cons.getType()) || ConstraintType.REVERSEUNIQUE.getText().equals(cons.getType())) {
            List<String> attrs = cons.getAttributes();
            if (!(attrs != null && attrs.contains(attrName))) {
                continue;
            }
            removedConstrainList.add(cons);
            Constraint newCons = new Constraint(true);
            newCons.setType(cons.getType());
            newCons.setName(cons.getName());
            cons.replaceAttribute(attrName, editAttr.getName());
            newCons.setAttributes(cons.getAttributes());
            for (String origRule : cons.getRules()) {
                if (cons.getRules().size() == 1) {
                    newCons.addRule(editAttr.getName() + origRule.substring(attrName.length()));
                    break;
                }
                int spaceIndex = origRule.indexOf(" ");
                String attrNameFromRule = origRule.substring(0, spaceIndex);
                if (attrName.equals(attrNameFromRule)) {
                    newCons.addRule(editAttr.getName() + origRule.substring(attrName.length()));
                } else {
                    newCons.addRule(origRule);
                }
            }
            addedConstrainList.add(newCons);
            String key = cons.getDefaultName(newERTable.getSchemaInfo().getClassname()) + "$" + cons.getName();
            SchemaChangeLog changeLog = new SchemaChangeLog(key, key, SchemeInnerType.TYPE_INDEX);
            schemaChangeMgr.addSchemeChangeLog(changeLog);
        }
    }
    if (removedConstrainList.size() == 0) {
        return false;
    }
    constrainList.removeAll(removedConstrainList);
    constrainList.addAll(addedConstrainList);
    indexTableView.setInput(newERTable.getSchemaInfo());
    return true;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ArrayList(java.util.ArrayList) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)

Example 4 with SchemaChangeLog

use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog in project cubrid-manager by CUBRID.

the class TableEditorPart method addDropAttrLog.

/**
	 * Add a log of dropping an attribute to change list.
	 *
	 * @param isClassAttribute boolean
	 * @param oldAttrName String
	 */
private void addDropAttrLog(String oldAttrName, boolean isClassAttribute) {
    SchemaChangeLog changeLog = new SchemaChangeLog(oldAttrName, null, getSchemaInnerType(isClassAttribute));
    schemaChangeMgr.addSchemeChangeLog(changeLog);
}
Also used : SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)

Example 5 with SchemaChangeLog

use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog in project cubrid-manager by CUBRID.

the class TableEditorPart method makeChangeLogForIndex.

public boolean makeChangeLogForIndex(String attrName, DBAttribute editAttr, DBAttribute origAttr) {
    List<Constraint> constrainList = newSchemaInfo.getConstraints();
    if (constrainList.size() == 0) {
        // FIXME move this logic to core module
        return false;
    }
    List<Constraint> removedConstrainList = new ArrayList<Constraint>();
    List<Constraint> addedConstrainList = new ArrayList<Constraint>();
    for (Constraint cons : constrainList) {
        if (cons == null) {
            continue;
        }
        if (ConstraintType.INDEX.getText().equals(cons.getType()) || ConstraintType.REVERSEINDEX.getText().equals(cons.getType()) || ConstraintType.UNIQUE.getText().equals(cons.getType()) || ConstraintType.REVERSEUNIQUE.getText().equals(cons.getType())) {
            List<String> attrs = cons.getAttributes();
            if (!(attrs != null && attrs.contains(attrName))) {
                continue;
            }
            removedConstrainList.add(cons);
            Constraint newCons = new Constraint(true);
            newCons.setType(cons.getType());
            newCons.setName(cons.getName());
            cons.replaceAttribute(attrName, editAttr.getName());
            newCons.setAttributes(cons.getAttributes());
            for (String origRule : cons.getRules()) {
                if (cons.getRules().size() == 1) {
                    newCons.addRule(editAttr.getName() + origRule.substring(attrName.length()));
                    break;
                }
                int spaceIndex = origRule.indexOf(" ");
                String attrNameFromRule = origRule.substring(0, spaceIndex);
                if (attrName.equals(attrNameFromRule)) {
                    newCons.addRule(editAttr.getName() + origRule.substring(attrName.length()));
                } else {
                    newCons.addRule(origRule);
                }
            }
            addedConstrainList.add(newCons);
            String key = cons.getDefaultName(newSchemaInfo.getClassname()) + "$" + cons.getName();
            SchemaChangeLog changeLog = new SchemaChangeLog(key, key, SchemeInnerType.TYPE_INDEX);
            schemaChangeMgr.addSchemeChangeLog(changeLog);
        }
    }
    if (removedConstrainList.size() == 0) {
        return false;
    }
    constrainList.removeAll(removedConstrainList);
    constrainList.addAll(addedConstrainList);
    indexTableView.setInput(newSchemaInfo);
    return true;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ArrayList(java.util.ArrayList) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)

Aggregations

SchemaChangeLog (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)16 Constraint (com.cubrid.common.core.common.model.Constraint)8 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)5 ArrayList (java.util.ArrayList)3 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)2 AddIndexDialog (com.cubrid.common.ui.cubrid.table.dialog.AddIndexDialog)2