use of com.cubrid.common.core.common.model.DBResolution in project cubrid-manager by CUBRID.
the class SubAttribute method getDBResolutionInfo.
/**
* Retrieves the resolutions of database
*
* @param schemaInfo SchemaInfo
* @throws SQLException the SQLException
*/
private void getDBResolutionInfo(SchemaInfo schemaInfo) throws SQLException {
if (schemaInfo != null) {
String sql = "SELECT attr_name, from_class_name, attr_type, from_attr_name" + " FROM db_attribute WHERE class_name=? AND attr_name<>from_attr_name" + " AND from_attr_name IS NOT NULL";
// [TOOLS-2425]Support shard broker
sql = databaseInfo.wrapShardQuery(sql);
try {
stmt = connection.prepareStatement(sql);
((PreparedStatement) stmt).setString(1, tableName);
rs = ((PreparedStatement) stmt).executeQuery();
while (rs.next()) {
DBResolution dbr = new DBResolution();
dbr.setAlias(rs.getString("attr_name"));
dbr.setClassName(rs.getString("from_class_name"));
dbr.setClassResolution(!rs.getString("attr_type").equals("INSTANCE"));
dbr.setName(rs.getString("from_attr_name"));
schemaInfo.addResolution(dbr);
}
} finally {
QueryUtil.freeQuery(stmt, rs);
}
}
}
use of com.cubrid.common.core.common.model.DBResolution in project cubrid-manager by CUBRID.
the class SchemaAlterDDLTest method removeResolution.
/**
* remove a resolution
*
* @param newSchema
* @param type
* @param superTable
* @param column
* @return
*/
private void removeResolution(SchemaInfo newSchema, String type, String superTable, String column) {
List<DBResolution> resolutions = null;
DBResolution removedResolution = null;
if (type.equals("Class")) {
//$NON-NLS-1$
resolutions = newSchema.getClassResolutions();
} else {
resolutions = newSchema.getResolutions();
}
for (int i = 0; i < resolutions.size(); i++) {
DBResolution r = resolutions.get(i);
if (r.getName().equals(column) && r.getClassName().equals(superTable)) {
removedResolution = resolutions.remove(i);
}
}
if (removedResolution.getAlias().equals("")) {
List<String[]> columnConflicts = null;
boolean isClassType;
if (type.equals("Class")) {
//$NON-NLS-1$
isClassType = true;
} else {
isClassType = false;
}
columnConflicts = SuperClassUtil.getColumnConflicts(databaseInfo, newSchema, newSchema.getSuperClasses(), isClassType);
DBResolution nextResolution = SuperClassUtil.getNextResolution(resolutions, removedResolution, columnConflicts);
assert (nextResolution != null);
newSchema.addResolution(nextResolution, isClassType);
SuperClassUtil.fireResolutionChanged(databaseInfo, testedSchemaInfo, newSchema, isClassType);
}
}
use of com.cubrid.common.core.common.model.DBResolution in project cubrid-manager by CUBRID.
the class SchemaAlterDDLTest method addResolution.
/**
* add a resolution
*
* @param newSchema
* @param column
* @param superTable
* @param alias
* @param isClassType
*/
private void addResolution(SchemaInfo newSchema, String column, String superTable, String alias, boolean isClassType) {
DBResolution newResolution = new DBResolution(column, superTable, alias);
newResolution.setClassResolution(isClassType);
String tbl = newResolution.getClassName();
if (newResolution != null) {
List<DBResolution> resolutions = null;
if (isClassType) {
resolutions = newSchema.getClassResolutions();
} else {
resolutions = newSchema.getResolutions();
}
if (alias.equals("")) {
for (int i = resolutions.size() - 1; i >= 0; i--) {
DBResolution r = resolutions.get(i);
// remove resolution
if (r.getName().equals(column)) {
if (r.getAlias().equals("")) {
//$NON-NLS-1$
resolutions.remove(i);
}
}
}
} else {
for (int i = resolutions.size() - 1; i >= 0; i--) {
DBResolution r = resolutions.get(i);
// remove resolution
if (r.getName().equals(column) && r.getClassName().equals(tbl)) {
resolutions.remove(i);
}
}
}
if (isClassType) {
newSchema.addClassResolution(newResolution);
SuperClassUtil.fireResolutionChanged(databaseInfo, testedSchemaInfo, newSchema, true);
} else {
newSchema.addResolution(newResolution);
SuperClassUtil.fireResolutionChanged(databaseInfo, testedSchemaInfo, newSchema, false);
}
}
}
Aggregations