use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableEditorPart method changeForEditAttribute.
/**
* Make a change log for editing attribute
*
* @param attrName
* @param lastAttr attribute previous changed by the user
* @param editAttr attribute to be changed by the user
* @param origAttr attribute on a server
* @return
*/
public boolean changeForEditAttribute(String attrName, DBAttribute editAttr, DBAttribute origAttr) {
// FIXME move this logic to core module
if (database == null || editAttr == null) {
return false;
}
String tableName = newSchemaInfo.getClassname();
editAttr.setInherit(tableName);
String newAttrName = editAttr.getName();
// new attribute
if (origAttr == null) {
if (!StringUtil.isEmpty(attrName) && newSchemaInfo.replaceDBAttributeByName(attrName, editAttr)) {
// replace
addDropAttrLog(attrName, false);
addNewAttrLog(newAttrName, false);
}
} else {
// existed attribute to changed with a name
addEditAttrLog(attrName, newAttrName, false);
}
if (origAttr == null) {
origAttr = new DBAttribute();
}
if (!origAttr.isUnique() && newSchemaInfo.getUniqueByAttrName(editAttr.getName()) == null && editAttr.isUnique()) {
Constraint unique = new Constraint(true);
unique.setType(Constraint.ConstraintType.UNIQUE.getText());
unique.addAttribute(newAttrName);
unique.addRule(newAttrName + " ASC");
unique.setName(ConstraintNamingUtil.getUniqueName(tableName, unique.getRules()));
newSchemaInfo.addConstraint(unique);
addNewUniqueLog(unique);
} else if (origAttr.isUnique() && !editAttr.isUnique()) {
if (oldSchemaInfo != null) {
Constraint unique = oldSchemaInfo.getUniqueByAttrName(origAttr.getName());
addDelUniqueLog(unique);
}
newSchemaInfo.removeUniqueByAttrName(attrName);
} else if (!origAttr.isUnique() && !editAttr.isUnique()) {
Constraint unique = newSchemaInfo.getUniqueByAttrName(attrName);
if (unique != null) {
addDelUniqueLog(unique);
}
newSchemaInfo.removeUniqueByAttrName(attrName);
}
indexTableView.setInput(newSchemaInfo);
fkTableView.setInput(newSchemaInfo);
if (database != null && database.getDatabaseInfo() != null && newSchemaInfo != null) {
SuperClassUtil.fireSuperClassChanged(database.getDatabaseInfo(), oldSchemaInfo, newSchemaInfo, newSchemaInfo.getSuperClasses());
}
attrLabelProvider.setSchema(newSchemaInfo);
loadColumnData();
columnTableView.setSelection(new StructuredSelection(editAttr), true);
columnsTable.setFocus();
handleSelectionChangeInColumnTable();
return true;
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableEditorPart method removeTempDBAttributeByName.
/**
* Remove temporary attribute by name
*
* @param name
*/
public void removeTempDBAttributeByName(String name) {
List<DBAttribute> removeList = new ArrayList<DBAttribute>();
for (DBAttribute attr : tempDBAttributeList) {
if (!StringUtil.isEmpty(name) && StringUtil.isEqual(name, attr.getName())) {
removeList.add(attr);
}
}
tempDBAttributeList.removeAll(removeList);
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableEditorPart method openEditIndexDialog.
/**
* Open the index edit dialog with the constraint object
*
* @param editedIndex Constraint
*/
private void openEditIndexDialog(Constraint editedIndex) {
boolean isNewConstraint = true;
for (int i = 0, len = originalConstraints.size(); i < len; i++) {
if (originalConstraints.get(i) == editedIndex) {
isNewConstraint = false;
}
}
AddIndexDialog dlg = new AddIndexDialog(getSite().getShell(), newSchemaInfo, database, editedIndex, isNewConstraint);
int returnCode = dlg.open();
if (returnCode == AddIndexDialog.OK) {
Constraint newIndex = dlg.getIndexConstraint();
if (newIndex == null) {
return;
}
newSchemaInfo.removeConstraintByName(editedIndex.getName(), editedIndex.getType());
newSchemaInfo.addConstraint(newIndex);
// For bug TOOLS-2394 Unique index can't be added again
if (Constraint.ConstraintType.UNIQUE.getText().equals(newIndex.getType()) && newIndex.getAttributes().size() == 1) {
DBAttribute attr = newSchemaInfo.getDBAttributeByName(newIndex.getAttributes().get(0), false);
attr.setUnique(true);
loadColumnData();
}
boolean modifiedUK = Constraint.ConstraintType.UNIQUE.getText().equals(editedIndex.getType()) && editedIndex.getAttributes().size() == 1;
boolean noNewUK = !Constraint.ConstraintType.UNIQUE.getText().equals(newIndex.getType()) || newIndex.getAttributes().size() != 1;
if (modifiedUK && noNewUK) {
String attrName = editedIndex.getAttributes().get(0);
DBAttribute attr = newSchemaInfo.getDBAttributeByName(attrName, false);
if (attr != null) {
attr.setUnique(false);
loadColumnData();
}
}
String key1 = editedIndex.getDefaultName(newSchemaInfo.getClassname()) + "$" + editedIndex.getName();
String key2 = newIndex.getDefaultName(newSchemaInfo.getClassname()) + "$" + newIndex.getName();
SchemaChangeLog changeLog = new SchemaChangeLog(key1, key2, SchemeInnerType.TYPE_INDEX);
schemaChangeMgr.addSchemeChangeLog(changeLog);
indexTableView.setInput(newSchemaInfo);
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableEditorPart method addNewColumn.
public void addNewColumn() {
// FIXME move this logic to core module
if (newSchemaInfo == null) {
return;
}
// boolean hasNotFinishedColumn = false;
boolean hasDuplicatedColumn = false;
List<DBAttribute> items = newSchemaInfo.getAttributes();
if (items != null && items.size() > 0) {
Set<String> matches = new HashSet<String>();
// check whether there is no name column
for (DBAttribute attr : items) {
if (attr == null) {
continue;
}
if (StringUtil.isEmpty(attr.getName())) {
continue;
}
if (matches.contains(attr.getName())) {
hasDuplicatedColumn = true;
break;
}
matches.add(attr.getName());
}
}
if (hasDuplicatedColumn) {
CommonUITool.openErrorBox(Messages.errSameNameOnEditTableAddColumn);
return;
}
String collation = null;
if (newSchemaInfo != null && newSchemaInfo.getCollation() != null) {
collation = newSchemaInfo.getCollation();
} else {
collation = Collation.DEFAULT_COLLATION;
}
String newAttrName = "";
DBAttribute addAttribute = new DBAttribute(newAttrName, DataType.DATATYPE_CHAR, newSchemaInfo.getClassname(), false, false, false, false, null, collation);
addAttribute.setNew(true);
tempDBAttributeList.add(addAttribute);
loadColumnData();
columnTableView.setSelection(new StructuredSelection(addAttribute), true);
columnsTable.setFocus();
handleSelectionChangeInColumnTable();
}
use of com.cubrid.common.core.common.model.DBAttribute 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();
}
}
Aggregations