Search in sources :

Example 6 with SchemaChangeLog

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

the class TableEditorPart method getNotNullChangedColumn.

/**
	 * Get all not null changed column
	 *
	 * @return
	 */
private List<String[]> getNotNullChangedColumn() {
    // FIXME move this logic to core module
    List<String[]> notNullChangedColumn = new ArrayList<String[]>();
    List<SchemaChangeLog> allAttrChanges = schemaChangeMgr.getAttrChangeLogs();
    List<SchemaInfo> oldSupers = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), oldSchemaInfo);
    if (oldSupers == null) {
        return notNullChangedColumn;
    }
    List<SchemaInfo> newSupers = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), newSchemaInfo);
    if (newSupers == null) {
        return notNullChangedColumn;
    }
    for (SchemaChangeLog changeLog : allAttrChanges) {
        if (changeLog.getOldValue() == null || changeLog.getNewValue() == null) {
            continue;
        }
        boolean isClassAttr = changeLog.getType() == SchemeInnerType.TYPE_CLASSATTRIBUTE;
        DBAttribute oldAttr = oldSchemaInfo.getDBAttributeByName(changeLog.getOldValue(), isClassAttr);
        DBAttribute newAttr = newSchemaInfo.getDBAttributeByName(changeLog.getNewValue(), isClassAttr);
        if (oldAttr == null || newAttr == null) {
            continue;
        }
        boolean oldNotNull = oldAttr.isNotNull();
        boolean newNotNull = newAttr.isNotNull();
        Constraint newPK = newSchemaInfo.getPK(newSupers);
        List<String> pkAttributes = newPK == null ? new ArrayList<String>() : newPK.getAttributes();
        if (oldNotNull == newNotNull) {
            continue;
        }
        boolean isChangedByPK = false;
        if (newNotNull) {
            // add a new PK
            if (pkAttributes.contains(newAttr.getName())) {
                isChangedByPK = true;
            }
        } else {
            // drop an old PK
            Constraint oldPK = oldSchemaInfo.getPK(oldSupers);
            if (oldPK != null) {
                List<String> oldPKAttrs = oldPK.getAttributes();
                if (oldPKAttrs != null && oldPKAttrs.contains(newAttr.getName())) {
                    isChangedByPK = true;
                }
            }
        }
        if (!isChangedByPK) {
            String[] newColumn = new String[] { newAttr.getName(), String.valueOf(newNotNull) };
            notNullChangedColumn.add(newColumn);
        }
    }
    return notNullChangedColumn;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ArrayList(java.util.ArrayList) SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 7 with SchemaChangeLog

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

the class TableEditorPart method addDelUniqueLog.

/**
	 * Add a log of delete an unique key.
	 *
	 * @param unique
	 */
private void addDelUniqueLog(Constraint unique) {
    if (unique == null) {
        return;
    }
    String key = newSchemaInfo.getClassname() + "$" + unique.getName();
    SchemaChangeLog changeLog = new SchemaChangeLog(key, null, SchemeInnerType.TYPE_INDEX);
    schemaChangeMgr.addSchemeChangeLog(changeLog);
}
Also used : SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)

Example 8 with SchemaChangeLog

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

the class TableSchemaCompareUpdateDDL method setFKAlterDDL.

/**
	 * Compare table FK constraints
	 */
public void setFKAlterDDL() {
    // FIXME logic code move to core module
    List<Constraint> sourceFKConstraints = sourceTableSchema.getFKConstraints();
    List<Constraint> targetFKConstraints = targetTableSchema.getFKConstraints();
    for (Constraint targetFk : targetFKConstraints) {
        String targetFkName = targetFk.getName();
        Constraint sourceFk = findConstraint(sourceTableSchema, targetFkName);
        if (sourceFk != null) {
            if (!targetFk.equals(sourceFk)) {
                changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceFk.getName(), targetFk.getName(), SchemeInnerType.TYPE_FK));
            }
        } else {
            changeManager.addSchemeChangeLog(new SchemaChangeLog(null, targetFk.getName(), SchemeInnerType.TYPE_FK));
        }
    }
    for (Constraint sourceFk : sourceFKConstraints) {
        String sourceFkName = sourceFk.getName();
        Constraint targetFk = findConstraint(targetTableSchema, sourceFkName);
        if (targetFk == null) {
            changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceFk.getName(), null, SchemeInnerType.TYPE_FK));
        }
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)

Example 9 with SchemaChangeLog

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

the class TableSchemaCompareUpdateDDL method setIndexAlterDDL.

/**
	 * Compare table index constraints
	 */
public void setIndexAlterDDL() {
    // FIXME logic code move to core module
    List<Constraint> sourceDBConstraints = sourceTableSchema.getConstraints();
    List<Constraint> targetDBConstraints = targetTableSchema.getConstraints();
    for (Constraint targetCons : targetDBConstraints) {
        String targetConsName = targetCons.getName().toLowerCase();
        Constraint sourceCons = findConstraint(sourceTableSchema, targetConsName);
        if (targetCons.getType().equals(Constraint.ConstraintType.INDEX.getText()) || targetCons.getType().equals(Constraint.ConstraintType.UNIQUE.getText())) {
            if (sourceCons != null) {
                if (!targetCons.equals(sourceCons)) {
                    changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceCons.getDefaultName(sourceTableSchema.getClassname()) + "$" + sourceCons.getName(), targetCons.getDefaultName(targetTableSchema.getClassname()) + "$" + targetCons.getName(), SchemeInnerType.TYPE_INDEX));
                }
            } else {
                changeManager.addSchemeChangeLog(new SchemaChangeLog(null, targetCons.getDefaultName(targetTableSchema.getClassname()) + "$" + targetCons.getName(), SchemeInnerType.TYPE_INDEX));
            }
        }
    }
    for (Constraint sourceCons : sourceDBConstraints) {
        String sourceConsName = sourceCons.getName();
        Constraint t_cons = findConstraint(targetTableSchema, sourceConsName);
        if (t_cons == null && (sourceCons.getType().equals(Constraint.ConstraintType.INDEX.getText()) || sourceCons.getType().equals(Constraint.ConstraintType.UNIQUE.getText()))) {
            changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceCons.getDefaultName(sourceTableSchema.getClassname()) + "$" + sourceCons.getName(), null, SchemeInnerType.TYPE_INDEX));
        }
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)

Example 10 with SchemaChangeLog

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

the class TableSchemaCompareUpdateDDL method setClassNameAlterDDL.

/**
	 * Compare table class name
	 */
public void setClassNameAlterDDL() {
    // FIXME logic code move to core module
    String sourceClassName = sourceTableSchema.getClassname();
    String targetClassName = targetTableSchema.getClassname();
    if (!sourceClassName.toLowerCase().equals(targetClassName.toLowerCase())) {
        changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceClassName, targetClassName, SchemeInnerType.TYPE_SCHEMA));
    }
}
Also used : 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