Search in sources :

Example 1 with QueryResultComposite

use of com.cubrid.common.ui.query.control.QueryResultComposite 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 QueryResultComposite

use of com.cubrid.common.ui.query.control.QueryResultComposite in project cubrid-manager by CUBRID.

the class QueryEditorPart method refreshQueryOptions.

//	/**
//	 * Set query connection
//	 *
//	 * @param queryConn Connection
//	 */
//	public void setQueryConn(Connection queryConn) {
//		this.queryConn = queryConn;
//	}
/**
	 * When query options change or database and server refresh, refresh this
	 * query style
	 */
public void refreshQueryOptions() {
    CubridDatabase database = getSelectedDatabase();
    boolean enabled = (database != DatabaseNavigatorMenu.NULL_DATABASE);
    if (enabled && !connection.hasConnection()) {
        this.initConnection(database);
    }
    enabled = enabled && connection.hasConnection();
    if (enabled) {
        for (CombinedQueryEditorComposite combinedQueryEditorComposite : getAllCombinedQueryEditorComposite()) {
            combinedQueryEditorComposite.getMultiDBQueryComp().setMainDatabase(database);
        }
    }
    queryPlanItem.setEnabled(enabled);
    setPstmtParaItem.setEnabled(enabled);
    ServerInfo serverInfo = getSelectedServer() == null ? null : getSelectedServer().getServerInfo();
    String fontString = QueryOptions.getFontString(serverInfo);
    Font font = ResourceManager.getFont(fontString);
    if (font == null) {
        String[] fontData = QueryOptions.getDefaultFont();
        font = ResourceManager.getFont(fontData[0], Integer.valueOf(fontData[1]), Integer.valueOf(fontData[2]));
    }
    int[] fontColor = QueryOptions.getFontColor(serverInfo);
    final Color color = ResourceManager.getColor(fontColor[0], fontColor[1], fontColor[2]);
    // Change SQL editor font
    if (font != null) {
        getSqlTextEditor().setFont(font);
    }
    getSqlTextEditor().setForeground(color);
    for (CombinedQueryEditorComposite combinedQueryEditorComposite : getAllCombinedQueryEditorComposite()) {
        combinedQueryEditorComposite.getSqlEditorComp().getTextViewer().refresh();
        // Change the table result font
        QueryResultComposite queryResultComp = combinedQueryComposite.getQueryResultComp();
        if (queryResultComp == null || queryResultComp.isDisposed()) {
            return;
        }
        Table resultTable = queryResultComp.getResultTable();
        if (resultTable != null && !resultTable.isDisposed()) {
            resultTable.setFont(font);
            resultTable.setForeground(color);
        }
        // Update editor config
        if (database != null) {
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, isCMMode);
            if (editorConfig != null && editorConfig.getBackGround() != null) {
                setEditorBackground(ResourceManager.getColor(editorConfig.getBackGround()));
            } else {
                setEditorBackground(ResourceManager.getColor(EditorConstance.getDefaultBackground()));
            }
        }
        //query plan
        combinedQueryComposite.getQueryPlanResultComp().fillPlanHistory();
        //sql history
        combinedQueryComposite.getRecentlyUsedSQLComposite().fillRecentlyUsedSQLList();
        /*Fire database changed*/
        combinedQueryComposite.fireDatabaseChanged(database);
    }
}
Also used : QueryResultComposite(com.cubrid.common.ui.query.control.QueryResultComposite) Table(org.eclipse.swt.widgets.Table) CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) Color(org.eclipse.swt.graphics.Color) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig) Font(org.eclipse.swt.graphics.Font)

Aggregations

QueryResultComposite (com.cubrid.common.ui.query.control.QueryResultComposite)2 StructQueryPlan (com.cubrid.common.core.queryplan.StructQueryPlan)1 CombinedQueryEditorComposite (com.cubrid.common.ui.query.control.CombinedQueryEditorComposite)1 SQLEditorComposite (com.cubrid.common.ui.query.control.SQLEditorComposite)1 TuneModeModel (com.cubrid.common.ui.query.control.tunemode.TuneModeModel)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 CUBRIDStatementProxy (com.cubrid.jdbc.proxy.driver.CUBRIDStatementProxy)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 StyledText (org.eclipse.swt.custom.StyledText)1 Color (org.eclipse.swt.graphics.Color)1 Font (org.eclipse.swt.graphics.Font)1 Point (org.eclipse.swt.graphics.Point)1 Table (org.eclipse.swt.widgets.Table)1 PartInitException (org.eclipse.ui.PartInitException)1