use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class AddColumnAction method run.
public void run() {
ERTable table = this.getERTable();
List<String> names = new ArrayList<String>();
List<ERTableColumn> columns = table.getColumns();
for (ERTableColumn column : columns) {
names.add(column.getName());
}
AddColumnDialog dlg = new AddColumnDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), table.getName(), true, names, getERSchema());
int ret = dlg.open();
if (ret == IDialogConstants.OK_ID) {
boolean isPhysical = table.getERSchema().isPhysicModel();
String newName = dlg.getNewColumnName();
String type = dlg.getDataType();
String realType = null;
String enumeration = null;
if (isPhysical) {
realType = DataType.getRealType(type);
} else {
String upPhysicalShowType = type;
realType = DataType.getRealType(upPhysicalShowType);
}
if (DataType.DATATYPE_ENUM.equals(type)) {
realType = DataType.getUpperEnumType().toLowerCase();
enumeration = "('" + DataType.ENUM_DAFAULT_VALUE + "')";
}
DBAttribute addAttribute = new DBAttribute(newName, realType, table.getName(), false, false, false, false, null, Collation.DEFAULT_COLLATION);
addAttribute.setEnumeration(enumeration);
ERTableColumn col = new ERTableColumn(table, addAttribute, false);
if (DataType.DATATYPE_STRING.equals(type)) {
col.setLogicalType(DataType.DATATYPE_STRING);
}
table.addColumnAndFire(col);
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class QueryEditorDNDController method getScript.
/**
* Get the script
*
* @param selectedNode ISchemaNode
* @return script
*/
private String getScript(ISchemaNode selectedNode) {
// FIXME move this logic to core module
if (selectedNode == null) {
return null;
}
CubridDatabase db = selectedNode.getDatabase();
DatabaseInfo dbInfo = db.getDatabaseInfo();
GetAllAttrTask task = new GetAllAttrTask(dbInfo);
task.setClassName(selectedNode.getName());
task.getAttrList();
if (task.getErrorMsg() != null) {
CommonUITool.openErrorBox(task.getErrorMsg());
return null;
}
List<DBAttribute> allAttrList = task.getAllAttrList();
String sql = SQLGenerateUtils.getSelectSQLWithLimit(selectedNode.getName(), allAttrList);
if (sql == null) {
return "";
}
try {
return new SqlFormattingStrategy().format(sql).trim() + StringUtil.NEWLINE + StringUtil.NEWLINE;
} catch (Exception ignored) {
return sql.trim() + StringUtil.NEWLINE + StringUtil.NEWLINE;
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class SchemaAlterDDLTest method dropColumn.
/**
* drop a column
*
* @param newSchema
* @param isClassAttribute
* @param attrName
*/
private void dropColumn(SchemaInfo newSchema, boolean isClassAttribute, String attrName) {
DBAttribute oldAttribute;
oldAttribute = newSchema.getDBAttributeByName(attrName, isClassAttribute);
if (!isClassAttribute) {
newSchema.getAttributes().remove(oldAttribute);
newSchema.removeUniqueByAttrName(attrName);
} else {
newSchema.getClassAttributes().remove(oldAttribute);
}
SuperClassUtil.fireSuperClassChanged(databaseInfo, testedSchemaInfo, newSchema, newSchema.getSuperClasses());
String oldAttrName = oldAttribute.getName();
addDropAttrLog(oldAttrName, isClassAttribute);
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class SchemaAlterDDLTest method firePKAdded.
private void firePKAdded(SchemaInfo newSchema, Constraint newPK) {
List<String> attrList = newPK.getAttributes();
if (attrList.size() == 1) {
String attr = attrList.get(0);
DBAttribute a = newSchema.getDBAttributeByName(attr, false);
boolean changed = false;
if (!a.isNotNull()) {
a.setNotNull(true);
changed = true;
}
if (!a.isUnique()) {
a.setUnique(true);
changed = true;
}
if (changed) {
changeList.addSchemeChangeLog(new SchemaChangeLog(a.getName(), a.getName(), SchemeInnerType.TYPE_ATTRIBUTE));
}
} else {
for (String attr : attrList) {
DBAttribute a = newSchema.getDBAttributeByName(attr, false);
boolean changed = false;
if (!a.isNotNull()) {
a.setNotNull(true);
changed = true;
}
if (changed) {
changeList.addSchemeChangeLog(new SchemaChangeLog(a.getName(), a.getName(), SchemeInnerType.TYPE_ATTRIBUTE));
}
}
}
}
use of com.cubrid.common.core.common.model.DBAttribute 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);
}
Aggregations