use of com.cubrid.cubridmanager.core.cubrid.table.model.TableIndex in project cubrid-manager by CUBRID.
the class GetUserClassIndexesTaskTest method testGetIndexesNames.
/**
* Test method for
* {@link com.cubrid.cubridmanager.core.cubrid.table.task.GetUserClassIndexesTask#getIndexesNames(java.lang.String)}
* .
*/
public void testGetIndexesNames() {
GetUserClassIndexesTask task = new GetUserClassIndexesTask(databaseInfo);
List<TableIndex> indexes = task.getIndexesNames(testTableName);
String actualIndexName = "";
for (TableIndex dbIndex : indexes) {
if (dbIndex.getIndexName() != null) {
if (!dbIndex.getIndexName().startsWith("pk")) {
actualIndexName = dbIndex.getIndexName();
}
}
}
assertEquals(indexName, actualIndexName);
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.TableIndex in project cubrid-manager by CUBRID.
the class GetUserClassIndexesTask method getIndexesNames.
/**
*Get all column name and type info into list
*
* @param tableName String the table name
* @return List<String[]>
*/
public List<TableIndex> getIndexesNames(String tableName) {
List<TableIndex> indexes = new ArrayList<TableIndex>();
try {
if (errorMsg != null && errorMsg.trim().length() > 0) {
return indexes;
}
if (connection == null || connection.isClosed()) {
errorMsg = Messages.error_getConnection;
return indexes;
}
String sql = "SELECT * FROM db_index WHERE class_name=?";
// [TOOLS-2425]Support shard broker
sql = databaseInfo.wrapShardQuery(sql);
stmt = connection.prepareStatement(sql);
((PreparedStatement) stmt).setString(1, tableName.toLowerCase(Locale.getDefault()));
rs = ((PreparedStatement) stmt).executeQuery();
while (rs.next()) {
String indexName = rs.getString("index_name");
String pk = rs.getString("is_primary_key");
String fk = rs.getString("is_foreign_key");
String unique = rs.getString("is_unique");
String reverse = rs.getString("is_reverse");
TableIndex dbIndex = new TableIndex();
dbIndex.setIndexName(indexName);
dbIndex.setPrimaryKey(pk);
dbIndex.setForeignKey(fk);
dbIndex.setUnique(unique);
dbIndex.setReverse(reverse);
indexes.add(dbIndex);
}
QueryUtil.freeQuery(stmt, rs);
sql = "SELECT key_attr_name FROM db_index_key" + " WHERE index_name=? AND class_name=?";
// [TOOLS-2425]Support shard broker
sql = databaseInfo.wrapShardQuery(sql);
stmt = connection.prepareStatement(sql);
for (TableIndex dbIndex : indexes) {
String indexName = dbIndex.getIndexName();
((PreparedStatement) stmt).setString(1, indexName.toLowerCase(Locale.getDefault()));
((PreparedStatement) stmt).setString(2, tableName.toLowerCase(Locale.getDefault()));
rs = ((PreparedStatement) stmt).executeQuery();
List<String> columns = new ArrayList<String>();
while (rs.next()) {
columns.add(rs.getString("key_attr_name"));
}
dbIndex.setColumns(columns);
}
} catch (SQLException e) {
errorMsg = e.getMessage();
} finally {
finish();
}
return indexes;
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.TableIndex in project cubrid-manager by CUBRID.
the class CubridUserTableIndexLoader method load.
/**
*
* Load children object for parent
*
* @param parent the parent node
* @param monitor the IProgressMonitor object
*/
public void load(ICubridNode parent, final IProgressMonitor monitor) {
synchronized (this) {
if (isLoaded()) {
return;
}
CubridDatabase database = ((ISchemaNode) parent).getDatabase();
if (!database.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
parent.removeAllChild();
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
return;
}
DatabaseInfo databaseInfo = database.getDatabaseInfo();
final GetUserClassIndexesTask task = new GetUserClassIndexesTask(databaseInfo);
monitorCancel(monitor, new ITask[] { task });
String tableName = parent.getParent().getLabel();
List<TableIndex> indexes = task.getIndexesNames(tableName);
final String errorMsg = task.getErrorMsg();
if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
parent.removeAllChild();
Display display = Display.getDefault();
display.syncExec(new Runnable() {
public void run() {
CommonUITool.openErrorBox(errorMsg);
}
});
setLoaded(true);
return;
}
if (monitor.isCanceled()) {
setLoaded(true);
return;
}
parent.removeAllChild();
String parentId = parent.getId();
if (indexes != null && !indexes.isEmpty()) {
for (TableIndex index : indexes) {
String indexName = index.getIndexName();
String nodeId = parentId + NODE_SEPARATOR + indexName;
String label = indexName;
List<String> dependColumns = index.getColumns();
if (dependColumns != null && !dependColumns.isEmpty()) {
String keyAttrName = index.getColumns().toString();
label += keyAttrName.replace('[', '(').replace(']', ')');
}
ICubridNode node = new DefaultSchemaNode(nodeId, label, "icons/navigator/table_index_item.png");
if (index.isPrimaryKey()) {
node.setIconPath("icons/primary_key.png");
}
node.setType(NodeType.TABLE_INDEX);
node.setModelObj(index);
node.setContainer(false);
parent.addChild(node);
}
}
Collections.sort(parent.getChildren());
setLoaded(true);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
}
}
Aggregations