use of com.cubrid.jdbc.proxy.driver.CUBRIDConnectionProxy in project cubrid-manager by CUBRID.
the class OIDNavigatorDialog method searchOID.
/**
*
* Get tree constructor by the result of execute oid
*
* @param strOid the oid string
* @param parent the parent treeitem
* @return <code>true</code> if found;<code>false</code> otherwise
*/
private boolean searchOID(String strOid, TreeItem parent) {
CUBRIDOIDProxy oid = null;
String tblName = null;
String[] columnName;
String[] typeName;
String[] value;
String[] oidSet = null;
boolean[] isOid = null;
int cntColumn = 0;
try {
oid = CUBRIDOIDProxy.getNewInstance((CUBRIDConnectionProxy) conn, strOid);
if (oid == null) {
return false;
}
tblName = oid.getTableName();
} catch (Exception e) {
CommonUITool.openErrorBox(getShell(), Messages.errOIDValue2);
return false;
}
if (tblName == null) {
CommonUITool.openErrorBox(getShell(), Messages.errOIDValue2);
return false;
}
parent.setText(strOid);
TreeItem item = new TreeItem(parent, SWT.NONE);
item.setText("table name: " + tblName);
String sql = "SELECT * FROM " + QuerySyntax.escapeKeyword(tblName) + " WHERE ROWNUM = 1";
stmt = null;
CUBRIDResultSetProxy rs = null;
try {
stmt = conn.createStatement();
rs = (CUBRIDResultSetProxy) stmt.executeQuery(sql);
ResultSetMetaData rsmt = rs.getMetaData();
cntColumn = rsmt.getColumnCount();
columnName = new String[cntColumn];
typeName = new String[cntColumn];
value = new String[cntColumn];
for (int i = 0; i < cntColumn; i++) {
columnName[i] = rsmt.getColumnName(i + 1);
typeName[i] = rsmt.getColumnTypeName(i + 1);
}
rs.close();
rs = (CUBRIDResultSetProxy) oid.getValues(columnName);
while (rs.next()) {
for (int i = 0; i < columnName.length; i++) {
if (rs.getObject(columnName[i]) == null) {
value[i] = "NULL";
} else {
if ("SET".equals(typeName[i]) || "MULTISET".equals(typeName[i]) || "SEQUENCE".equals(typeName[i])) {
Object[] set = (Object[]) rs.getCollection(columnName[i]);
oidSet = new String[set.length];
isOid = new boolean[set.length];
value[i] = "{";
if (set.length > 0) {
for (int j = 0; j < set.length; j++) {
if (set[j].getClass() == oid.getCUBRIDOIDClass()) {
value[i] += (new CUBRIDOIDProxy(set[j])).getOidString();
oidSet[j] = (new CUBRIDOIDProxy(set[j])).getOidString();
isOid[j] = true;
} else {
value[i] += set[j];
oidSet[j] = null;
isOid[j] = false;
}
if (i < set.length - 1) {
value[i] += ", ";
}
}
}
value[i] += "}";
} else {
value[i] = rs.getString(columnName[i]);
}
}
}
}
rs.close();
for (int i = 0; i < value.length; i++) {
if ("CLASS".equals(typeName[i]) && !"NULL".equals(value[i])) {
item = new TreeItem(parent, SWT.NONE);
item.setText(columnName[i] + ": " + value[i]);
TreeItem treeItem = new TreeItem(item, SWT.NONE);
treeItem.setText(value[i]);
treeItem.setData(OID_ITEM_FLAG, value[i]);
TreeItem dumyItem = new TreeItem(treeItem, SWT.NONE);
dumyItem.setData(DUMY_ITEM_FLAG, DUMY_ITEM_FLAG);
} else if ("SET".equals(typeName[i]) || "MULTISET".equals(typeName[i]) || "SEQUENCE".equals(typeName[i])) {
item = new TreeItem(parent, SWT.NONE);
item.setText(columnName[i] + ": " + value[i]);
if (isOid != null) {
for (int j = 0; j < oidSet.length; j++) {
if (isOid[j]) {
TreeItem treeItem = new TreeItem(item, SWT.NONE);
treeItem.setData(OID_ITEM_FLAG, oidSet[j]);
treeItem.setText(oidSet[j]);
TreeItem dumyItem = new TreeItem(treeItem, SWT.NONE);
dumyItem.setData(DUMY_ITEM_FLAG, DUMY_ITEM_FLAG);
}
}
}
} else {
(new TreeItem(parent, SWT.NONE)).setText(columnName[i] + ": " + value[i]);
}
}
} catch (SQLException e) {
CommonUITool.openErrorBox(getShell(), Messages.bind(com.cubrid.common.ui.common.Messages.errCommonTip, e.getErrorCode(), e.getMessage()));
LOGGER.error("", e);
return false;
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
} catch (SQLException e) {
LOGGER.error(e.getMessage(), e);
}
}
return true;
}
use of com.cubrid.jdbc.proxy.driver.CUBRIDConnectionProxy in project cubrid-manager by CUBRID.
the class CubridWorkbenchContrItem method connectDatabase.
/**
*
* Connect the database
*
* @param dbInfo DatabaseInfo
* @return boolean
*/
public static boolean connectDatabase(DatabaseInfo dbInfo) {
// FIXME extract
if (dbInfo == null || dbInfo.getServerInfo() == null) {
return false;
}
Map<String, String> jdbcVersionMap = CubridJdbcManager.getInstance().getLoadedJdbc();
if (jdbcVersionMap == null || jdbcVersionMap.get(dbInfo.getServerInfo().getJdbcDriverVersion()) == null) {
return false;
}
CUBRIDConnectionProxy connection = null;
try {
connection = (CUBRIDConnectionProxy) JDBCConnectionManager.getConnection(dbInfo, false);
DbUserInfo userInfo = dbInfo.getAuthLoginedDbUserInfo();
IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
checkTask.execute();
userInfo.setDbaAuthority(checkTask.isDBAUser());
dbInfo.setLogined(true);
dbInfo.setRunningType(DbRunningType.CS);
dbInfo.getServerInfo().setConnected(true);
dbInfo.setLogined(true);
return true;
} catch (SQLException e) {
CommonUITool.openErrorBox(Messages.bind(Messages.errCommonTip, e.getErrorCode(), e.getMessage()));
return false;
} catch (Exception e) {
CommonUITool.openErrorBox(e.getMessage());
return false;
} finally {
if (connection != null) {
try {
connection.close();
connection = null;
} catch (SQLException e) {
connection = null;
}
}
}
}
Aggregations