use of com.cubrid.common.core.schemacomment.model.SchemaComment in project cubrid-manager by CUBRID.
the class SchemaCommentHandler method bindSchemaInfo.
/**
* Bind schema descriptions to SchemaInfo object.
*
* @param comments
* @param schema
*/
public static void bindSchemaInfo(Map<String, SchemaComment> comments, SchemaInfo schema) {
if (comments == null || schema == null) {
return;
}
String tableName = schema.getClassname();
SchemaComment cmt = find(comments, tableName, null);
if (cmt != null) {
schema.setDescription(cmt.getDescription());
}
if (schema.getAttributes() == null) {
return;
}
for (DBAttribute attr : schema.getAttributes()) {
if (attr.getName() == null) {
continue;
}
cmt = find(comments, tableName, attr.getName());
if (cmt != null) {
attr.setDescription(cmt.getDescription());
}
}
}
use of com.cubrid.common.core.schemacomment.model.SchemaComment in project cubrid-manager by CUBRID.
the class SchemaCommentHandler method loadObjectDescription.
public static SchemaComment loadObjectDescription(IDatabaseSpec dbSpec, Connection conn, String objName, CommentType type) throws SQLException {
String sql = null;
switch(type) {
case INDEX:
sql = "SELECT index_name, comment " + "FROM db_index " + "WHERE index_name = ?";
break;
case VIEW:
sql = "SELECT vclass_name, comment " + "FROM db_vclass " + "WHERE vclass_name = ?";
break;
case SP:
sql = "SELECT sp_name, comment " + "FROM db_stored_procedure " + "WHERE sp_name = ?";
break;
case TRIGGER:
sql = "SELECT name, comment " + "FROM db_trigger " + "WHERE name = ?";
break;
case SERIAL:
sql = "SELECT name, comment " + "FROM db_serial " + "WHERE name = ?";
break;
case USER:
sql = "SELECT name, comment " + "FROM db_user " + "WHERE name = ?";
break;
case PARTITION:
sql = "SELECT partition_name, comment " + "FROM db_partition " + "WHERE partition_name = ?";
break;
}
// [TOOLS-2425]Support shard broker
if (dbSpec.isShard()) {
sql = dbSpec.wrapShardQuery(sql);
}
SchemaComment schemaComment = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, objName);
rs = pstmt.executeQuery();
if (rs.next()) {
schemaComment = new SchemaComment();
schemaComment.setType(type);
schemaComment.setObjectName(rs.getString(1));
schemaComment.setDescription(rs.getString(2));
}
} catch (SQLException e) {
QueryUtil.rollback(conn);
LOGGER.error(e.getMessage(), e);
throw e;
} finally {
QueryUtil.freeQuery(pstmt, rs);
}
return schemaComment;
}
use of com.cubrid.common.core.schemacomment.model.SchemaComment in project cubrid-manager by CUBRID.
the class TestSchemaComment method testGetSet.
public void testGetSet() {
SchemaComment meta = new SchemaComment();
meta.setTable("table");
meta.setColumn("column");
meta.setDescription("description");
assertTrue(meta.isTable());
assertFalse(meta.isColumn());
assertEquals(meta.getTable(), "table");
assertEquals(meta.getColumn(), "column");
assertEquals(meta.getDescription(), "description");
meta = new SchemaComment();
meta.setTable("table");
meta.setColumn(null);
meta.setDescription("description");
assertFalse(meta.isTable());
assertTrue(meta.isColumn());
assertEquals(meta.getTable(), "table");
assertNull(meta.getColumn());
assertEquals(meta.getDescription(), "description");
}
use of com.cubrid.common.core.schemacomment.model.SchemaComment in project cubrid-manager by CUBRID.
the class TableEditorPart method init.
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
TableEditorInput tableInfoEditorInput = (TableEditorInput) input;
this.database = tableInfoEditorInput.getDatabase();
this.editedTableNode = tableInfoEditorInput.getEditedTableNode();
this.isNewTableFlag = tableInfoEditorInput.isNewTableFlag();
this.dbUserList = tableInfoEditorInput.getDbUserList();
this.showDefaultType = tableInfoEditorInput.getType();
this.collationList = tableInfoEditorInput.getCollationList();
if (collationList != null) {
Collation emptyCollation = new Collation();
emptyCollation.setCharset("");
emptyCollation.setName("");
collationList.add(0, emptyCollation);
}
this.oldSchemaInfo = tableInfoEditorInput.getSchemaInfo();
this.supportCharset = CompatibleUtil.isSupportCreateDBByCharset(database.getDatabaseInfo());
if (isNewTableFlag) {
newSchemaInfo = new SchemaInfo();
//$NON-NLS-1$
newSchemaInfo.setClassname("");
newSchemaInfo.setOwner(database.getUserName());
newSchemaInfo.setDbname(database.getName());
newSchemaInfo.setType(Messages.userSchema);
newSchemaInfo.setVirtual(Messages.schemaTypeClass);
if (database.getDatabaseInfo() != null) {
newSchemaInfo.setCollation(database.getDatabaseInfo().getCollation());
}
} else {
newSchemaInfo = null;
if (tableInfoEditorInput.getSchemaInfo() != null) {
newSchemaInfo = tableInfoEditorInput.getSchemaInfo().clone();
originalConstraints.addAll(newSchemaInfo.getConstraints());
}
}
if (supportCharset) {
columnProperites = new String[] { IAttributeColumn.COL_EMPTY, IAttributeColumn.COL_FLAG, IAttributeColumn.COL_NAME, IAttributeColumn.COL_DATATYPE, IAttributeColumn.COL_DEFAULT, IAttributeColumn.COL_AUTO_INCREMENT, IAttributeColumn.COL_NOT_NULL, IAttributeColumn.COL_PK, IAttributeColumn.COL_UK, IAttributeColumn.COL_SHARED, IAttributeColumn.COL_COLLATION, IAttributeColumn.COL_MEMO };
} else {
columnProperites = new String[] { IAttributeColumn.COL_EMPTY, IAttributeColumn.COL_FLAG, IAttributeColumn.COL_NAME, IAttributeColumn.COL_DATATYPE, IAttributeColumn.COL_DEFAULT, IAttributeColumn.COL_AUTO_INCREMENT, IAttributeColumn.COL_NOT_NULL, IAttributeColumn.COL_PK, IAttributeColumn.COL_UK, IAttributeColumn.COL_SHARED, IAttributeColumn.COL_MEMO };
}
Connection conn = null;
try {
conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
IDatabaseSpec dbSpec = database.getDatabaseInfo();
isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
database.getDatabaseInfo().setSupportTableComment(isSupportTableComment);
if (isSupportTableComment && !isNewTableFlag && newSchemaInfo != null) {
Map<String, SchemaComment> map = SchemaCommentHandler.loadDescription(dbSpec, conn, newSchemaInfo.getClassname());
for (DBAttribute attr : newSchemaInfo.getAttributes()) {
SchemaComment schemaComment = SchemaCommentHandler.find(map, newSchemaInfo.getClassname(), attr.getName());
if (schemaComment != null) {
attr.setDescription(schemaComment.getDescription());
}
}
// get description for index
for (Constraint cons : newSchemaInfo.getConstraints()) {
if (CompatibleUtil.isCommentSupports(dbSpec)) {
String indexName = cons.getName();
SchemaComment indexComment = SchemaCommentHandler.loadObjectDescription(dbSpec, conn, indexName, CommentType.INDEX);
if (indexComment != null) {
cons.setDescription(indexComment.getDescription());
}
}
}
SchemaComment schemaComment = SchemaCommentHandler.find(map, newSchemaInfo.getClassname(), null);
if (schemaComment != null) {
newSchemaInfo.setDescription(schemaComment.getDescription());
}
}
} catch (SQLException e) {
LOGGER.error("", e);
} catch (Exception e) {
LOGGER.error("", e);
} finally {
QueryUtil.freeQuery(conn);
}
schemaChangeMgr = new SchemaChangeManager(database.getDatabaseInfo(), isNewTableFlag);
schemaDDL = new SchemaDDL(schemaChangeMgr, database.getDatabaseInfo());
if (database != null) {
isSupportChange = CompatibleUtil.isSupportChangeColumn(database.getDatabaseInfo());
}
setSite(site);
setInput(input);
setPartName(input.getName());
setTitleToolTip(input.getName());
setTitleImage(CommonUIPlugin.getImage("icons/navigator/schema_table.png"));
}
use of com.cubrid.common.core.schemacomment.model.SchemaComment in project cubrid-manager by CUBRID.
the class GetAllSchemaTask method getTableInfo.
/**
* Retieves the main information of table.
*
* @return schemaInfo SchemaInfo
* @throws SQLException the SQLException
*/
private void getTableInfo() throws SQLException {
boolean isSupportReuseOid = CompatibleUtil.isSupportReuseOID(databaseInfo);
boolean isSupportCharset = CompatibleUtil.isSupportCreateDBByCharset(databaseInfo);
String reuseOidCoulmn = isSupportReuseOid ? ", c.is_reuse_oid_class\n" : "\n";
String dbName = databaseInfo.getDbName();
boolean isSupportComment = SchemaCommentHandler.isInstalledMetaTable(databaseInfo, connection);
Map<String, SchemaComment> descriptions = null;
if (isSupportComment) {
descriptions = SchemaCommentHandler.loadDescriptions(databaseInfo, connection);
}
String sql = "SELECT a.attr_name, a.attr_type, a.from_class_name," + " a.data_type, a.prec, a.scale, a.is_nullable," + " a.domain_class_name, a.default_value, a.def_order," + " c.is_system_class, c.class_type, c.partitioned, c.owner_name, c.class_name," + " a.from_attr_name" + reuseOidCoulmn + " FROM db_attribute a, db_class c" + " WHERE c.class_name=a.class_name" + " ORDER BY a.class_name, a.def_order";
// [TOOLS-2425]Support shard broker
sql = databaseInfo.wrapShardQuery(sql);
try {
stmt = connection.prepareStatement(sql);
rs = ((PreparedStatement) stmt).executeQuery();
SchemaInfo schemaInfo = null;
while (rs.next()) {
String type = rs.getString("class_type");
boolean isTable = "CLASS".equals(type);
boolean isUserClass = "NO".equals(rs.getString("is_system_class"));
String owner = rs.getString("owner_name");
String className = rs.getString("class_name");
String partitioned = rs.getString("partitioned");
schemaInfo = schemas.get(className);
if (schemaInfo == null) {
schemaInfo = new SchemaInfo();
schemas.put(className, schemaInfo);
}
if (isTable) {
schemaInfo.setVirtual(VIRTUAL_NORMAL);
} else {
schemaInfo.setVirtual(VIRTUAL_VIEW);
}
if (isUserClass) {
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);
}
}
SchemaComment tableComment = isSupportComment ? descriptions.get(className + "*") : null;
if (tableComment != null) {
schemaInfo.setDescription(tableComment.getDescription());
}
schemaInfo.setOwner(owner);
schemaInfo.setClassname(className);
schemaInfo.setDbname(dbName);
schemaInfo.setPartitionGroup(partitioned);
getColumnInfo(rs, schemaInfo, isSupportCharset, descriptions);
String fromAttrName = rs.getString("from_attr_name");
String attrName = rs.getString("attr_name");
if (StringUtil.isNotEmpty(fromAttrName) && !fromAttrName.equals(attrName)) {
DBResolution dbr = new DBResolution();
dbr.setAlias(attrName);
dbr.setClassName(rs.getString("from_class_name"));
dbr.setClassResolution(!rs.getString("attr_type").equals("INSTANCE"));
dbr.setName(fromAttrName);
schemaInfo.addResolution(dbr);
}
if (isSupportCharset && isNeedCollationInfo) {
GetSchemaTask.getTableCollation(connection, schemaInfo);
}
}
} finally {
QueryUtil.freeQuery(stmt, rs);
}
}
Aggregations