use of com.cubrid.common.core.common.model.PartitionInfo in project cubrid-manager by CUBRID.
the class TableEditorPart method loadPartitionInfoList.
/**
* Load partition information list
*/
private void loadPartitionInfoList() {
boolean isPartitionTable = false;
if (!isNewTableFlag) {
isPartitionTable = "YES".equals(oldSchemaInfo.isPartitionGroup());
}
if (isPartitionTable) {
GetPartitionedClassListTask task = new GetPartitionedClassListTask(database.getDatabaseInfo());
List<PartitionInfo> list = task.getPartitionItemList(newSchemaInfo.getClassname());
partitionInfoList.clear();
if (!ArrayUtil.isEmpty(list)) {
PartitionInfo partitionInfo = list.get(0);
if (partitionInfo != null && partitionInfo.getPartitionType() == PartitionType.RANGE) {
RangePartitionComparator comparator = new RangePartitionComparator(partitionInfo.getPartitionExprType());
Collections.sort(list, comparator);
}
partitionInfoList.addAll(list);
}
}
oldPartitionInfoList = new ArrayList<PartitionInfo>();
for (int i = 0; i < partitionInfoList.size(); i++) {
PartitionInfo partitionInfo = partitionInfoList.get(i);
if (partitionInfo != null) {
oldPartitionInfoList.add(partitionInfo.clone());
}
}
if (oldSchemaInfo != null) {
oldSchemaInfo.setPartitionList(oldPartitionInfoList);
}
if (newSchemaInfo != null) {
newSchemaInfo.setPartitionList(partitionInfoList);
}
}
use of com.cubrid.common.core.common.model.PartitionInfo in project cubrid-manager by CUBRID.
the class TableEditorPart method deleteColumn.
private void deleteColumn() {
if (!CommonUITool.openConfirmBox(Messages.msgDeleteColumnConfirm)) {
return;
}
TableItem[] tblItems = columnsTable.getSelection();
if (tblItems.length > 0) {
DBAttribute attr = (DBAttribute) tblItems[0].getData();
List<DBAttribute> items = newSchemaInfo.getAttributes();
if (!items.contains(attr)) {
return;
}
}
TableItem[] selection = columnsTable.getSelection();
int selectionIndex = columnsTable.getSelectionIndex();
if (selection != null && selection.length >= 1) {
List<String> attrNames = new ArrayList<String>();
for (int m = 0; m < selection.length; m++) {
attrNames.add(m, selection[m].getText(1));
}
List<SchemaInfo> allSupers = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), newSchemaInfo);
Constraint pk = newSchemaInfo.getPK(allSupers);
List<String> pkAttributes = pk == null ? new ArrayList<String>() : pk.getAttributes();
boolean hasPk = false;
for (String pkAttribute : pkAttributes) {
if (attrNames.contains(pkAttribute)) {
hasPk = true;
break;
}
}
if (hasPk) {
if (attrNames.containsAll(pkAttributes)) {
newSchemaInfo.removeConstraintByName(pk.getName(), Constraint.ConstraintType.PRIMARYKEY.getText());
} else {
CommonUITool.openErrorBox(Messages.errColumnNotDropForPk);
return;
}
}
for (PartitionInfo partitionInfo : newSchemaInfo.getPartitionList()) {
String partitionExpr = partitionInfo.getPartitionExpr();
if (StringUtil.isNotEmpty(partitionExpr)) {
if (partitionExpr.startsWith("[") && partitionExpr.endsWith("]")) {
partitionExpr = partitionExpr.substring(1, partitionExpr.length() - 1);
if (attrNames.contains(partitionExpr)) {
CommonUITool.openErrorBox(Messages.errDropForPartitonColumn);
return;
}
} else {
if (attrNames.contains(partitionExpr)) {
CommonUITool.openErrorBox(Messages.errDropForPartitonColumn);
return;
}
}
}
}
for (TableItem selec : selection) {
DBAttribute oldAttribute = (DBAttribute) selec.getData();
if (oldAttribute == null) {
continue;
}
if (!oldAttribute.getInherit().equals(newSchemaInfo.getClassname())) {
CommonUITool.openErrorBox(Messages.errColumnNotDrop);
return;
}
if (oldAttribute.isClassAttribute()) {
newSchemaInfo.getClassAttributes().remove(oldAttribute);
} else {
newSchemaInfo.getAttributes().remove(oldAttribute);
// newSchemaInfo.removeUniqueByAttrName(selec.getText(1));
// For bug TOOLS-2390 After delete a column of a table,some
// related index doesn't been deleted.
newSchemaInfo.removeConstraintByAttrName(oldAttribute.getName());
indexTableView.setInput(newSchemaInfo);
fkTableView.setInput(newSchemaInfo);
}
SuperClassUtil.fireSuperClassChanged(database.getDatabaseInfo(), oldSchemaInfo, newSchemaInfo, newSchemaInfo.getSuperClasses());
String oldAttrName = oldAttribute.getName();
addDropAttrLog(oldAttrName, oldAttribute.isClassAttribute());
}
attrLabelProvider.setSchema(newSchemaInfo);
loadColumnData();
int itemCount = columnsTable.getItemCount();
columnsTable.select(selectionIndex < itemCount ? selectionIndex : selectionIndex - 1);
columnsTable.setFocus();
}
}
use of com.cubrid.common.core.common.model.PartitionInfo in project cubrid-manager by CUBRID.
the class TableEditorPart method editPartition.
/**
* Show the edit dialog for selected partition.
*/
private void editPartition() {
if (WidgetUtil.disposed(partitionTableView)) {
return;
}
PartitionInfo partitionInfo = null;
if (getPartitonType() == PartitionType.HASH) {
partitionInfo = partitionInfoList.get(0);
} else {
IStructuredSelection selection = (IStructuredSelection) partitionTableView.getSelection();
if (selection == null || selection.isEmpty()) {
return;
}
partitionInfo = (PartitionInfo) selection.getFirstElement();
}
String tableName = tableNameText.getText();
if (WidgetUtil.disposed(tableNameText) || StringUtil.isEmpty(tableName)) {
CommonUITool.openErrorBox(getSite().getShell(), Messages.msgNoTableName);
return;
}
newSchemaInfo.setClassname(tableName);
CreatePartitionWizard wizard = new CreatePartitionWizard(database.getDatabaseInfo(), newSchemaInfo, partitionInfoList, isNewTableFlag, partitionInfo);
CMWizardDialog dialog = new CMWizardDialog(getSite().getShell(), wizard);
dialog.setPageSize(600, 400);
if (dialog.open() != IDialogConstants.OK_ID) {
return;
}
newSchemaInfo.setPartitionList(partitionInfoList);
partitionTableView.refresh();
changePartitionTabButtonStatus();
}
use of com.cubrid.common.core.common.model.PartitionInfo in project cubrid-manager by CUBRID.
the class SchemaInfoTest method testData.
/**
* test data
*
*/
public void testData() {
assertNull(classname);
assertNull(type);
assertNull(owner);
assertNull(virtual);
assertNull(dbname);
assertNull(is_partitiongroup);
assertNull(partitiongroupname);
assertNull(classAttributes);
// DBAttribute
assertNull(attributes);
// DBMethod
assertNull(classMethods);
// DBMethod
assertNull(methods);
// DBResolution
assertNull(classResolutions);
// DBResolution
assertNull(resolutions);
// Constraint
assertNull(constraints);
// add super classes
assertNull(superClasses);
assertNull(subClasses);
assertNull(oidList);
assertNull(methodFiles);
assertNull(querySpecs);
assertNull(partitions);
SchemaInfo schemaInfo = new SchemaInfo();
schemaInfo.getConstraints();
schemaInfo.getDBMethodByName("name");
schemaInfo.addResolution(new DBResolution());
schemaInfo.addResolution(new DBResolution());
schemaInfo.addResolution(new DBResolution(), true);
schemaInfo.addResolution(new DBResolution(), false);
schemaInfo.clone();
schemaInfo.getInheritAttributes();
schemaInfo.getLocalAttributes();
schemaInfo.getInheritClassAttributes();
//create List<SchemaInfo>
List<SchemaInfo> supers = new ArrayList<SchemaInfo>();
supers.add(schemaInfo);
schemaInfo.getPK(supers);
schemaInfo.getConstraintByName("constraintName");
schemaInfo.getConstraintByName("name", "type");
schemaInfo.removeConstraintByName("name", "type");
schemaInfo.removeUniqueByAttrName("constraintName");
schemaInfo.getFKConstraint("name");
schemaInfo.getFKConstraints();
schemaInfo.removeFKConstraint("constraintName");
schemaInfo.isAttributeUnique(new DBAttribute(), supers);
schemaInfo.getForeignTables();
//create constraint
String name = "name";
String type = "FOREIGN KEY";
int keyCount = 6;
// String
List<String> rules = new ArrayList<String>();
rules.add("REFERENCES aa");
// test getters and setters
Constraint constraintYes = new Constraint(name, type);
constraintYes.setName(name);
constraintYes.setType(type);
constraintYes.setKeyCount(keyCount);
constraintYes.setRules(rules);
schemaInfo.addConstraint(constraintYes);
schemaInfo.getFKConstraints();
schemaInfo.getForeignTables();
schemaInfo.removeFKConstraint(constraintYes);
schemaInfo.addConstraint(constraintYes);
schemaInfo.removeFKConstraint("name");
schemaInfo.addConstraint(constraintYes);
schemaInfo.addQuerySpec("name");
schemaInfo.addMethodFile("constraintName");
schemaInfo.addMethod(null);
schemaInfo.addClassMethod(null);
schemaInfo.removeConstraintByName("name", "type");
schemaInfo.removeDBAttributeByName("name", false);
partitions = null;
schemaInfo.getPartitionByName("name");
schemaInfo.isSystemClass();
schemaInfo.setType("system");
schemaInfo.isSystemClass();
schemaInfo.setClassname("classname");
schemaInfo.compareTo(schemaInfo);
schemaInfo.hashCode();
//+test the equal()
assertTrue(schemaInfo.equals(schemaInfo));
assertFalse(schemaInfo.equals(null));
assertFalse(schemaInfo.equals("other object"));
//-test the equal()
schemaInfo.getMethodFiles();
schemaInfo.getClassMethods();
schemaInfo.getMethods();
schemaInfo.getLocalClassAttributes();
schemaInfo.getSubClasses();
schemaInfo.getOidList();
List<PartitionInfo> partitiona = new ArrayList<PartitionInfo>();
//create partition
String className = "className";
String partitionName = "partitionName";
@SuppressWarnings("unused") String partitionClassName = "partitionClassName";
PartitionType partitionType = PartitionType.HASH;
String partitionExpr = "partitionExpr";
final List<String> partitionValues = new ArrayList<String>();
int rows = -1;
PartitionInfo partitionInfo3 = new PartitionInfo(className, partitionName, partitionType, partitionExpr, partitionValues, rows);
partitiona.add(partitionInfo3);
schemaInfo.setPartitionList(partitiona);
schemaInfo.getPartitionByName("name");
schemaInfo.getQuerySpecs();
SchemaInfo schemaInfoOld = new SchemaInfo();
schemaInfo.setAttributes(attributes);
schemaInfo.setSuperClasses(superClasses);
schemaInfo.setClassAttributes(classAttributes);
schemaInfo.setClassResolutions(classResolutions);
schemaInfo.setResolutions(classResolutions);
schemaInfoOld.equals(schemaInfo);
//create DBMethod();
String sname = "name";
String inherit = "inherit";
String function = "function";
// test getters and setters
DBMethod dbMethod = new DBMethod();
dbMethod.setName(sname);
dbMethod.setInherit(inherit);
dbMethod.setFunction(function);
DBMethod dbMethod3 = new DBMethod();
dbMethod3.setName("notsame");
dbMethod3.setInherit("notsame");
dbMethod3.setFunction("notsame");
SchemaInfo schemaInfo3 = new SchemaInfo();
schemaInfo3.addMethod(dbMethod);
schemaInfo3.addClassMethod(dbMethod);
schemaInfo3.getDBMethodByName("name");
SchemaInfo schemaInfo2 = new SchemaInfo();
//create DBAttribute
String dname = "name";
String dtype = "type";
// it belongs to which class
String dinherit = "inherit";
boolean indexed = true;
boolean notNull = true;
boolean shared = true;
boolean unique = true;
String defaultValue = "defaultValue";
DBAttribute dbAttribute1 = new DBAttribute(dname, dtype, dinherit, indexed, notNull, shared, unique, defaultValue, null);
DBAttribute dbAttribute2 = new DBAttribute(dname, dtype, dinherit, indexed, notNull, shared, unique, defaultValue, null);
DBAttribute dbAttribute3 = new DBAttribute("notsame", dtype, dinherit, indexed, notNull, shared, unique, defaultValue, null);
//+test the equal()
SchemaInfo schemaInfo1 = new SchemaInfo();
schemaInfo1.addAttribute(dbAttribute2);
schemaInfo2.addAttribute(dbAttribute3);
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.addAttribute(dbAttribute2);
schemaInfo2.removeDBAttributeByName("notsame", false);
schemaInfo2.addAttribute(dbAttribute2);
schemaInfo1.addClassAttribute(dbAttribute2);
schemaInfo2.addClassAttribute(dbAttribute3);
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.addClassAttribute(dbAttribute2);
schemaInfo2.removeDBAttributeByName("notsame", true);
schemaInfo2.addAttribute(dbAttribute2);
schemaInfo1.addClassMethod(dbMethod);
schemaInfo2.addClassMethod(dbMethod3);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.equals(schemaInfo1);
schemaInfoOld.addClassMethod(dbMethod);
schemaInfo2.getClassMethods().clear();
schemaInfo2.addClassMethod(dbMethod);
//create DBResolution
String rname = "name";
String rclassName = "className";
String alias = "alias";
boolean isClassResolution = true;
DBResolution dbResolution = new DBResolution(rname, rclassName, alias);
dbResolution.setName(rname);
dbResolution.setClassName(rclassName);
dbResolution.setAlias(alias);
dbResolution.setClassResolution(isClassResolution);
DBResolution dbResolution3 = new DBResolution(rname, rclassName, alias);
dbResolution3.setName("notsame");
dbResolution3.setClassName(rclassName);
dbResolution3.setAlias(alias);
dbResolution3.setClassResolution(isClassResolution);
schemaInfo1.addClassResolution(dbResolution);
schemaInfo2.addClassResolution(dbResolution3);
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.addClassResolution(dbResolution);
schemaInfo2.getClassResolutions().clear();
schemaInfo2.addClassResolution(dbResolution);
schemaInfo1.setClassname("classname");
schemaInfo2.setClassname("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setClassname("classname");
schemaInfo2.setClassname("classname");
schemaInfo1.setClassname("classname");
schemaInfo2.setClassname("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setClassname("classname");
schemaInfo2.setClassname("classname");
schemaInfo2.addConstraint(new Constraint(false));
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.addConstraint(constraintYes);
schemaInfo2.getConstraints().clear();
schemaInfo2.addConstraint(constraintYes);
schemaInfo1.setDbname("dbname");
schemaInfo2.setDbname("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setDbname("dbname");
schemaInfo2.setDbname("dbname");
schemaInfo1.setPartitionGroup("isPartitiongroup");
schemaInfo2.setPartitionGroup("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setPartitionGroup("isPartitiongroup");
schemaInfo2.setPartitionGroup("isPartitiongroup");
schemaInfo1.setOwner("owner");
schemaInfo2.setOwner("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setOwner("owner");
schemaInfo2.setOwner("owner");
schemaInfo1.addResolution(dbResolution);
schemaInfo2.addResolution(dbResolution3);
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.addResolution(dbResolution);
schemaInfo2.getResolutions().clear();
schemaInfo2.addResolution(dbResolution);
schemaInfo1.getSuperClasses().clear();
schemaInfo1.addSuperClass("superClass");
schemaInfo2.addSuperClass("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.addSuperClass("superClass");
schemaInfo2.getSuperClasses().clear();
schemaInfo2.addSuperClass("superClass");
schemaInfo1.setType("type");
schemaInfo2.setType("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setType("type");
schemaInfo2.setType("type");
schemaInfo1.setVirtual("virtual");
schemaInfo2.setVirtual("notsame");
schemaInfoOld.equals(schemaInfo1);
schemaInfo2.equals(schemaInfo1);
schemaInfoOld.setVirtual("virtual");
schemaInfo2.setVirtual("virtual");
//+test the equal()
schemaInfo.addDBAttribute(dbAttribute2, true);
schemaInfo.addDBAttribute(dbAttribute2, false);
schemaInfo.replaceDBAttributeByName(dbAttribute1, dbAttribute2, true, supers);
schemaInfo.replaceDBAttributeByName(dbAttribute1, dbAttribute2, false, supers);
schemaInfo.setClassname("inherit");
schemaInfo.getLocalClassAttributes();
constraintYes.setType("UNIQUE");
List<String> a = new ArrayList<String>();
a.add("name");
constraintYes.setAttributes(a);
schemaInfo.addConstraint(constraintYes);
schemaInfo.removeUniqueByAttrName("name");
}
use of com.cubrid.common.core.common.model.PartitionInfo in project cubrid-manager by CUBRID.
the class ConstraintComparator method isPartitonChange.
/**
*
* Check whether the partition change
*
* @param oldPartitionInfoList the old partition information list
* @param newPartitionInfoList the new partition information list
* @return <code>true</code> if changed;otherwise <code>false</code>
*/
private boolean isPartitonChange(List<PartitionInfo> oldPartitionInfoList, List<PartitionInfo> newPartitionInfoList) {
if (oldPartitionInfoList == null || oldPartitionInfoList.isEmpty()) {
if (newPartitionInfoList == null || newPartitionInfoList.isEmpty()) {
return false;
}
return true;
} else {
if (newPartitionInfoList == null || newPartitionInfoList.isEmpty()) {
return true;
}
if (oldPartitionInfoList.size() != newPartitionInfoList.size()) {
return true;
}
if (oldPartitionInfoList.get(0).getPartitionType() != newPartitionInfoList.get(0).getPartitionType()) {
return true;
}
if (!oldPartitionInfoList.get(0).getPartitionExpr().trim().equals(newPartitionInfoList.get(0).getPartitionExpr().trim())) {
return true;
}
for (int i = 0; i < oldPartitionInfoList.size(); i++) {
PartitionInfo oldInfo = oldPartitionInfoList.get(i);
boolean isEqual = false;
for (int j = 0; j < newPartitionInfoList.size(); j++) {
PartitionInfo newInfo = newPartitionInfoList.get(j);
if (oldInfo.equals(newInfo)) {
isEqual = true;
break;
}
}
if (!isEqual) {
return true;
}
}
}
return false;
}
Aggregations