Search in sources :

Example 91 with SchemaInfo

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

the class AddTableFileDialog method fillInToList.

/**
	 * Fill in the to list
	 *
	 * @param tableName String
	 */
private void fillInToList(String tableName) {
    colNameList.clear();
    colTypeList.clear();
    toList.removeAll();
    ICubridNode classNode = mappingComposite.getTableNode(tableName);
    if (!mappingComposite.isNewClassNode(classNode)) {
        SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
        List<DBAttribute> attributes = schemaInfo == null ? null : schemaInfo.getAttributes();
        if (attributes == null) {
            return;
        }
        for (DBAttribute attr : attributes) {
            String column = attr.getName();
            String dataType = attr.getType();
            toList.add(column);
            colNameList.add(column);
            colTypeList.add(dataType);
        }
    } else {
        List<ICubridNode> columnList = classNode.getChildren();
        for (ICubridNode node : columnList) {
            toList.add(node.getName());
            colNameList.add(node.getName());
            colTypeList.add(node.getData(ImportObjectLabelProvider.DATE_TYPE).toString());
        }
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 92 with SchemaInfo

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

the class DatabaseInfo method getSchemaInfo.

/**
	 * get a schema object via table name
	 * 
	 * Note: using delay loading method for large amount number of tables
	 * 
	 * @param connection
	 * @param tableName String The table name
	 * @return SchemaInfo The instance of SchemaInfo
	 */
public SchemaInfo getSchemaInfo(Connection connection, String tableName) {
    if (StringUtil.isEmpty(tableName)) {
        return null;
    }
    if (schemaMap == null) {
        schemaMap = new HashMap<String, SchemaInfo>();
    }
    SchemaInfo schemaInfo = schemaMap.get(tableName);
    if (schemaInfo == null) {
        SchemaProvider schemaProvider = new SchemaProvider(this, tableName);
        schemaInfo = schemaProvider.getSchema(connection);
        if (schemaInfo == null && StringUtil.isNotEmpty(schemaProvider.getErrorMessage())) {
            errorMessage = schemaProvider.getErrorMessage();
            return null;
        } else {
            putSchemaInfo(schemaInfo);
        }
    }
    return schemaInfo;
}
Also used : SchemaProvider(com.cubrid.cubridmanager.core.cubrid.table.SchemaProvider) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 93 with SchemaInfo

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

the class DatabaseInfo method getSchemaInfo.

/**
	 * get a schema object via table name
	 * 
	 * Note: using delay loading method for large amount number of tables
	 * 
	 * @param tableName String The table name
	 * @return SchemaInfo The instance of SchemaInfo
	 */
public SchemaInfo getSchemaInfo(String tableName) {
    if (StringUtil.isEmpty(tableName)) {
        return null;
    }
    if (null == schemaMap) {
        schemaMap = new HashMap<String, SchemaInfo>();
    }
    SchemaInfo schemaInfo = schemaMap.get(tableName);
    if (null == schemaInfo) {
        SchemaProvider schemaProvider = new SchemaProvider(this, tableName);
        schemaInfo = schemaProvider.getSchema();
        if (schemaInfo == null && StringUtil.isNotEmpty(schemaProvider.getErrorMessage())) {
            errorMessage = schemaProvider.getErrorMessage();
            return null;
        } else {
            putSchemaInfo(schemaInfo);
        }
    }
    return schemaInfo;
}
Also used : SchemaProvider(com.cubrid.cubridmanager.core.cubrid.table.SchemaProvider) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 94 with SchemaInfo

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

the class SubAttribute method getTableInfo.

/**
	 * Retieves the main information of table.
	 * 
	 * @return schemaInfo SchemaInfo
	 * @throws SQLException the SQLException
	 */
private SchemaInfo getTableInfo() throws SQLException {
    boolean supportCharset = CompatibleUtil.isSupportCreateDBByCharset(databaseInfo);
    // get table comment
    boolean supportComment = SchemaCommentHandler.isInstalledMetaTable(databaseInfo, connection);
    SchemaComment schemaComment = null;
    if (supportComment) {
        schemaComment = SchemaCommentHandler.loadDescription(databaseInfo, connection, tableName).get(tableName + "*");
    }
    //get table information
    String sql = "SELECT * FROM db_class WHERE class_name=?";
    // [TOOLS-2425]Support shard broker
    sql = databaseInfo.wrapShardQuery(sql);
    SchemaInfo schemaInfo = null;
    try {
        stmt = connection.prepareStatement(sql);
        ((PreparedStatement) stmt).setString(1, tableName);
        rs = ((PreparedStatement) stmt).executeQuery();
        // databaseInfo.getServerInfo().compareVersionKey("8.2.2") >= 0;
        boolean isSupportReuseOid = CompatibleUtil.isSupportReuseOID(databaseInfo);
        if (rs.next()) {
            String type = rs.getString("class_type");
            String isSystemClass = rs.getString("is_system_class");
            String owner = rs.getString("owner_name");
            schemaInfo = new SchemaInfo();
            if ("CLASS".equals(type)) {
                schemaInfo.setVirtual(SchemaInfo.VIRTUAL_NORMAL);
            } else {
                schemaInfo.setVirtual(SchemaInfo.VIRTUAL_VIEW);
            }
            if ("NO".equals(isSystemClass)) {
                schemaInfo.setType("user");
            } else {
                schemaInfo.setType("system");
            }
            if (isSupportReuseOid) {
                String isReuseOid = rs.getString("is_reuse_oid_class");
                if ("NO".equals(isReuseOid)) {
                    schemaInfo.setReuseOid(false);
                } else {
                    schemaInfo.setReuseOid(true);
                }
            }
            if (schemaComment != null) {
                schemaInfo.setDescription(schemaComment.getDescription());
            }
            schemaInfo.setOwner(owner);
            schemaInfo.setClassname(tableName);
            schemaInfo.setDbname(databaseInfo.getDbName());
            schemaInfo.setPartitionGroup(rs.getString("partitioned"));
        }
        // after cubrid 9.1
        if (supportCharset && schemaInfo != null && StringUtil.isEqual(SchemaInfo.VIRTUAL_NORMAL, schemaInfo.getVirtual())) {
            getTableCollation(connection, schemaInfo);
        }
    } finally {
        QueryUtil.freeQuery(stmt, rs);
    }
    return schemaInfo;
}
Also used : SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment) PreparedStatement(java.sql.PreparedStatement) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 95 with SchemaInfo

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

the class SchemaAlterDDLTest method indexTest2.

//drop exist index
private void indexTest2() {
    changeList = new SchemaChangeManager(databaseInfo, false);
    ddl = new SchemaDDL(changeList, databaseInfo);
    SchemaInfo newSchema = sup2.clone();
    String indexName = null;
    String indexType = null;
    indexName = "u_sup2_date_d";
    indexType = "UNIQUE";
    Constraint index = newSchema.getConstraintByName(indexName, indexType);
    newSchema.removeConstraintByName(indexName, indexType);
    changeList.addSchemeChangeLog(new SchemaChangeLog(index.getDefaultName(newSchema.getClassname()) + "$" + //$NON-NLS-1$
    index.getName(), //$NON-NLS-1$
    null, SchemeInnerType.TYPE_INDEX));
    indexName = "i_sup2_bigint_numeric1";
    indexType = "INDEX";
    index = newSchema.getConstraintByName(indexName, indexType);
    newSchema.removeConstraintByName(indexName, indexType);
    changeList.addSchemeChangeLog(new SchemaChangeLog(index.getDefaultName(newSchema.getClassname()) + "$" + //$NON-NLS-1$
    index.getName(), //$NON-NLS-1$
    null, SchemeInnerType.TYPE_INDEX));
    indexName = "ru_sup2_numeric2_float";
    indexType = "REVERSE UNIQUE";
    index = newSchema.getConstraintByName(indexName, indexType);
    newSchema.removeConstraintByName(indexName, indexType);
    changeList.addSchemeChangeLog(new SchemaChangeLog(index.getDefaultName(newSchema.getClassname()) + "$" + //$NON-NLS-1$
    index.getName(), //$NON-NLS-1$
    null, SchemeInnerType.TYPE_INDEX));
    indexName = "ri_sup2_numeric1_float";
    indexType = "REVERSE INDEX";
    index = newSchema.getConstraintByName(indexName, indexType);
    newSchema.removeConstraintByName(indexName, indexType);
    changeList.addSchemeChangeLog(new SchemaChangeLog(index.getDefaultName(newSchema.getClassname()) + "$" + //$NON-NLS-1$
    index.getName(), //$NON-NLS-1$
    null, SchemeInnerType.TYPE_INDEX));
    String expected = "ALTER TABLE sup2 DROP UNIQUE INDEX u_sup2_date_d;" + StringUtil.NEWLINE;
    expected += "ALTER TABLE sup2 DROP INDEX i_sup2_bigint_numeric1;" + StringUtil.NEWLINE;
    expected += "ALTER TABLE sup2 DROP REVERSE UNIQUE INDEX ru_sup2_numeric2_float;" + StringUtil.NEWLINE;
    expected += "ALTER TABLE sup2 DROP REVERSE INDEX ri_sup2_numeric1_float;";
    String alterDDL = ddl.getAlterDDL(sup2, newSchema);
    assertEquals(expected, alterDDL.trim());
}
Also used : 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