Search in sources :

Example 31 with SchemaInfo

use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.

the class GetAllSchemaTask method getQuerySpecs.

/**
	 * Get view's query specs.
	 *
	 * @param schemaInfo SchemaInfo
	 * @param isView boolean
	 * @throws SQLException the SQLException
	 */
private void getQuerySpecs() throws SQLException {
    String sql = "SELECT vclass_name, vclass_def FROM db_vclass ORDER BY vclass_name";
    // [TOOLS-2425]Support shard broker
    sql = databaseInfo.wrapShardQuery(sql);
    try {
        stmt = connection.prepareStatement(sql);
        rs = ((PreparedStatement) stmt).executeQuery();
        while (rs.next()) {
            String vClassName = rs.getString("vclass_name");
            String vClassDef = rs.getString("vclass_def");
            SchemaInfo schemaInfo = schemas.get(vClassName);
            if (schemaInfo == null) {
                LOGGER.error("View " + vClassName + " not found on the schema info.");
                continue;
            }
            schemaInfo.addQuerySpec(vClassDef);
        }
    } finally {
        QueryUtil.freeQuery(stmt, rs);
    }
}
Also used : SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 32 with SchemaInfo

use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.

the class GetAllSchemaTask method getSuperClassInfo.

//	/**
//	 * Convert data type string from db to strings to displayed in client.
//	 *
//	 * @param dataType String
//	 * @param prec String
//	 * @param scale String
//	 * @return local string of data type
//	 * 
//	 * @deprecated Use following static method instead:
//	 *             <br>com.cubrid.cubridmanager.core.cubrid.table.model.
//	 *             DataType.convertAttrTypeString(String, String, String);
//	 */
//	private String convertAttrTypeString(String dataType, String prec,
//			String scale) {
//		String dt = dataType;
//		if ("SHORT".equals(dt)) {
//			dt = ("smallint");
//		} else if ("STRING".equals(dt)) {
//			dt = ("character varying" + "(" + prec + ")");
//		} else if ("CHAR".equals(dt)) {
//			dt = ("character(" + prec + ")");
//		} else if ("VARCHAR".equals(dt)) {
//			dt = ("character varying(" + prec + ")");
//		} else if ("NCHAR".equals(dt)) {
//			dt = ("national character(" + prec + ")");
//		} else if ("VARNCHAR".equals(dt)) {
//			dt = ("national character varying(" + prec + ")");
//		} else if ("BIT".equals(dt)) {
//			dt = ("bit(" + prec + ")");
//		} else if ("VARBIT".equals(dt)) {
//			dt = ("bit varying(" + prec + ")");
//		} else if ("NUMERIC".equals(dt)) {
//			dt = ("numeric(" + prec + "," + scale + ")");
//		} else if ("SET".equals(dt)) {
//			dt = ("set_of");
//		} else if ("MULTISET".equals(dt)) {
//			dt = ("multiset_of");
//		} else if ("SEQUENCE".equals(dt)) {
//			dt = ("sequence_of");
//		} else {
//			dt = (dt.toLowerCase(Locale.getDefault()));
//		}
//		return dt;
//	}
/**
	 * Get super class information (partitioned table)
	 *
	 * @param schemaInfo the SchemaInfo
	 * @throws SQLException the exception
	 */
private void getSuperClassInfo() throws SQLException {
    String sql = "SELECT class_name, super_class_name" + " FROM db_direct_super_class" + " ORDER BY class_name, super_class_name";
    // [TOOLS-2425]Support shard broker
    sql = databaseInfo.wrapShardQuery(sql);
    try {
        stmt = connection.prepareStatement(sql);
        rs = ((PreparedStatement) stmt).executeQuery();
        while (rs.next()) {
            String className = rs.getString("class_name");
            String superClass = rs.getString("super_class_name");
            SchemaInfo schemaInfo = schemas.get(className);
            if (schemaInfo != null) {
                schemaInfo.addSuperClass(superClass);
            } else {
                LOGGER.error("Table " + className + " not found on the schema info.");
            }
        }
    } finally {
        QueryUtil.freeQuery(stmt, rs);
    }
}
Also used : SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 33 with SchemaInfo

use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.

the class GetAllSchemaTask method getPartitionInfo.

/**
	 * Get the partition information of table.
	 *
	 * @param schemaInfo SchemaInfo
	 */
private void getPartitionInfo() throws SQLException {
    final String sql = "SELECT class_name, partition_name, partition_class_name," + " partition_type, partition_expr, partition_values" + " FROM db_partition" + " ORDER BY class_name";
    stmt = connection.createStatement();
    rs = stmt.executeQuery(sql);
    String exprDataType = null;
    while (rs.next()) {
        String className = rs.getString("class_name");
        String partitionName = rs.getString("partition_name");
        String partitionClassName = rs.getString("partition_class_name");
        String partitionExpr = rs.getString("partition_expr");
        SchemaInfo schemaInfo = schemas.get(className);
        if (schemaInfo == null) {
            LOGGER.error("Table " + className + " not found on the schema info.");
            continue;
        }
        PartitionType partitionType = null;
        String partitionTypeStr = rs.getString("partition_type");
        if (partitionTypeStr.equalsIgnoreCase("HASH")) {
            partitionType = PartitionType.HASH;
        } else if (partitionTypeStr.equalsIgnoreCase("LIST")) {
            partitionType = PartitionType.LIST;
        } else if (partitionTypeStr.equalsIgnoreCase("RANGE")) {
            partitionType = PartitionType.RANGE;
        }
        List<String> partitionValues = new ArrayList<String>();
        if (partitionType != PartitionType.HASH) {
            Object obj = rs.getObject("partition_values");
            if (obj == null) {
                continue;
            }
            Object[] arr = (Object[]) obj;
            for (int i = 0, len = arr.length; i < len; i++) {
                if (arr[i] == null) {
                    partitionValues.add(null);
                } else {
                    partitionValues.add(arr[i].toString());
                }
            }
        }
        PartitionInfo partitionItem = new PartitionInfo(className, partitionName, partitionClassName, partitionType, partitionExpr, partitionValues, -1);
        List<PartitionInfo> result = schemaInfo.getPartitionList();
        if (result == null) {
            result = new ArrayList<PartitionInfo>();
            schemaInfo.setPartitionList(result);
        }
        if (exprDataType == null && partitionExpr != null && partitionExpr.trim().length() > 0) {
            exprDataType = getExprDataType(className, partitionExpr);
        }
        partitionItem.setPartitionExprType(exprDataType);
        result.add(partitionItem);
    }
}
Also used : ArrayList(java.util.ArrayList) PartitionInfo(com.cubrid.common.core.common.model.PartitionInfo) PartitionType(com.cubrid.common.core.common.model.PartitionType) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 34 with SchemaInfo

use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.

the class SuperClassUtil method getColumnConflicts.

/**
	 * given a set of super classes, return the conflict attribute information,
	 * including: <li>attribute name <li>data type <li>name of the table which
	 * contains the attribute
	 * 
	 * @param database DatabaseInfo
	 * @param newSchemaInfo SchemaInfo
	 * @param superClasses List<String>
	 * @param isClassAttr boolean
	 * @return List<String[]>
	 */
public static List<String[]> getColumnConflicts(DatabaseInfo database, SchemaInfo newSchemaInfo, List<String> superClasses, boolean isClassAttr) {
    List<DBAttribute> localAttributes = new ArrayList<DBAttribute>();
    if (isClassAttr) {
        localAttributes.addAll(newSchemaInfo.getLocalClassAttributes());
    } else {
        localAttributes.addAll(newSchemaInfo.getLocalAttributes());
    }
    //		List<String> superClasses = newSchema.getSuperClasses();
    Map<String, List<SchemaInfo>> columnInheritSchemaMap = new HashMap<String, List<SchemaInfo>>();
    addAttributes2StatisticMap(columnInheritSchemaMap, newSchemaInfo, localAttributes, isClassAttr);
    addAttributes2StatisticMap(columnInheritSchemaMap, database, superClasses, isClassAttr);
    List<String[]> retList = new ArrayList<String[]>();
    for (Iterator<Entry<String, List<SchemaInfo>>> i = columnInheritSchemaMap.entrySet().iterator(); i.hasNext(); ) {
        Entry<String, List<SchemaInfo>> entry = i.next();
        String columnName = entry.getKey();
        List<SchemaInfo> schemaList = entry.getValue();
        if (schemaList.size() > 1) {
            for (SchemaInfo s : schemaList) {
                DBAttribute a = s.getDBAttributeByName(columnName, isClassAttr);
                if (a == null) {
                    continue;
                }
                String[] strs = { columnName, a.getType(), s.getClassname() };
                retList.add(strs);
            }
        }
    }
    return retList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Entry(java.util.Map.Entry) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ArrayList(java.util.ArrayList) List(java.util.List) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 35 with SchemaInfo

use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.

the class SuperClassUtil method addAttributes2StatisticMap.

/**
	 * add super classes' attribute to map for statistic
	 * 
	 * @param columnSchemaMap Map<String, List<SchemaInfo>> the map for
	 *        statistic,structure: key=attribute name, value=List\<SchemaInfo\>
	 * @param database DatabaseInfo
	 * @param superClasses List<String>
	 * @param isClassAttr boolean
	 */
private static void addAttributes2StatisticMap(Map<String, List<SchemaInfo>> columnSchemaMap, DatabaseInfo database, List<String> superClasses, boolean isClassAttr) {
    List<SchemaInfo> schemalist = new ArrayList<SchemaInfo>();
    for (int i = 0, n = superClasses.size(); i < n; i++) {
        String superClass = superClasses.get(i);
        SchemaInfo superSchema = database.getSchemaInfo(superClass);
        schemalist.add(superSchema);
    }
    addAttributes2StatisticMap(columnSchemaMap, schemalist, isClassAttr);
}
Also used : ArrayList(java.util.ArrayList) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)136 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)57 Constraint (com.cubrid.common.core.common.model.Constraint)56 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)15 List (java.util.List)15 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)10 Connection (java.sql.Connection)10 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)9 SQLException (java.sql.SQLException)9 TableItem (org.eclipse.swt.widgets.TableItem)9 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)8 SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)8 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)7 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 DBResolution (com.cubrid.common.core.common.model.DBResolution)6 Map (java.util.Map)5