Search in sources :

Example 16 with DBResolution

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);
        }
    }
}
Also used : DBResolution(com.cubrid.common.core.common.model.DBResolution) PreparedStatement(java.sql.PreparedStatement)

Example 17 with DBResolution

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);
    }
}
Also used : DBResolution(com.cubrid.common.core.common.model.DBResolution) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 18 with DBResolution

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);
        }
    }
}
Also used : DBResolution(com.cubrid.common.core.common.model.DBResolution) Constraint(com.cubrid.common.core.common.model.Constraint)

Aggregations

DBResolution (com.cubrid.common.core.common.model.DBResolution)18 Constraint (com.cubrid.common.core.common.model.Constraint)10 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)6 ArrayList (java.util.ArrayList)6 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)5 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)2 PartitionType (com.cubrid.common.core.common.model.PartitionType)2 List (java.util.List)2 DBMethod (com.cubrid.common.core.common.model.DBMethod)1 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)1 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)1 PreparedStatement (java.sql.PreparedStatement)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1