Search in sources :

Example 1 with DBResolution

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

the class SchemaDDLTest method testdata.

/**
	 * test data()
	 * 
	 */
@SuppressWarnings("unused")
public void testdata() throws Exception {
    boolean success = createTestTable();
    assertTrue(success);
    SchemaInfo sup1 = databaseInfo.getSchemaInfo("sup1");
    SchemaInfo sup2 = databaseInfo.getSchemaInfo("sup2");
    SchemaInfo test = databaseInfo.getSchemaInfo("test");
    SchemaInfo testSuperTableName = databaseInfo.getSchemaInfo("testSuperTableName");
    SchemaInfo testTableName = databaseInfo.getSchemaInfo("testTableName");
    SchemaChangeManager changeList = new SchemaChangeManager(databaseInfo, true);
    List<SchemaChangeLog> changeListNoAuto = new ArrayList<SchemaChangeLog>();
    //SchemeChangeLog schemeChangeLog= new SchemeChangeLog();
    changeList.addSchemeChangeLog(new SchemaChangeLog("a", null, SchemeInnerType.TYPE_CLASSATTRIBUTE));
    changeList.addSchemeChangeLog(new SchemaChangeLog("a", null, SchemeInnerType.TYPE_ATTRIBUTE));
    changeList.addSchemeChangeLog(new SchemaChangeLog(null, "fk", SchemeInnerType.TYPE_FK));
    changeList.addSchemeChangeLog(new SchemaChangeLog("fk", null, SchemeInnerType.TYPE_FK));
    Constraint index = testTableName.getConstraintByName("index", "UNIQUE");
    changeList.addSchemeChangeLog(new SchemaChangeLog(index.getDefaultName(testTableName.getClassname()) + "$" + //$NON-NLS-1$
    index.getName(), //$NON-NLS-1$
    null, SchemeInnerType.TYPE_INDEX));
    changeList.addSchemeChangeLog(new SchemaChangeLog("a", "a", SchemeInnerType.TYPE_ATTRIBUTE));
    changeList.addSchemeChangeLog(new SchemaChangeLog("a", "a", SchemeInnerType.TYPE_ATTRIBUTE));
    //changeListNoAuto.add(o)
    changeList.setChangeList(changeListNoAuto);
    SchemaDDL ddl = new SchemaDDL(changeList, databaseInfo);
    SchemaChangeManager changeList2 = new SchemaChangeManager(databaseInfo, false);
    SchemaDDL ddl2 = new SchemaDDL(changeList2, databaseInfo);
    List<String[]> columnConflicts = SuperClassUtil.getColumnConflicts(databaseInfo, testTableName, testTableName.getSuperClasses(), true);
    String[][] classConflicts = columnConflicts.toArray(new String[columnConflicts.size()][]);
    columnConflicts = SuperClassUtil.getColumnConflicts(databaseInfo, testTableName, testTableName.getSuperClasses(), false);
    String[][] conflicts = columnConflicts.toArray(new String[columnConflicts.size()][]);
    ddl.getSchemaDDL(sup1);
    ddl.getSchemaDDL(sup2);
    ddl.getSchemaDDL(sup1, sup2);
    ddl.getAlterDDL(sup1, sup2);
    ddl.getSchemaDDL(testTableName);
    ddl.getSchemaDDL(testTableName, testTableName);
    ddl.getAlterDDL(testTableName, testTableName);
    ddl.getSchemaDDL(testTableName, sup1);
    ddl.getSchemaDDL(sup1, testTableName);
    ddl2.getSchemaDDL(sup1);
    ddl2.getSchemaDDL(sup2);
    ddl2.getSchemaDDL(sup1, sup2);
    ddl2.getAlterDDL(sup1, sup2);
    ddl2.getSchemaDDL(testTableName);
    ddl2.getSchemaDDL(testTableName, testTableName);
    ddl2.getAlterDDL(testTableName, testTableName);
    ddl2.getSchemaDDL(testTableName, sup1);
    ddl2.getSchemaDDL(sup1, testTableName);
    String name = "name";
    String className = "className";
    String alias = "alias";
    boolean isClassResolution = true;
    DBResolution oldResolutions = new DBResolution(name, className, alias);
    oldResolutions.setName(name);
    oldResolutions.setClassName(className);
    oldResolutions.setAlias(alias);
    oldResolutions.setClassResolution(isClassResolution);
    DBResolution newResolutions = new DBResolution(name, className, alias);
    newResolutions.setName(name);
    newResolutions.setClassName(className);
    newResolutions.setAlias(alias);
    newResolutions.setClassResolution(isClassResolution);
    List<DBResolution> oldResolution = new ArrayList<DBResolution>();
    oldResolution.add(oldResolutions);
    List<DBResolution> newResolution = new ArrayList<DBResolution>();
    newResolution.add(newResolutions);
    ddl.getResolutionChanges(oldResolution, newResolution);
    List<String> oldSupers = new ArrayList<String>();
    oldSupers.add("oldstring");
    List<String> newSupers = new ArrayList<String>();
    newSupers.add("newstring");
    ddl.getSuperclassChanges(oldSupers, newSupers);
    ddl.getAddSuperClassDDL("tableName", newSupers, oldResolution, newResolution);
    ddl.getDropSuperClassesDDL("tableName", newSupers);
    ddl.getChangeOwnerDDL("tableName", "newOwner");
    String aname = "name";
    String type = "type";
    // it belongs to which class
    String inherit = "inherit";
    boolean indexed = true;
    boolean notNull = true;
    boolean shared = true;
    boolean unique = true;
    String defaultValue = "defaultValue";
    SerialInfo autoIncrement = null;
    String domainClassName = "domainClassName";
    boolean isClassAttribute = true;
    DBAttribute dbAttribute = new DBAttribute(aname, type, inherit, indexed, notNull, shared, unique, defaultValue, "iso88591_bin");
    ddl.getAddColumnDDL("tableName", dbAttribute, newSupers, sup1);
    ddl.setEndLineChar("endLineChar");
    String aclassName = "className";
    String partitionName = "partitionName";
    String partitionClassName = "partitionClassName";
    PartitionType partitionType = PartitionType.HASH;
    String partitionExpr = "partitionExpr";
    final List<String> partitionValues = new ArrayList<String>();
    partitionValues.add("str");
    partitionValues.add("str1");
    final List<String> partitionValues2 = new ArrayList<String>();
    partitionValues.add("str");
    partitionValues.add(null);
    int rows = -1;
    PartitionInfo partitionInfo4 = new PartitionInfo(aclassName, partitionName, partitionClassName, PartitionType.LIST, partitionExpr, partitionValues, rows);
    PartitionInfo partitionInfo6 = new PartitionInfo(aclassName, partitionName, partitionClassName, partitionType, partitionExpr, partitionValues2, rows);
    PartitionInfo partitionInfo7 = new PartitionInfo(aclassName, partitionName, partitionClassName, PartitionType.RANGE, partitionExpr, partitionValues, rows);
    List<PartitionInfo> partInfoList = new ArrayList<PartitionInfo>();
    partInfoList.add(partitionInfo4);
    ddl.getTransformToPartitionDDL(partInfoList);
    List<PartitionInfo> partInfoListRange = new ArrayList<PartitionInfo>();
    partInfoListRange.add(partitionInfo7);
    ddl.getTransformToPartitionDDL(partInfoListRange);
    ddl.getTransformToGenericDDL("tableName");
    ddl.getAddPartitionDDL(partitionInfo4);
    ddl.getDelPartitionDDL("tableName", "partName");
    PartitionInfo partitionInfo5 = new PartitionInfo(aclassName, partitionName, partitionClassName, partitionType, "partitionExpr1", partitionValues, -1);
    List<PartitionInfo> newPartInfoList = new ArrayList<PartitionInfo>();
    newPartInfoList.add(partitionInfo5);
    newPartInfoList.add(partitionInfo7);
    ddl.getCoalescePartitionDDL(partInfoList, newPartInfoList);
    ddl.getCoalescePartitionDDL(newPartInfoList, partInfoList);
    ddl.getCoalescePartitionDDL(newPartInfoList, partInfoListRange);
    ddl.getSplitPartitionDDL(partInfoList, newPartInfoList);
    partInfoList.clear();
    partInfoList.add(partitionInfo6);
    ddl.getSplitPartitionDDL(partInfoList, newPartInfoList);
    ddl.getAlterAutoIncrementDDL("tableName", "columnName");
    partInfoList.clear();
    partitionInfo4 = new PartitionInfo(aclassName, partitionName, partitionClassName, PartitionType.RANGE, partitionExpr, partitionValues, rows);
    partInfoList.add(partitionInfo4);
    ddl.getSplitPartitionDDL(partInfoList, newPartInfoList);
    partInfoList.clear();
    partitionInfo4 = new PartitionInfo(aclassName, partitionName, partitionClassName, PartitionType.LIST, partitionExpr, partitionValues, rows);
    partInfoList.add(partitionInfo4);
    ddl.getSplitPartitionDDL(partInfoList, newPartInfoList);
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ArrayList(java.util.ArrayList) PartitionType(com.cubrid.common.core.common.model.PartitionType) Constraint(com.cubrid.common.core.common.model.Constraint) DBResolution(com.cubrid.common.core.common.model.DBResolution) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) PartitionInfo(com.cubrid.common.core.common.model.PartitionInfo) SerialInfo(com.cubrid.common.core.common.model.SerialInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 2 with DBResolution

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

the class DBResolutionTest method testDBResolution.

/**
	 * Test DBResolution
	 */
public final void testDBResolution() {
    String name = "name";
    String className = "className";
    String alias = "alias";
    boolean isClassResolution = true;
    // test getters and setters
    DBResolution dbResolution = new DBResolution(name, className, alias);
    dbResolution.getAlias();
    dbResolution.setName(name);
    dbResolution.setClassName(className);
    dbResolution.setAlias(alias);
    dbResolution.setClassResolution(isClassResolution);
    assertEquals(dbResolution.getName(), name);
    assertEquals(dbResolution.getClassName(), className);
    assertEquals(dbResolution.getAlias(), alias);
    assertTrue(dbResolution.isClassResolution());
    // test public boolean equals(Object obj)
    assertTrue(dbResolution.equals(dbResolution));
    assertFalse(dbResolution.equals(null));
    assertFalse(dbResolution.equals("other object"));
    // test public int hashCode()
    dbResolution.hashCode();
    // test public SerialInfo clone()
    DBResolution clonedSerialInfo = dbResolution.clone();
    assertEquals(dbResolution, clonedSerialInfo);
    DBResolution resolution = new DBResolution();
    assertEquals("", resolution.getAlias());
}
Also used : DBResolution(com.cubrid.common.core.common.model.DBResolution)

Example 3 with DBResolution

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

the class SuperClassUtil method removeUnusedResolutionForSuper.

/**
	 * remove unused resolution when some super class is removed.
	 * 
	 * @param resolutions List<DBResolution>
	 * @param newSupers List<String>
	 */
private static void removeUnusedResolutionForSuper(List<DBResolution> resolutions, List<String> newSupers) {
    for (int j = 0; j < resolutions.size(); ) {
        DBResolution resolution = resolutions.get(j);
        boolean found = false;
        for (String superClassName : newSupers) {
            if (superClassName.equals(resolution.getClassName())) {
                found = true;
            }
        }
        //if not found in conflicts, so should be removed
        if (found) {
            j++;
        } else {
            resolutions.remove(j);
        }
    }
}
Also used : DBResolution(com.cubrid.common.core.common.model.DBResolution) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 4 with DBResolution

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

the class SuperClassUtil method fireSuperClassChanged.

/**
	 * reset attributes and resolutions when super classes change, eg: <li>when
	 * adding a super class, some naming conflicts maybe occurs, so some
	 * resolution would be added, attributes to the schema should be reset and
	 * ordered
	 * 
	 * @param database DatabaseInfo the given reference of a DatabaseInfo object
	 * @param oldSchemaInfo SchemaInfo the given reference of old SchemaInfo
	 *        object
	 * @param newSchemaInfo SchemaInfo the given reference of new SchemaInfo
	 *        object
	 * @param newSupers List<String>
	 * @return boolean whether is succeed
	 */
public static boolean fireSuperClassChanged(DatabaseInfo database, SchemaInfo oldSchemaInfo, SchemaInfo newSchemaInfo, List<String> newSupers) {
    //checking attribute
    List<DBResolution> newResolutions = getCloneResolutions(newSchemaInfo.getResolutions());
    List<DBAttribute> localAttributes = newSchemaInfo.getLocalAttributes();
    Map<String, List<SchemaInfo>> columnInheritSchemaMap = new HashMap<String, List<SchemaInfo>>();
    boolean success = checkingOnSuperClassChanged(columnInheritSchemaMap, database, oldSchemaInfo, newSchemaInfo, newSupers, localAttributes, newResolutions, false);
    if (!success) {
        return false;
    }
    //checking class attributes
    List<DBResolution> newClassResolutions = getCloneResolutions(newSchemaInfo.getClassResolutions());
    List<DBAttribute> localClassAttributes = newSchemaInfo.getLocalClassAttributes();
    Map<String, List<SchemaInfo>> classColumnInheritSchemaMap = new HashMap<String, List<SchemaInfo>>();
    boolean classSuccess = checkingOnSuperClassChanged(classColumnInheritSchemaMap, database, oldSchemaInfo, newSchemaInfo, newSupers, localClassAttributes, newClassResolutions, true);
    if (!classSuccess) {
        return false;
    }
    if (database == null) {
        return false;
    }
    //reset resolution, super classes and resolution
    List<SchemaInfo> schemalist = new ArrayList<SchemaInfo>();
    for (String sup : newSupers) {
        schemalist.add(database.getSchemaInfo(sup).clone());
    }
    if (success && classSuccess) {
        //remove inherit constraint
        List<SchemaInfo> superList = getSuperClasses(database, newSchemaInfo);
        List<Constraint> constraints = newSchemaInfo.getConstraints();
        for (int j = constraints.size() - 1; j >= 0; j--) {
            Constraint constraint = constraints.get(j);
            String constraintType = constraint.getType();
            String constraintName = constraint.getName();
            boolean isConstraintInheritSupported = isConstraintTypeInherit(constraintType);
            if (isConstraintInheritSupported && newSchemaInfo.isInSuperClasses(superList, constraintName)) {
                constraints.remove(j);
            }
        }
        resetAttribute(newSchemaInfo, schemalist, newResolutions, localAttributes, columnInheritSchemaMap, false);
        newSchemaInfo.setResolutions(newResolutions);
        resetAttribute(newSchemaInfo, schemalist, newClassResolutions, localClassAttributes, classColumnInheritSchemaMap, true);
        newSchemaInfo.setClassResolutions(newClassResolutions);
        newSchemaInfo.setSuperClasses(newSupers);
        //add inherit constraint
        superList = getSuperClasses(database, newSupers);
        for (SchemaInfo schema : superList) {
            constraints = schema.getConstraints();
            for (int i = 0; i < constraints.size(); i++) {
                Constraint constraint = constraints.get(i);
                String constraintType = constraint.getType();
                boolean isConstraintInheritSupported = isConstraintTypeInherit(constraintType);
                if (isConstraintInheritSupported) {
                    newSchemaInfo.addConstraint(constraint);
                }
            }
        }
    }
    return true;
}
Also used : HashMap(java.util.HashMap) Constraint(com.cubrid.common.core.common.model.Constraint) ArrayList(java.util.ArrayList) Constraint(com.cubrid.common.core.common.model.Constraint) DBResolution(com.cubrid.common.core.common.model.DBResolution) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ArrayList(java.util.ArrayList) List(java.util.List) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 5 with DBResolution

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

the class ConstraintComparator method getResolutionsDDL.

/**
	 * Return the DDL of resolution part
	 *
	 * @param classResolutions List<DBResolution> the given list includes the
	 *        DBResolution object, which are class resolutions
	 * @param resolutions List<DBResolution> he given list includes the
	 *        DBResolution object, which are plain resolutions
	 * @return String a string indicates the resolution DDL
	 */
private String getResolutionsDDL(List<DBResolution> classResolutions, List<DBResolution> resolutions) {
    StringBuffer bf = new StringBuffer();
    int count = 0;
    for (DBResolution r : classResolutions) {
        if (count == 0) {
            bf.append(StringUtil.NEWLINE).append("INHERIT ");
        } else {
            bf.append(", ");
        }
        bf.append(getDBResolutionDDL(r, true));
        count++;
    }
    for (DBResolution r : resolutions) {
        if (count == 0) {
            bf.append(StringUtil.NEWLINE).append("INHERIT ");
        } else {
            bf.append(", ");
        }
        bf.append(getDBResolutionDDL(r, false));
        count++;
    }
    return bf.toString();
}
Also used : DBResolution(com.cubrid.common.core.common.model.DBResolution) Constraint(com.cubrid.common.core.common.model.Constraint)

Aggregations

DBResolution (com.cubrid.common.core.common.model.DBResolution)18 Constraint (com.cubrid.common.core.common.model.Constraint)10 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)6 ArrayList (java.util.ArrayList)6 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)5 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)2 PartitionType (com.cubrid.common.core.common.model.PartitionType)2 List (java.util.List)2 DBMethod (com.cubrid.common.core.common.model.DBMethod)1 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)1 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)1 PreparedStatement (java.sql.PreparedStatement)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1