Search in sources :

Example 21 with SchemaInfo

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

the class SchemaAlterDDLTest method superAndResolutionTest.

/**
	 * test table inherits table "sup1", then add super class "sup2";
	 * 
	 * @return
	 */
private void superAndResolutionTest() {
    changeList = new SchemaChangeManager(databaseInfo, false);
    ddl = new SchemaDDL(changeList, databaseInfo);
    SchemaInfo newSchema = testedSchemaInfo.clone();
    String alterDDL = null;
    List<String> newSuperclass = new ArrayList<String>();
    //add sup2 and sup3
    newSuperclass.add("sup1");
    newSuperclass.add("sup2");
    newSuperclass.add("sup3");
    boolean success = SuperClassUtil.fireSuperClassChanged(databaseInfo, testedSchemaInfo, newSchema, newSuperclass);
    assertTrue(success);
    newSchema.setSuperClasses(newSuperclass);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("ALTER TABLE testschemaalterddl ADD SUPERCLASS sup2,sup3") > -1);
    assertTrue(alterDDL.indexOf("INHERIT CLASS [float] OF sup1") > -1);
    assertTrue(alterDDL.indexOf("[bigint] OF sup1") > -1);
    assertTrue(alterDDL.indexOf("[float] OF sup1") > -1);
    assertTrue(alterDDL.indexOf("numeric1 OF sup1") > -1);
    assertTrue(alterDDL.indexOf("numeric2 OF sup1") > -1);
    String type = "";
    String superTable = "";
    String column = "";
    String alias = "";
    boolean isClassType = false;
    //add "numeric1" OF "sup2", expected "numeric1" OF "sup1" dropped
    column = "numeric1";
    superTable = "sup2";
    alias = "";
    isClassType = false;
    addResolution(newSchema, column, superTable, alias, isClassType);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("numeric1 OF sup2") > -1);
    assertTrue(alterDDL.indexOf("numeric1 OF sup1") == -1);
    //add alias "numeric1" OF "sup3", 
    //expected "numeric1" OF "sup2" exist, and alias resolution exist too
    column = "numeric1";
    superTable = "sup3";
    alias = "numeric1sup3";
    isClassType = false;
    addResolution(newSchema, column, superTable, alias, isClassType);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("numeric1 OF sup2") > -1);
    assertTrue(alterDDL.indexOf("numeric1 OF sup3 AS numeric1sup3") > -1);
    //drop "numeric1" OF "sup2", expected "numeric1" OF "sup1"
    type = "";
    superTable = "sup2";
    column = "numeric1";
    removeResolution(newSchema, type, superTable, column);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("numeric1 OF sup1") > -1);
    //drop "numeric1" OF "sup1", expected "numeric1" OF "sup2"
    type = "";
    superTable = "sup1";
    column = "numeric1";
    removeResolution(newSchema, type, superTable, column);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("numeric1 OF sup2") > -1);
    //add alias "numeric1" OF "sup2", 
    //expected "numeric1" OF "sup1" exist, and alias resolution of(sup2,sup3) exist too
    column = "numeric1";
    superTable = "sup2";
    alias = "numeric1sup2";
    isClassType = false;
    addResolution(newSchema, column, superTable, alias, isClassType);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("numeric1 OF sup1") > -1);
    assertTrue(alterDDL.indexOf("numeric1 OF sup2 AS numeric1sup2") > -1);
    assertTrue(alterDDL.indexOf("numeric1 OF sup3 AS numeric1sup3") > -1);
    //drop "bigint" OF "sup1", expected "bigint" OF "sup2"
    type = "";
    superTable = "sup1";
    column = "bigint";
    removeResolution(newSchema, type, superTable, column);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("[bigint] OF sup2") > -1);
    //drop "bigint" OF "sup2", expected "bigint" OF "sup3"
    type = "";
    superTable = "sup2";
    column = "bigint";
    removeResolution(newSchema, type, superTable, column);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("[bigint] OF sup3") > -1);
    //drop "bigint" OF "sup3", expected "bigint" OF "sup1"
    type = "";
    superTable = "sup3";
    column = "bigint";
    removeResolution(newSchema, type, superTable, column);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("[bigint] OF sup1") > -1);
    //drop Class "float" OF "sup1", expected Class "float" OF "sup2"
    type = "Class";
    superTable = "sup1";
    column = "float";
    removeResolution(newSchema, type, superTable, column);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("CLASS [float] OF sup2") > -1);
    //drop Class "float" OF "sup2", expected Class "float" OF "sup3"
    type = "Class";
    superTable = "sup2";
    column = "float";
    removeResolution(newSchema, type, superTable, column);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("CLASS [float] OF sup3") > -1);
    //drop Class "float" OF "sup3", expected Class "float" OF "sup1"
    type = "Class";
    superTable = "sup3";
    column = "float";
    removeResolution(newSchema, type, superTable, column);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("CLASS [float] OF sup1") > -1);
    //drop sup1
    newSuperclass.clear();
    success = SuperClassUtil.fireSuperClassChanged(databaseInfo, testedSchemaInfo, newSchema, newSuperclass);
    assertTrue(success);
    newSchema.setSuperClasses(newSuperclass);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    assertTrue(alterDDL.indexOf("ALTER TABLE testschemaalterddl DROP SUPERCLASS sup1;") > -1);
}
Also used : ArrayList(java.util.ArrayList) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 22 with SchemaInfo

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

the class SchemaAlterDDLTest method pkTest.

private void pkTest() {
    changeList = new SchemaChangeManager(databaseInfo, false);
    ddl = new SchemaDDL(changeList, databaseInfo);
    SchemaInfo newSchema = sup3.clone();
    Constraint newPK = new Constraint(false);
    newPK.setType(Constraint.ConstraintType.PRIMARYKEY.getText());
    newPK.addAttribute("smallint");
    newPK.addAttribute("integer");
    String op = "ADD";
    resetPK(newSchema, null, newPK, op);
    String alterDDL = ddl.getAlterDDL(sup3, newSchema);
    String expected = "ALTER TABLE sup3 ADD PRIMARY KEY([smallint],[integer]);";
    //		assertEquals(expected, alterDDL.trim());
    assertTrue(alterDDL.trim().indexOf(expected) > -1);
    /*	ALTER TABLE sup3 CHANGE COLUMN [smallint] [smallint] smallint AUTO_INCREMENT(1,1) NOT NULL;
ALTER TABLE sup3 CHANGE COLUMN [integer] [integer] integer AUTO_INCREMENT(2,1) NOT NULL;
ALTER TABLE sup3 ADD PRIMARY KEY([smallint],[integer]);
*/
    changeList = new SchemaChangeManager(databaseInfo, false);
    ddl = new SchemaDDL(changeList, databaseInfo);
    newSchema = testedSchemaInfo.clone();
    String testColumn = "pkattr";
    boolean isClassAttribute = false;
    DBAttribute attr = new DBAttribute();
    attr.setName(testColumn);
    attr.setType("smallint");
    attr.setInherit(newSchema.getClassname());
    addColumn(newSchema, isClassAttribute, attr);
    Constraint oldPK = newSchema.getPK(superList);
    newPK = oldPK.clone();
    newPK.addAttribute(testColumn);
    op = "MODIFY";
    resetPK(newSchema, oldPK, newPK, op);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    expected = "ALTER TABLE " + testTableName.toLowerCase() + " DROP CONSTRAINT pk_testschemaalterddl_name_gender;" + StringUtil.NEWLINE;
    expected += "ALTER TABLE " + testTableName.toLowerCase() + " ADD COLUMN pkattr smallint NOT NULL AFTER [shared];" + StringUtil.NEWLINE;
    expected += "ALTER TABLE " + testTableName.toLowerCase() + " ADD CONSTRAINT pk_testschemaalterddl_name_gender PRIMARY KEY ([name],gender,pkattr);";
    assertEquals(expected, alterDDL.trim());
    //drop pk
    oldPK = newPK;
    newPK = null;
    op = "DEL";
    resetPK(newSchema, oldPK, newPK, op);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    expected = "ALTER TABLE " + testTableName.toLowerCase() + " DROP CONSTRAINT pk_testschemaalterddl_name_gender;" + StringUtil.NEWLINE;
    assertTrue(alterDDL.trim().indexOf(expected) > -1);
    expected = "ALTER TABLE " + testTableName.toLowerCase() + " ADD COLUMN pkattr smallint AFTER [shared];";
    //assertEquals(expected, alterDDL.trim());
    assertTrue(alterDDL.trim().indexOf(expected) > -1);
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 23 with SchemaInfo

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

the class SchemaChangeManagerTest method testGetDDL.

/**
	 * test getting ddl
	 */
public void testGetDDL() {
    SchemaInfo schema1 = new SchemaInfo();
    schema1.setClassname(tableName);
    schema1.setOwner(owner);
    schema1.setVirtual(virtual);
    schema1.setType(type);
    DBAttribute a = new DBAttribute();
    a.setName(attributeName);
    a.setType(dataType);
    a.setInherit(inherit);
    a.setNotNull(isNotNull);
    a.setShared(false);
    a.setUnique(unique);
    a.setDefault(defaultv);
    schema1.addAttribute(a);
    schema1.addClassAttribute(a);
    Constraint pk = new Constraint(false);
    pk.setName(pkName);
    pk.setType(pkType);
    pk.addAttribute(attributes[0]);
    pk.addAttribute(attributes[1]);
    pk.addAttribute(attributes[2]);
    schema1.addConstraint(pk);
    schemaChangeManager.getChangeList();
    schemaChangeManager.isNewAdded(SchemeInnerType.TYPE_ATTRIBUTE, "value");
    schemaChangeManager.isNewAdded("attrName", true);
    schemaChangeManager.isNewAdded("attrName", false);
    schemaChangeManager.getIndexChangeLogs();
    schemaChangeManager.getFKChangeLogs();
    schemaChangeManager.getAttrChangeLogs();
    schemaChangeManager.getClassAttrChangeLogs();
    schemaChangeManager.getChangeLogs(SchemeInnerType.TYPE_ATTRIBUTE);
    schemaChangeManager.setNewTableFlag(true);
    schemaChangeManager.isNewTableFlag();
    schemaChangeManager.setDatabaseInfo(database);
    schemaChangeManager.getDatabaseInfo();
    String oldValue = "oldValue";
    String newValue = "newValue";
    SchemeInnerType stype = SchemeInnerType.TYPE_ATTRIBUTE;
    SchemaChangeLog schemeChangeLog = new SchemaChangeLog(oldValue, newValue, stype);
    changeList = new ArrayList<SchemaChangeLog>();
    changeList.add(schemeChangeLog);
    schemaChangeManager.setChangeList(changeList);
    schemaChangeManager.getChangeLogs(SchemeInnerType.TYPE_ATTRIBUTE);
    schemaChangeManager.addSchemeChangeLog(schemeChangeLog);
    schemaChangeManager.setNewTableFlag(false);
    schemaChangeManager.addSchemeChangeLog(schemeChangeLog);
    schemaChangeManager.isNewAdded(SchemeInnerType.TYPE_ATTRIBUTE, "value");
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemeInnerType(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog.SchemeInnerType) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 24 with SchemaInfo

use of com.cubrid.common.core.common.model.SchemaInfo 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 25 with SchemaInfo

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

the class GetSchemaTaskTest method innerTestGetSchemaTask.

public void innerTestGetSchemaTask() {
    try {
        if (!createTestTable()) {
            dropTestTable();
            //test again
            if (!createTestTable()) {
                fail();
            }
        }
    } catch (Exception e) {
        fail();
    }
    testTableName = testTableName.toLowerCase();
    GetSchemaTask task = new GetSchemaTask(databaseInfo, testTableName);
    task.execute();
    SchemaInfo jSchema = task.getSchema();
    DBAttribute attr = null;
    SerialInfo auto = null;
    //"smallint" smallint AUTO_INCREMENT PRIMARY KEY UNIQUE,
    attr = jSchema.getAttributes().get(0);
    assertFalse(attr.isClassAttribute());
    assertEquals("smallint", attr.getName());
    assertEquals("smallint", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNotNull(auto);
    assertEquals("1", auto.getMinValue());
    assertEquals("1", auto.getIncrementValue());
    //"smallint2" smallint,
    attr = jSchema.getAttributes().get(1);
    assertFalse(attr.isClassAttribute());
    assertEquals("smallint2", attr.getName());
    assertEquals("smallint", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"integer" integer AUTO_INCREMENT(2,1),
    attr = jSchema.getAttributes().get(2);
    assertFalse(attr.isClassAttribute());
    assertEquals("integer", attr.getName());
    assertEquals("integer", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNotNull(auto);
    assertEquals("2", auto.getMinValue());
    assertEquals("1", auto.getIncrementValue());
    //"bigint" bigint,
    attr = jSchema.getAttributes().get(3);
    assertFalse(attr.isClassAttribute());
    assertEquals("bigint", attr.getName());
    assertEquals("bigint", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"numeric1" numeric(15,0) AUTO_INCREMENT UNIQUE,
    attr = jSchema.getAttributes().get(4);
    assertFalse(attr.isClassAttribute());
    assertEquals("numeric1", attr.getName());
    assertEquals("numeric(15,0)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNotNull(auto);
    assertEquals("1", auto.getMinValue());
    assertEquals("1", auto.getIncrementValue());
    //"numeric2" numeric(17,2) DEFAULT 12.50,
    attr = jSchema.getAttributes().get(5);
    assertFalse(attr.isClassAttribute());
    assertEquals("numeric2", attr.getName());
    assertEquals("numeric(17,2)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertEquals("12.50", attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"float" float DEFAULT 12 NOT NULL,
    attr = jSchema.getAttributes().get(6);
    assertFalse(attr.isClassAttribute());
    assertEquals("float", attr.getName());
    assertEquals("float", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertEquals("12", attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"date" date DEFAULT DATE'12/12/2009',
    attr = jSchema.getAttributes().get(7);
    assertFalse(attr.isClassAttribute());
    assertEquals("date", attr.getName());
    assertEquals("date", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertEquals("2009/12/12", attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"datetime" datetime DEFAULT DATETIME'2009-12-12 12:12:12.333',
    attr = jSchema.getAttributes().get(8);
    assertFalse(attr.isClassAttribute());
    assertEquals("datetime", attr.getName());
    assertEquals("datetime", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertEquals("2009-12-12 12:12:12.333", attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"timestamp" timestamp DEFAULT TIMESTAMP'12/01/2009 03:07:51',
    attr = jSchema.getAttributes().get(9);
    assertFalse(attr.isClassAttribute());
    assertEquals("timestamp", attr.getName());
    assertEquals("timestamp", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertEquals("2009-12-01 03:07:51", attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"time" time DEFAULT TIME'00:00:12',
    attr = jSchema.getAttributes().get(10);
    assertFalse(attr.isClassAttribute());
    assertEquals("time", attr.getName());
    assertEquals("time", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    //assertEquals("AM 12:00:12", attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"char" character(10) DEFAULT 'aa        ',
    attr = jSchema.getAttributes().get(11);
    assertFalse(attr.isClassAttribute());
    assertEquals("char", attr.getName());
    assertEquals("character(10)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertEquals("'aa        '", attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"varchar" character varying(10) DEFAULT '77',
    attr = jSchema.getAttributes().get(12);
    assertFalse(attr.isClassAttribute());
    assertEquals("varchar", attr.getName());
    assertEquals("character varying(10)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertEquals("'77'", attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"setint" set_of(smallint) DEFAULT {1, 2},
    attr = jSchema.getAttributes().get(13);
    assertFalse(attr.isClassAttribute());
    assertEquals("setint", attr.getName());
    assertEquals("set_of(smallint)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertEquals("{1, 2}", attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"multisetchar" multiset_of(character varying(10)) DEFAULT {'12', '13'},
    attr = jSchema.getAttributes().get(14);
    assertFalse(attr.isClassAttribute());
    assertEquals("multisetchar", attr.getName());
    assertEquals("multiset_of(character varying(10))", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertEquals("{'12', '13'}", attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"shared" character varying(1073741823) SHARED 'sharedvalue'
    attr = jSchema.getAttributes().get(15);
    assertFalse(attr.isClassAttribute());
    assertEquals("shared", attr.getName());
    assertEquals("character varying(1073741823)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertTrue(attr.isShared());
    assertEquals("'sharedvalue'", attr.getSharedValue());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"bit" bit(1),
    attr = jSchema.getAttributes().get(16);
    assertFalse(attr.isClassAttribute());
    assertEquals("bit", attr.getName());
    assertEquals("bit(1)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"bitv" bit varying(100),
    attr = jSchema.getAttributes().get(17);
    assertFalse(attr.isClassAttribute());
    assertEquals("bitv", attr.getName());
    assertEquals("bit varying(100)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"nchar" national character(1),
    attr = jSchema.getAttributes().get(18);
    assertFalse(attr.isClassAttribute());
    assertEquals("nchar", attr.getName());
    assertEquals("national character(1)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //"varnchar" national character varying(100)
    attr = jSchema.getAttributes().get(19);
    assertFalse(attr.isClassAttribute());
    assertEquals("varnchar", attr.getName());
    assertEquals("national character varying(100)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //		"sequence_numeric" sequence_of(numeric(15,1)),
    attr = jSchema.getAttributes().get(20);
    assertFalse(attr.isClassAttribute());
    assertEquals("sequence_numeric", attr.getName());
    assertEquals("sequence_of(numeric(15,1))", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //		"set_bigint" set_of(bigint),		
    attr = jSchema.getAttributes().get(21);
    assertFalse(attr.isClassAttribute());
    assertEquals("set_bigint", attr.getName());
    assertEquals("set_of(bigint)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //		"multiset_float" multiset_of(float),	
    attr = jSchema.getAttributes().get(22);
    assertFalse(attr.isClassAttribute());
    assertEquals("multiset_float", attr.getName());
    assertEquals("multiset_of(float)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //		"sequence_nchar" sequence_of(national character(2)),
    attr = jSchema.getAttributes().get(23);
    assertFalse(attr.isClassAttribute());
    assertEquals("sequence_nchar", attr.getName());
    assertEquals("sequence_of(national character(2))", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //		"set_vnchar" set_of(national character varying(100)),
    attr = jSchema.getAttributes().get(24);
    assertFalse(attr.isClassAttribute());
    assertEquals("set_vnchar", attr.getName());
    assertEquals("set_of(national character varying(100))", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //		"set_time" set_of(time),		
    attr = jSchema.getAttributes().get(25);
    assertFalse(attr.isClassAttribute());
    assertEquals("set_time", attr.getName());
    assertEquals("set_of(time)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //		"multiset_date" multiset_of(date),		
    attr = jSchema.getAttributes().get(26);
    assertFalse(attr.isClassAttribute());
    assertEquals("multiset_date", attr.getName());
    assertEquals("multiset_of(date)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //		"sequence_datetime" sequence_of(datetime),
    attr = jSchema.getAttributes().get(27);
    assertFalse(attr.isClassAttribute());
    assertEquals("sequence_datetime", attr.getName());
    assertEquals("sequence_of(datetime)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //		"set_timestamp" set_of(timestamp),		
    attr = jSchema.getAttributes().get(28);
    assertFalse(attr.isClassAttribute());
    assertEquals("set_timestamp", attr.getName());
    assertEquals("set_of(timestamp)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //		"multiset_monetary" multiset_of(monetary),
    attr = jSchema.getAttributes().get(29);
    assertFalse(attr.isClassAttribute());
    assertEquals("multiset_monetary", attr.getName());
    assertEquals("multiset_of(monetary)", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //		"sequence_bit" sequence_of(bit(2)),
    attr = jSchema.getAttributes().get(30);
    assertFalse(attr.isClassAttribute());
    assertEquals("sequence_bit", attr.getName());
    assertEquals("sequence_of(bit(2))", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    //		"set_varbit" set_of(bit varying(120))
    attr = jSchema.getAttributes().get(31);
    assertFalse(attr.isClassAttribute());
    assertEquals("set_varbit", attr.getName());
    assertEquals("set_of(bit varying(120))", attr.getType());
    assertEquals(testTableName, attr.getInherit());
    assertNull(attr.getDefault());
    auto = attr.getAutoIncrement();
    assertNull(auto);
    List<String> ruleList = new ArrayList<String>();
    List<String> attrList = new ArrayList<String>();
    String constraintName = null;
    Constraint constraint = null;
    //CREATE  UNIQUE INDEX ON "testgetrecordcounttask"("numeric2" DESC,"float" ASC,"date" DESC);
    attrList.clear();
    ruleList.clear();
    attrList.add("numeric2");
    attrList.add("float");
    attrList.add("date");
    ruleList.add("numeric2 DESC");
    ruleList.add("float ASC");
    ruleList.add("date DESC");
    constraintName = ConstraintNamingUtil.getUniqueName(testTableName, ruleList);
    constraint = jSchema.getConstraintByName(constraintName);
    assertNotNull(constraint);
    assertEquals(attrList, constraint.getAttributes());
    assertEquals(ruleList, constraint.getRules());
    //CREATE  REVERSE UNIQUE INDEX ON "testgetrecordcounttask"("integer" DESC,"bigint" ASC);
    attrList.clear();
    ruleList.clear();
    attrList.add("integer");
    attrList.add("bigint");
    ruleList.add("integer DESC");
    ruleList.add("bigint ASC");
    constraintName = ConstraintNamingUtil.getReverseUniqueName(testTableName, attrList);
    constraint = jSchema.getConstraintByName(constraintName);
    assertNotNull(constraint);
    assertEquals(attrList, constraint.getAttributes());
    assertNotSame(ruleList, constraint.getRules());
    assertEquals("integer DESC", constraint.getRules().get(0));
    assertEquals("bigint DESC", constraint.getRules().get(1));
    //CREATE  INDEX ON "testgetrecordcounttask"("smallint" DESC,"smallint2" DESC);
    attrList.clear();
    ruleList.clear();
    attrList.add("smallint");
    attrList.add("smallint2");
    ruleList.add("smallint DESC");
    ruleList.add("smallint2 DESC");
    constraintName = ConstraintNamingUtil.getIndexName(testTableName, ruleList);
    constraint = jSchema.getConstraintByName(constraintName);
    assertNotNull(constraint);
    assertEquals(attrList, constraint.getAttributes());
    assertEquals(ruleList, constraint.getRules());
    //CREATE  REVERSE INDEX ON "testgetrecordcounttask"("numeric1" ASC,"numeric2" DESC);
    attrList.clear();
    ruleList.clear();
    attrList.add("numeric1");
    attrList.add("numeric2");
    ruleList.add("numeric1 ASC");
    ruleList.add("numeric2 DESC");
    constraintName = ConstraintNamingUtil.getReverseIndexName(testTableName, attrList);
    constraint = jSchema.getConstraintByName(constraintName);
    assertNotNull(constraint);
    assertEquals(attrList, constraint.getAttributes());
    assertEquals("numeric1 DESC", constraint.getRules().get(0));
    assertEquals("numeric2 DESC", constraint.getRules().get(1));
    task.setErrorMsg("errorMsg");
    task.execute();
    task.setErrorMsg(null);
    task.execute();
    task.cancel();
    task.execute();
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ArrayList(java.util.ArrayList) SerialInfo(com.cubrid.common.core.common.model.SerialInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)136 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)57 Constraint (com.cubrid.common.core.common.model.Constraint)56 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)15 List (java.util.List)15 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)10 Connection (java.sql.Connection)10 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)9 SQLException (java.sql.SQLException)9 TableItem (org.eclipse.swt.widgets.TableItem)9 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)8 SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)8 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)7 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 DBResolution (com.cubrid.common.core.common.model.DBResolution)6 Map (java.util.Map)5