Search in sources :

Example 6 with CUBRIDConnectionProxy

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;
}
Also used : CUBRIDResultSetProxy(com.cubrid.jdbc.proxy.driver.CUBRIDResultSetProxy) CUBRIDOIDProxy(com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy) TreeItem(org.eclipse.swt.widgets.TreeItem) SQLException(java.sql.SQLException) CUBRIDConnectionProxy(com.cubrid.jdbc.proxy.driver.CUBRIDConnectionProxy) SQLException(java.sql.SQLException) ResultSetMetaData(java.sql.ResultSetMetaData)

Example 7 with CUBRIDConnectionProxy

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;
            }
        }
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) SQLException(java.sql.SQLException) IsDBAUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask) CUBRIDConnectionProxy(com.cubrid.jdbc.proxy.driver.CUBRIDConnectionProxy) SQLException(java.sql.SQLException) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

CUBRIDConnectionProxy (com.cubrid.jdbc.proxy.driver.CUBRIDConnectionProxy)7 SQLException (java.sql.SQLException)6 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)2 IsDBAUserTask (com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask)2 CUBRIDOIDProxy (com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Writer (java.io.Writer)2 PartInitException (org.eclipse.ui.PartInitException)2 ColumnInfo (com.cubrid.common.ui.query.control.ColumnInfo)1 FormatDataResult (com.cubrid.cubridmanager.core.cubrid.table.model.FormatDataResult)1 CUBRIDBlobProxy (com.cubrid.jdbc.proxy.driver.CUBRIDBlobProxy)1 CUBRIDClobProxy (com.cubrid.jdbc.proxy.driver.CUBRIDClobProxy)1 CUBRIDResultSetProxy (com.cubrid.jdbc.proxy.driver.CUBRIDResultSetProxy)1 CUBRIDProxyException (com.cubrid.jdbc.proxy.manage.CUBRIDProxyException)1 BufferedOutputStream (java.io.BufferedOutputStream)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1