use of com.cubrid.common.core.schemacomment.model.SchemaComment in project cubrid-manager by CUBRID.
the class GetAllSchemaTask method getColumnInfo.
/**
* Get column information
*
* @param schemaInfo the SchemaInfo
* @throws SQLException the exception
*/
private void getColumnInfo(ResultSet rs, SchemaInfo schemaInfo, boolean supportCharset, Map<String, SchemaComment> descriptions) throws SQLException {
if (schemaInfo == null) {
return;
}
Map<String, String> columnCollMap = null;
if (supportCharset && isNeedCollationInfo) {
columnCollMap = GetSchemaTask.extractColumnCollationMap(connection, schemaInfo);
}
String attrName = rs.getString("attr_name");
String type = rs.getString("attr_type");
String inherit = rs.getString("from_class_name");
String dataType = rs.getString("data_type");
String prec = rs.getString("prec");
String scale = rs.getString("scale");
String isNull = rs.getString("is_nullable");
String defaultValue = rs.getString("default_value");
DBAttribute attr = new DBAttribute();
attr.setName(attrName);
if (inherit == null) {
attr.setInherit(schemaInfo.getClassname());
} else {
attr.setInherit(inherit);
}
if ("YES".equals(isNull)) {
//null
attr.setNotNull(false);
} else {
attr.setNotNull(true);
}
dataType = DataType.convertAttrTypeString(dataType, prec, scale);
attr.setType(dataType);
//Fix bug TOOLS-3093
defaultValue = DataType.convertDefaultValue(dataType, defaultValue, databaseInfo);
attr.setDefault(defaultValue);
//Fixe bug TOOLS-259
//Different solution between CQB and CM on default value make some problem
attr.resetDefault();
// after 9.1
if (supportCharset && columnCollMap != null) {
String collation = columnCollMap.get(attrName);
attr.setCollation(collation);
}
SchemaComment columnSchema = descriptions != null ? descriptions.get(schemaInfo.getClassname() + "*" + attrName) : null;
if (columnSchema != null) {
attr.setDescription(columnSchema.getDescription());
}
if ("INSTANCE".equals(type)) {
//INSTANCE
schemaInfo.addAttribute(attr);
} else if ("CLASS".equals(type)) {
schemaInfo.addClassAttribute(attr);
} else {
attr.setShared(true);
schemaInfo.addAttribute(attr);
}
}
use of com.cubrid.common.core.schemacomment.model.SchemaComment 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.schemacomment.model.SchemaComment in project cubrid-manager by CUBRID.
the class SubAttribute method getColumnInfo.
/**
* Get column information
*
* @param schemaInfo the SchemaInfo
* @throws SQLException the exception
*/
private void getColumnInfo(SchemaInfo schemaInfo) throws SQLException {
if (schemaInfo != null) {
String sql = null;
Map<String, String> columnCollMap = null;
boolean supportCharset = CompatibleUtil.isSupportCreateDBByCharset(databaseInfo);
if (supportCharset && isNeedCollationInfo && StringUtil.isEqual(schemaInfo.getVirtual(), SchemaInfo.VIRTUAL_NORMAL)) {
columnCollMap = extractColumnCollationMap(connection, schemaInfo);
}
// get table comment
boolean supportComment = SchemaCommentHandler.isInstalledMetaTable(databaseInfo, connection);
Map<String, SchemaComment> comments = null;
if (supportComment) {
comments = SchemaCommentHandler.loadDescriptions(databaseInfo, connection);
}
sql = "SELECT *" + " FROM db_attribute" + " WHERE class_name=? " + " ORDER BY def_order";
// [TOOLS-2425]Support shard broker
sql = databaseInfo.wrapShardQuery(sql);
List<String> enumColumnList = new ArrayList<String>();
try {
stmt = connection.prepareStatement(sql);
((PreparedStatement) stmt).setString(1, tableName);
rs = ((PreparedStatement) stmt).executeQuery();
while (rs.next()) {
String attrName = rs.getString("attr_name");
String type = rs.getString("attr_type");
String inherit = rs.getString("from_class_name");
String dataType = rs.getString("data_type");
String prec = rs.getString("prec");
String scale = rs.getString("scale");
String isNull = rs.getString("is_nullable");
String defaultValue = rs.getString("default_value");
DBAttribute attr = new DBAttribute();
attr.setName(attrName);
if (inherit == null) {
attr.setInherit(tableName);
} else {
attr.setInherit(inherit);
}
if ("YES".equals(isNull)) {
//null
attr.setNotNull(false);
} else {
attr.setNotNull(true);
}
if (DataType.DATATYPE_ENUM.equalsIgnoreCase(dataType)) {
enumColumnList.add(attrName);
}
dataType = DataType.convertAttrTypeString(dataType, prec, scale);
attr.setType(dataType);
//Fix bug TOOLS-3093
defaultValue = DataType.convertDefaultValue(dataType, defaultValue, databaseInfo);
attr.setDefault(defaultValue);
//Fixe bug TOOLS-259
//Different solution between CQB and CM on default value make some problem
attr.resetDefault();
// after 9.1
if (supportCharset && columnCollMap != null && DataType.canUseCollation(attr.getType())) {
String collation = columnCollMap.get(attrName);
attr.setCollation(collation);
}
SchemaComment schemaComment = comments.get(tableName + "*" + attrName);
if (schemaComment != null) {
attr.setDescription(schemaComment.getDescription());
}
if ("INSTANCE".equals(type)) {
//INSTANCE
schemaInfo.addAttribute(attr);
} else if ("CLASS".equals(type)) {
schemaInfo.addClassAttribute(attr);
} else {
attr.setShared(true);
schemaInfo.addAttribute(attr);
}
}
} finally {
QueryUtil.freeQuery(stmt, rs);
}
// Get enumeration
if (CompatibleUtil.isSupportEnumVersion(databaseInfo) && enumColumnList.size() > 0) {
String escapedTableName = QuerySyntax.escapeKeyword(schemaInfo.getClassname());
StringBuilder sb = new StringBuilder();
sb.append("SHOW COLUMNS FROM ").append(escapedTableName).append(" WHERE FIELD IN (");
try {
stmt = connection.createStatement();
for (int i = 0; i < enumColumnList.size(); i++) {
sb.append("'").append(enumColumnList.get(i)).append("'");
if (i + 1 < enumColumnList.size()) {
sb.append(",");
}
}
sb.append(");");
rs = stmt.executeQuery(sb.toString());
while (rs.next()) {
String name = rs.getString("Field");
String type = rs.getString("Type");
DBAttribute attr = schemaInfo.getDBAttributeByName(name, false);
attr.setEnumeration(StringUtil.getEnumeration(type));
}
} finally {
QueryUtil.freeQuery(stmt, rs);
}
}
}
}
Aggregations