Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the Index's comment in DB Server since 10.0 #71

Merged
merged 8 commits into from May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -49,6 +49,7 @@ public class Constraint implements
private List<String> classAttributes = null; // String
private List<String> attributes = null; // String
private List<String> rules = null; // String
private String description;

private boolean newFlag;

Expand Down Expand Up @@ -624,4 +625,12 @@ public boolean isNewFlag() {
public void setNewFlag(boolean newFlag) {
this.newFlag = newFlag;
}

public void setDescription(String description) {
this.description = description;
}

public String getDescription() {
return description;
}
}
Expand Up @@ -40,6 +40,7 @@
import com.cubrid.common.core.common.model.DBAttribute;
import com.cubrid.common.core.common.model.IDatabaseSpec;
import com.cubrid.common.core.common.model.SchemaInfo;
import com.cubrid.common.core.schemacomment.model.CommentType;
import com.cubrid.common.core.schemacomment.model.SchemaComment;
import com.cubrid.common.core.util.CompatibleUtil;
import com.cubrid.common.core.util.ConstantsUtil;
Expand Down Expand Up @@ -285,6 +286,79 @@ public static Map<String, SchemaComment> loadDescription(IDatabaseSpec dbSpec,
return results;
}

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;
}

public static void updateDescription(IDatabaseSpec dbSpec, Connection conn,
String tableName, String columnName, String description) throws SQLException {

Expand Down
@@ -0,0 +1,21 @@
package com.cubrid.common.core.schemacomment.model;

public enum CommentType {
INDEX("INDEX"),
VIEW("VIEW"),
SP("SP"),
TRIGGER("TRIGGER"),
SERIAL("SERIAL"),
USER("USER"),
PARTITION("PARTITION");

final private String type;

private CommentType(String type) {
this.type = type;
}

public String getName() {
return type;
}
}
Expand Up @@ -31,17 +31,23 @@ public class SchemaComment { // FIXME add description
private String table;
private String column;
private String description;
private String objectName;
private CommentType type;

public String getId() {
if (table == null && column == null) {
if (table == null && column == null && type == null) {
return null;
}

if (column == null) {
return table + "*";
if (type == null) {
if (column == null) {
return table + "*";
} else {
return table + "*" + column;
}
}

return table + "*" + column;
return type.getName() + "*" + objectName;
}

public String getTable() {
Expand Down Expand Up @@ -75,4 +81,20 @@ public boolean isTable() {
public boolean isColumn() {
return table != null && column != null;
}

public String getObjectName() {
return objectName;
}

public void setObjectName(String objectName) {
this.objectName = objectName;
}

public void setType(CommentType type) {
this.type = type;
}

public CommentType getType() {
return type;
}
}
Expand Up @@ -139,6 +139,7 @@ public class Messages extends
public static String lblCurVal;
public static String lblIndexes;
public static String lblIndexName;
public static String lblIndexDescription;
public static String lblIndexType;
public static String lblOwner;
public static String lblCollation;
Expand Down Expand Up @@ -260,6 +261,7 @@ public class Messages extends
public static String tblColumnForeignTable;
public static String tblColumnIndexName;
public static String tblColumnIndexRule;
public static String tblColumnIndexMemo;
public static String tblColumnIndexType;
public static String tblColumnInherit;
public static String tblColumnInheritHint;
Expand Down
Expand Up @@ -268,6 +268,7 @@ tblColumnIndexName=Index Name
tblColumnIndexType=Index Type
tblColumnOnColumns=On Column(s)
tblColumnIndexRule=Index Rules
tblColumnIndexMemo=Index Memo
tblColumnType=Type
tblColumnSuperTable=Super table
tblColumnColumns=Columns
Expand All @@ -294,6 +295,7 @@ lblIncrement=In&crement:
lblCurVal=Current &value:
lblIndexType=Index &type:
lblIndexName=Index &name(optional):
lblIndexDescription=Index &memo(optional):
lblIndexes=Indexes:
lblSize=&Size:
lblOwner=Ow&ner:
Expand Down
Expand Up @@ -213,6 +213,7 @@ tblColumnIndexName=\u7d22\u5f15\u540d
tblColumnIndexType=\u7d22\u5f15\u30bf\u30a4\u30d7
tblColumnOnColumns=\u5217\u3067(s)
tblColumnIndexRule=\u7d22\u5f15\u30eb\u30fc\u30eb
tblColumnIndexMemo=\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30e1\u30e2
tblColumnType=\u30bf\u30a4\u30d7
tblColumnSuperTable=\u30b9\u30fc\u30d1\u30fc\u30c6\u30fc\u30d6\u30eb
tblColumnColumns=\u5217
Expand All @@ -235,6 +236,7 @@ lblIncrement=\u5897\u5206:
lblCurVal=\u73fe\u5728\u306e\u5024:
lblIndexType=\u7d22\u5f15\u30bf\u30a4\u30d7:
lblIndexName=\u7d22\u5f15\u540d(\u30aa\u30d7\u30b7\u30e7\u30f3):
lblIndexDescription=\u7d22\u5f15\u30e1\u30e2\uff08\u30aa\u30d7\u30b7\u30e7\u30f3\uff09:
lblIndexes=\u7d22\u5f15:
lblSize=\u30b5\u30a4\u30ba:
lblOwner=\u6240\u6709\u8005:
Expand Down
Expand Up @@ -197,6 +197,7 @@ tblColumnIndexName=\u1788\u17d2\u1798\u17c4\u17c7\u179b\u17b7\u1794\u17b7\u1780\
tblColumnIndexType=\u1794\u17d2\u179a\u1797\u17c1\u1791\u179b\u17b7\u1794\u17b7\u1780\u17d2\u179a\u1798
tblColumnOnColumns=\u179b\u17be\u1787\u17bd\u179a\u1788\u179a
tblColumnIndexRule=\u1785\u17d2\u1794\u17b6\u1794\u17cb\u179b\u17b7\u1794\u17b7\u1780\u17d2\u179a\u1798
tblColumnIndexMemo=\u17a2\u1793\u17bb\u179f\u179a\u178e\u17c8\u179f\u1793\u17d2\u1791\u179f\u17d2\u179f\u1793\u17cd
tblColumnType=\u1794\u17d2\u179a\u1797\u17c1\u1791
tblColumnSuperTable=\u178f\u17b6\u179a\u17b6\u1784\u1792\u17c6
tblColumnColumns=\u1787\u17bd\u179a\u1788\u179a
Expand All @@ -219,6 +220,7 @@ lblIncrement=\u1785\u17c6\u1793\u17bd\u1793\u1794\u1793\u17d2\u1790\u17c2\u1798(
lblCurVal=\u178f\u1798\u17d2\u179b\u17c3\u1785\u179a\u1793\u17d2\u178f(&v):
lblIndexType=\u1794\u17d2\u179a\u1797\u17c1\u1791\u179b\u17b7\u1794\u17b7\u1780\u17d2\u179a\u1798(&t):
lblIndexName=\u1788\u17d2\u1798\u17c4\u17c7\u179b\u17b7\u1794\u17b7\u1780\u17d2\u179a\u1798(\u178a\u17c2\u179b\u1787\u17d2\u179a\u17be\u179f)(&n):
lblIndexDescription=\u17a2\u1793\u17bb\u179f\u17d2\u179f\u179a\u178e\u17c8\u179f\u1793\u17d2\u1791\u179f\u17d2\u179f\u1793\u17cd(\u179f\u17d2\u179a\u17c1\u1785\u1785\u17b7\u178f\u17d2\u178f)(&d):
lblIndexes=\u179b\u17b7\u1794\u17b7\u1780\u17d2\u179a\u1798\u1793\u17b6\u1793\u17b6:
lblSize=\u1781\u17d2\u1793\u17b6\u178f(&S):
lblOwner=\u1798\u17d2\u1785\u17b6\u179f\u17cb&n):
Expand Down