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());
}
}
}
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;
}
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;
}
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;
}
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());
}
Aggregations