use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog in project cubrid-manager by CUBRID.
the class TableSchemaCompareUpdateDDL method setPositionAlterDDL.
/**
* Compare table Attributes Positions
*/
public void setPositionAlterDDL() {
// FIXME logic code move to core module
List<DBAttribute> targetDBAttributes = targetTableSchema.getAttributes();
List<DBAttribute> sourceDBAttributes = sourceTableSchema.getAttributes();
for (DBAttribute targetAttr : targetDBAttributes) {
String targetAttrName = targetAttr.getName();
int targetPosition = targetDBAttributes.indexOf(targetAttr);
DBAttribute sourceAttr = sourceTableSchema.getDBAttributeByName(targetAttrName, false);
int sourcePosition = sourceDBAttributes.indexOf(sourceAttr);
if (sourceAttr != null && sourcePosition != targetPosition) {
changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceAttr.getName(), targetAttr.getName(), SchemeInnerType.TYPE_POSITION));
}
}
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog in project cubrid-manager by CUBRID.
the class TableSchemaCompareUpdateDDL method setAttributesAlterDDL.
/**
* Compare table attributes
*/
public void setAttributesAlterDDL() {
// FIXME logic code move to core module
List<DBAttribute> sourceDBAttributes = sourceTableSchema.getAttributes();
List<DBAttribute> targetDBAttributes = targetTableSchema.getAttributes();
for (DBAttribute targetAttr : targetDBAttributes) {
String targetAttrName = targetAttr.getName().toLowerCase();
DBAttribute sourceAttr = sourceTableSchema.getDBAttributeByName(targetAttrName, false);
if (sourceAttr != null) {
if (!targetAttr.equals(sourceAttr)) {
changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceAttr.getName(), targetAttrName, SchemeInnerType.TYPE_ATTRIBUTE));
changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceAttr.getName(), targetAttrName, SchemeInnerType.TYPE_POSITION));
}
} else {
changeManager.addSchemeChangeLog(new SchemaChangeLog(null, targetAttrName, SchemeInnerType.TYPE_ATTRIBUTE));
changeManager.addSchemeChangeLog(new SchemaChangeLog(targetAttrName, targetAttrName, SchemeInnerType.TYPE_POSITION));
}
}
for (DBAttribute sourceAttr : sourceDBAttributes) {
String sourceAttrName = sourceAttr.getName();
DBAttribute targetAttr = targetTableSchema.getDBAttributeByName(sourceAttrName, false);
if (targetAttr == null) {
changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceAttrName, null, SchemeInnerType.TYPE_ATTRIBUTE));
}
}
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method makeChangeLogForIndex.
public boolean makeChangeLogForIndex(String attrName, DBAttribute editAttr, DBAttribute origAttr) {
// FIXME move this logic to core module
List<Constraint> constrainList = newERTable.getSchemaInfo().getConstraints();
if (constrainList.size() == 0 || StringUtil.isEmpty(attrName)) {
return false;
}
List<Constraint> removedConstrainList = new ArrayList<Constraint>();
List<Constraint> addedConstrainList = new ArrayList<Constraint>();
for (Constraint cons : constrainList) {
if (cons == null) {
continue;
}
if (ConstraintType.INDEX.getText().equals(cons.getType()) || ConstraintType.REVERSEINDEX.getText().equals(cons.getType()) || ConstraintType.UNIQUE.getText().equals(cons.getType()) || ConstraintType.REVERSEUNIQUE.getText().equals(cons.getType())) {
List<String> attrs = cons.getAttributes();
if (!(attrs != null && attrs.contains(attrName))) {
continue;
}
removedConstrainList.add(cons);
Constraint newCons = new Constraint(true);
newCons.setType(cons.getType());
newCons.setName(cons.getName());
cons.replaceAttribute(attrName, editAttr.getName());
newCons.setAttributes(cons.getAttributes());
for (String origRule : cons.getRules()) {
if (cons.getRules().size() == 1) {
newCons.addRule(editAttr.getName() + origRule.substring(attrName.length()));
break;
}
int spaceIndex = origRule.indexOf(" ");
String attrNameFromRule = origRule.substring(0, spaceIndex);
if (attrName.equals(attrNameFromRule)) {
newCons.addRule(editAttr.getName() + origRule.substring(attrName.length()));
} else {
newCons.addRule(origRule);
}
}
addedConstrainList.add(newCons);
String key = cons.getDefaultName(newERTable.getSchemaInfo().getClassname()) + "$" + cons.getName();
SchemaChangeLog changeLog = new SchemaChangeLog(key, key, SchemeInnerType.TYPE_INDEX);
schemaChangeMgr.addSchemeChangeLog(changeLog);
}
}
if (removedConstrainList.size() == 0) {
return false;
}
constrainList.removeAll(removedConstrainList);
constrainList.addAll(addedConstrainList);
indexTableView.setInput(newERTable.getSchemaInfo());
return true;
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog in project cubrid-manager by CUBRID.
the class TableEditorPart method addDropAttrLog.
/**
* Add a log of dropping an attribute to change list.
*
* @param isClassAttribute boolean
* @param oldAttrName String
*/
private void addDropAttrLog(String oldAttrName, boolean isClassAttribute) {
SchemaChangeLog changeLog = new SchemaChangeLog(oldAttrName, null, getSchemaInnerType(isClassAttribute));
schemaChangeMgr.addSchemeChangeLog(changeLog);
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog in project cubrid-manager by CUBRID.
the class TableEditorPart method makeChangeLogForIndex.
public boolean makeChangeLogForIndex(String attrName, DBAttribute editAttr, DBAttribute origAttr) {
List<Constraint> constrainList = newSchemaInfo.getConstraints();
if (constrainList.size() == 0) {
// FIXME move this logic to core module
return false;
}
List<Constraint> removedConstrainList = new ArrayList<Constraint>();
List<Constraint> addedConstrainList = new ArrayList<Constraint>();
for (Constraint cons : constrainList) {
if (cons == null) {
continue;
}
if (ConstraintType.INDEX.getText().equals(cons.getType()) || ConstraintType.REVERSEINDEX.getText().equals(cons.getType()) || ConstraintType.UNIQUE.getText().equals(cons.getType()) || ConstraintType.REVERSEUNIQUE.getText().equals(cons.getType())) {
List<String> attrs = cons.getAttributes();
if (!(attrs != null && attrs.contains(attrName))) {
continue;
}
removedConstrainList.add(cons);
Constraint newCons = new Constraint(true);
newCons.setType(cons.getType());
newCons.setName(cons.getName());
cons.replaceAttribute(attrName, editAttr.getName());
newCons.setAttributes(cons.getAttributes());
for (String origRule : cons.getRules()) {
if (cons.getRules().size() == 1) {
newCons.addRule(editAttr.getName() + origRule.substring(attrName.length()));
break;
}
int spaceIndex = origRule.indexOf(" ");
String attrNameFromRule = origRule.substring(0, spaceIndex);
if (attrName.equals(attrNameFromRule)) {
newCons.addRule(editAttr.getName() + origRule.substring(attrName.length()));
} else {
newCons.addRule(origRule);
}
}
addedConstrainList.add(newCons);
String key = cons.getDefaultName(newSchemaInfo.getClassname()) + "$" + cons.getName();
SchemaChangeLog changeLog = new SchemaChangeLog(key, key, SchemeInnerType.TYPE_INDEX);
schemaChangeMgr.addSchemeChangeLog(changeLog);
}
}
if (removedConstrainList.size() == 0) {
return false;
}
constrainList.removeAll(removedConstrainList);
constrainList.addAll(addedConstrainList);
indexTableView.setInput(newSchemaInfo);
return true;
}
Aggregations