use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class TableEditorPart method getNotNullChangedColumn.
/**
* Get all not null changed column
*
* @return
*/
private List<String[]> getNotNullChangedColumn() {
// FIXME move this logic to core module
List<String[]> notNullChangedColumn = new ArrayList<String[]>();
List<SchemaChangeLog> allAttrChanges = schemaChangeMgr.getAttrChangeLogs();
List<SchemaInfo> oldSupers = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), oldSchemaInfo);
if (oldSupers == null) {
return notNullChangedColumn;
}
List<SchemaInfo> newSupers = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), newSchemaInfo);
if (newSupers == null) {
return notNullChangedColumn;
}
for (SchemaChangeLog changeLog : allAttrChanges) {
if (changeLog.getOldValue() == null || changeLog.getNewValue() == null) {
continue;
}
boolean isClassAttr = changeLog.getType() == SchemeInnerType.TYPE_CLASSATTRIBUTE;
DBAttribute oldAttr = oldSchemaInfo.getDBAttributeByName(changeLog.getOldValue(), isClassAttr);
DBAttribute newAttr = newSchemaInfo.getDBAttributeByName(changeLog.getNewValue(), isClassAttr);
if (oldAttr == null || newAttr == null) {
continue;
}
boolean oldNotNull = oldAttr.isNotNull();
boolean newNotNull = newAttr.isNotNull();
Constraint newPK = newSchemaInfo.getPK(newSupers);
List<String> pkAttributes = newPK == null ? new ArrayList<String>() : newPK.getAttributes();
if (oldNotNull == newNotNull) {
continue;
}
boolean isChangedByPK = false;
if (newNotNull) {
// add a new PK
if (pkAttributes.contains(newAttr.getName())) {
isChangedByPK = true;
}
} else {
// drop an old PK
Constraint oldPK = oldSchemaInfo.getPK(oldSupers);
if (oldPK != null) {
List<String> oldPKAttrs = oldPK.getAttributes();
if (oldPKAttrs != null && oldPKAttrs.contains(newAttr.getName())) {
isChangedByPK = true;
}
}
}
if (!isChangedByPK) {
String[] newColumn = new String[] { newAttr.getName(), String.valueOf(newNotNull) };
notNullChangedColumn.add(newColumn);
}
}
return notNullChangedColumn;
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ERTable method createEmptySchemaInfo.
public static SchemaInfo createEmptySchemaInfo(String tableName, String dbName) {
SchemaInfo schemaInfo = new SchemaInfo();
schemaInfo.setType("user");
schemaInfo.setClassname(tableName);
schemaInfo.setDbname(dbName);
schemaInfo.setVirtual(ClassType.NORMAL.getText());
schemaInfo.setReuseOid(false);
return schemaInfo;
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ERTableColumn method setName.
public void setName(String newName) {
if (StringUtil.isEqual(name, newName)) {
return;
}
attr.setName(newName);
SchemaInfo schemaInfo = this.getTable().getSchemaInfo();
Constraint pk = schemaInfo.getPK();
if (pk != null && pk.contains(name, false)) {
pk.replaceAttribute(name, newName);
}
schemaInfo.updateAttrNameInIndex(name, newName);
name = newName;
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ERSchemaTableNodesLoader method getAllUserTablesInfo.
/**
* Get all the user tables node infos
*
* @return List<SchemaInfo>
*/
public List<SchemaInfo> getAllUserTablesInfo() {
List<DefaultSchemaNode> tableNodes = getAllTablesNode();
List<SchemaInfo> tables = new ArrayList<SchemaInfo>();
for (DefaultSchemaNode node : tableNodes) {
SchemaInfo table = dbNode.getDatabaseInfo().getSchemaInfo(node.getName());
if (null != table) {
tables.add(table);
}
}
return tables;
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class CubridTableParser method getReferredColumns.
/**
* Get the other table columns name which is referred on the foreign key
* constraint
*
* @param schemaInfo
* @param fkConstaint
* @return The results is all columns of pk in the primary table actually.
* @throws Exception
*/
private List<String> getReferredColumns(SchemaInfo schemaInfo, Constraint fkConstaint) throws Exception {
List<String> resultList = new ArrayList<String>();
String refTable = getReferencedTableName(fkConstaint);
SchemaInfo referedSchemaInfo = getReferencedTable(refTable);
if (referedSchemaInfo != null) {
Constraint pkConstaint = referedSchemaInfo.getPK();
if (pkConstaint == null) {
throw new ERException(Messages.bind(Messages.errFKColumnMatch, new String[] { schemaInfo.getClassname(), fkConstaint.getName() }));
}
List<String> pklist = pkConstaint.getAttributes();
for (int i = 0; i < pklist.size(); i++) {
String referedKey = pklist.get(i).replace(" ASC", "").replace(" DESC", "");
resultList.add(referedKey);
}
}
return resultList;
}
Aggregations