Search in sources :

Example 1 with CUBRIDStatementProxy

use of com.cubrid.jdbc.proxy.driver.CUBRIDStatementProxy in project cubrid-manager by CUBRID.

the class QueryEditorPart method runQueryPlanOnly.

/**
	 * Fetch execution plans while running SQLs
	 *
	 * @param queries String
	 */
private void runQueryPlanOnly(Vector<String> qVector) {
    try {
        connection.getConnection(true);
    } catch (SQLException e) {
        CommonUITool.openErrorBox(e.getLocalizedMessage());
        return;
    }
    if (!connection.hasConnection()) {
        return;
    }
    // clearPlan();
    CUBRIDStatementProxy statement = null;
    int i = 0;
    try {
        int len = qVector.size();
        for (i = 0; i < len; i++) {
            String sql = qVector.get(i).toString();
            statement = getStatement(connection.getConnection(), false);
            StructQueryPlan sq = new StructQueryPlan(sql, statement.getQueryplan(sql), new Date());
            if (combinedQueryComposite.getQueryPlanResultComp().isDisposed()) {
                combinedQueryComposite.newQueryPlanComp();
            }
            combinedQueryComposite.getQueryPlanResultComp().makePlan(sq, i);
            QueryUtil.freeQuery(statement);
            statement = null;
            if (collectExecStats) {
                displayTuneModeResult(new TuneModeModel(sq, null));
            }
        }
    } catch (Exception ee) {
        int errorCode = 0;
        if (SQLException.class.isInstance(ee)) {
            errorCode = ((SQLException) ee).getErrorCode();
        }
        String errmsg = "";
        if (isAutocommit) {
            try {
                queryAction(QUERY_ACTION.ROLLBACK);
            } catch (SQLException e1) {
                LOGGER.error("", e1);
            }
        }
        SQLEditorComposite sqlEditorComp = combinedQueryComposite.getSqlEditorComp();
        sqlEditorComp.txtFind((String) qVector.get(i), 0, false, false, true, false);
        StyledText txaEdit = sqlEditorComp.getText();
        int line = txaEdit.getLineAtOffset(txaEdit.getSelection().x) + 1;
        String errorLineMsg = Messages.bind(Messages.errWhere, line);
        errmsg += Messages.runError + errorCode + StringUtil.NEWLINE + errorLineMsg + StringUtil.NEWLINE + Messages.errorHead + ee.getMessage();
        CTabFolder queryResultTabFolder = combinedQueryComposite.getQueryResultComp().getQueryResultTabFolder();
        StyledText logMessagesArea = combinedQueryComposite.getQueryResultComp().getLogMessagesArea();
        QueryResultComposite queryResult = combinedQueryComposite.getQueryResultComp();
        queryResultTabFolder.setSelection(0);
        String logMessage = logMessagesArea.getText();
        if (logMessage != null && logMessage.length() > 0) {
            logMessage += StringUtil.NEWLINE;
        }
        logMessagesArea.setText(logMessage + StringUtil.NEWLINE + errmsg);
        logMessagesArea.setTopIndex(logMessagesArea.getLineCount() - 1);
        queryResult.setSelection();
        LOGGER.error(ee.getMessage(), ee);
    } finally {
        QueryUtil.freeQuery(statement);
        statement = null;
    }
    autoCommitItem.setEnabled(true);
    queryPlanItem.setEnabled(true);
    setPstmtParaItem.setEnabled(true);
    isRunning = false;
}
Also used : TuneModeModel(com.cubrid.common.ui.query.control.tunemode.TuneModeModel) SQLEditorComposite(com.cubrid.common.ui.query.control.SQLEditorComposite) QueryResultComposite(com.cubrid.common.ui.query.control.QueryResultComposite) StyledText(org.eclipse.swt.custom.StyledText) CTabFolder(org.eclipse.swt.custom.CTabFolder) SQLException(java.sql.SQLException) CUBRIDStatementProxy(com.cubrid.jdbc.proxy.driver.CUBRIDStatementProxy) Point(org.eclipse.swt.graphics.Point) StructQueryPlan(com.cubrid.common.core.queryplan.StructQueryPlan) Date(java.util.Date) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 2 with CUBRIDStatementProxy

use of com.cubrid.jdbc.proxy.driver.CUBRIDStatementProxy in project cubrid-manager by CUBRID.

the class EditQueryPlanDialog method checkQuery.

/**
	 * check the query
	 * 
	 * @param queries String
	 * @return error message String
	 */
private String checkQuery(String queries) {
    if (queries.trim().length() == 0) {
        return Messages.errQueryplanStmtEmpty;
    }
    Vector<String> qVector = QueryUtil.queriesToQuery(queries);
    CUBRIDStatementProxy statement = null;
    Connection queryConn = null;
    try {
        queryConn = getConnection();
        statement = (CUBRIDStatementProxy) queryConn.createStatement();
        int len = qVector.size();
        for (int i = 0; i < len; i++) {
            String sql = qVector.get(i);
            statement.getQueryplan(sql);
        }
    } catch (SQLException e) {
        return e.getMessage();
    } finally {
        QueryUtil.freeQuery(queryConn, statement);
    }
    return null;
}
Also used : SQLException(java.sql.SQLException) CUBRIDStatementProxy(com.cubrid.jdbc.proxy.driver.CUBRIDStatementProxy) Connection(java.sql.Connection)

Aggregations

CUBRIDStatementProxy (com.cubrid.jdbc.proxy.driver.CUBRIDStatementProxy)2 SQLException (java.sql.SQLException)2 StructQueryPlan (com.cubrid.common.core.queryplan.StructQueryPlan)1 QueryResultComposite (com.cubrid.common.ui.query.control.QueryResultComposite)1 SQLEditorComposite (com.cubrid.common.ui.query.control.SQLEditorComposite)1 TuneModeModel (com.cubrid.common.ui.query.control.tunemode.TuneModeModel)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 Date (java.util.Date)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 StyledText (org.eclipse.swt.custom.StyledText)1 Point (org.eclipse.swt.graphics.Point)1 PartInitException (org.eclipse.ui.PartInitException)1