use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.
the class ERAttributeCellModifier method canModify.
public boolean canModify(Object element, String property) {
// FIXME move this logic to core module
ERTableColumn erColumn = (ERTableColumn) element;
DBAttribute attr = erColumn.getAttr();
if (!editor.isNewTableFlag() && !editor.isSupportChange() && editor.getOldSchemaInfo().getDBAttributeByName(attr.getName(), false) != null) {
return false;
}
if (StringUtil.isEqual(property, IAttributeColumn.COL_AUTO_INCREMENT)) {
DBAttribute aiAttr = editor.getNewSchemaInfo().getAutoIncrementColumn();
if (aiAttr != null && aiAttr != attr) {
return false;
} else if (!DataType.isIntegerType(attr.getType())) {
return false;
} else if (attr != null && StringUtil.isNotEmpty(attr.getDefault())) {
CommonUITool.openErrorBox(Messages.errCanNotSetAIOnDefault);
return false;
}
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_NOT_NULL) || StringUtil.isEqual(property, IAttributeColumn.COL_UK)) {
Constraint pk = editor.getNewSchemaInfo().getPK();
if (pk != null && pk.getAttributes().contains(attr.getName())) {
return false;
}
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_COLLATION)) {
if (attr.isNew() && DataType.canUseCollation(attr.getType())) {
return true;
} else {
return false;
}
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_MEMO)) {
return editor.isSupportTableComment();
}
return true;
}
use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.
the class SchemaAlterDDLTest method addColumn.
/**
* add a column
*
* @param newSchema
* @param newAttrName
* @param isClassAttribute
* @param addAttribute
*/
private void addColumn(SchemaInfo newSchema, boolean isClassAttribute, DBAttribute addAttribute) {
String newAttrName = addAttribute.getName();
String tableName = newSchema.getClassname();
if (addAttribute != null) {
addAttribute.setInherit(tableName);
} else {
return;
}
newSchema.removeDBAttributeByName(newAttrName, isClassAttribute);
newSchema.addDBAttribute(addAttribute, isClassAttribute);
if (addAttribute.isUnique()) {
Constraint unique = new Constraint(false);
unique.setType(Constraint.ConstraintType.UNIQUE.getText());
unique.addAttribute(newAttrName);
unique.addRule(newAttrName + " ASC");
unique.setName(ConstraintNamingUtil.getUniqueName(tableName, unique.getRules()));
newSchema.addConstraint(unique);
}
if (!isClassAttribute) {
changeList.addSchemeChangeLog(new SchemaChangeLog(null, newAttrName, SchemeInnerType.TYPE_ATTRIBUTE));
} else {
changeList.addSchemeChangeLog(new SchemaChangeLog(null, newAttrName, SchemeInnerType.TYPE_CLASSATTRIBUTE));
}
}
use of com.cubrid.common.core.common.model.Constraint 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);
}
use of com.cubrid.common.core.common.model.Constraint 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");
}
use of com.cubrid.common.core.common.model.Constraint 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);
}
Aggregations