Search in sources :

Example 1 with TuneModeModel

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

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

the class QueryExecuter method makeTable.

/**
	 * make query editor result table
	 *
	 * @param start int
	 * @throws SQLException if failed
	 */
public TuneModeModel makeTable(int start, boolean useTuneMode) throws SQLException {
    int end = start + recordLimit - 1;
    String sql = multiQuerySql;
    if (multiQuerySql.indexOf(SqlParser.ROWNUM_CONDITION_MARK) != -1) {
        if (dontTipNext) {
            if (recordLimit > 0) {
                sql = this.multiQuerySql.replace(SqlParser.ROWNUM_CONDITION_MARK, "\r\nWHERE ROWNUM  >= " + String.valueOf(start));
            }
        } else {
            sql = this.multiQuerySql.replace(SqlParser.ROWNUM_CONDITION_MARK, "\r\nWHERE ROWNUM BETWEEN " + String.valueOf(start) + " AND " + String.valueOf(end));
        }
    }
    TuneModeModel tuneModeModel = null;
    long beginTimestamp = 0;
    long endTimestamp = 0;
    double elapsedTime = 0.0;
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(3);
    stmt = null;
    rs = null;
    boolean isHasError = false;
    try {
        beginTimestamp = System.currentTimeMillis();
        stmt = getStatement(connection.checkAndConnectQuietly(), sql, false, false);
        stmt.setQueryInfo(false);
        stmt.setOnlyQueryPlan(false);
        // begin tune mode
        if (queryEditor.isCollectExecStats()) {
            queryEditor.beginCollectExecStats();
        }
        if (columnTableNames == null || columnTableNames.size() == 0) {
            columnTableNames = UIQueryUtil.loadColumnTableNameList(stmt);
        }
        stmt.executeQuery();
        String queryPlan = null;
        rs = (CUBRIDResultSetProxy) stmt.getResultSet();
        endTimestamp = System.currentTimeMillis();
        elapsedTime = (endTimestamp - beginTimestamp) * 0.001;
        String elapsedTimeStr = new String(nf.format(elapsedTime));
        if (start == 1) {
            makeResult(rs);
        } else {
            fillTableItemData(rs);
        }
        // collect statistics and query plan on tune mode
        if (useTuneMode && queryEditor.isCollectExecStats()) {
            Map<String, String> stat = CubridUtil.fetchStatistics(connection.checkAndConnectQuietly());
            StructQueryPlan sq = new StructQueryPlan(sql, stmt.getQueryplan(sql), new Date());
            queryPlan = sq.getPlanRaw();
            tuneModeModel = new TuneModeModel(sq, stat);
        }
        queryMsg += "[ " + elapsedTimeStr + " " + Messages.second + " , " + Messages.totalRows + " : " + cntRecord + " ]" + StringUtil.NEWLINE;
        if (useTuneMode && queryEditor.isCollectExecStats() && queryPlan != null) {
            this.queryPlanLog = queryPlan;
        }
        query += sql + StringUtil.NEWLINE;
        recordSQLDetail(elapsedTimeStr.toString(), queryMsg);
    } catch (SQLException event) {
        queryMsg += Messages.runError + event.getErrorCode() + StringUtil.NEWLINE + Messages.errorHead + event.getMessage() + StringUtil.NEWLINE;
        query += sql + StringUtil.NEWLINE;
        isHasError = true;
        LOGGER.error("execute SQL failed sql at query editor: " + query + " error message: " + event.getMessage(), event);
        throw event;
    } finally {
        queryInfo = new QueryInfo(allDataList == null ? 0 : allDataList.size(), pageLimit);
        queryInfo.setCurrentPage(1);
        QueryUtil.freeQuery(stmt, rs);
        stmt = null;
        rs = null;
        if (!isHasError && cntRecord == recordLimit && recordLimit > 0) {
            isEnd = false;
            final String msg = Messages.bind(Messages.tooManyRecord, end);
            showQueryTip(msg);
            if (!isEnd) {
                makeTable(end + 1, false);
            }
        }
    }
    return tuneModeModel;
}
Also used : TuneModeModel(com.cubrid.common.ui.query.control.tunemode.TuneModeModel) SQLException(java.sql.SQLException) Point(org.eclipse.swt.graphics.Point) StructQueryPlan(com.cubrid.common.core.queryplan.StructQueryPlan) Date(java.util.Date) NumberFormat(java.text.NumberFormat)

Example 3 with TuneModeModel

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

the class QueryPlanCompositeWithHistory method createPlanToolbar.

private void createPlanToolbar() {
    Composite toolBarComposite = new Composite(this, SWT.NONE);
    GridLayout gridLayout = new GridLayout(2, false);
    gridLayout.verticalSpacing = 0;
    gridLayout.horizontalSpacing = 10;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    toolBarComposite.setLayout(gridLayout);
    toolBarComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));
    ToolBar toolBar = new ToolBar(toolBarComposite, SWT.FLAT | SWT.RIGHT);
    dispModeTextItem = new ToolItem(toolBar, SWT.CHECK);
    dispModeTextItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_mode_raw.png"));
    dispModeTextItem.setToolTipText(Messages.tooltip_qedit_explain_display_mode + "(F11)");
    dispModeTextItem.setText(Messages.lblPlanRawBtn);
    dispModeTextItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            showSelectedPlan(PLAN_DISPLAY_MODE.TEXT.getInt());
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    dispModeTreeItem = new ToolItem(toolBar, SWT.CHECK);
    dispModeTreeItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_mode_tree.png"));
    dispModeTreeItem.setToolTipText(Messages.tooltip_qedit_explain_display_mode + "(F11)");
    dispModeTreeItem.setText(Messages.lblPlanTreeBtn);
    dispModeTreeItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            showSelectedPlan(PLAN_DISPLAY_MODE.TREE.getInt());
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    dispModeGraphItem = new ToolItem(toolBar, SWT.CHECK);
    dispModeGraphItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_mode_graph.png"));
    dispModeGraphItem.setToolTipText(Messages.tooltip_qedit_explain_display_mode + "(F11)");
    dispModeGraphItem.setText(Messages.lblPlanGraph);
    dispModeGraphItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            showSelectedPlan(PLAN_DISPLAY_MODE.GRAPH.getInt());
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    editTableItem = new ToolItem(toolBar, SWT.None);
    editTableItem.setImage(CommonUIPlugin.getImage("icons/navigator/schema_table_item.png"));
    editTableItem.setText(Messages.lblPlanEditTable);
    editTableItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            QueryPlanComposite comp = getSelectedQueryPlanComposite();
            String tableName = comp.getSelectedTable();
            if (StringUtil.isEmpty(tableName)) {
                CommonUITool.openErrorBox(Messages.msgPlanEditTable);
                return;
            }
            ISchemaNode node = new DefaultSchemaNode(tableName, tableName, null);
            node.setDatabase(editor.getSelectedDatabase());
            EditTableAction action = (EditTableAction) ActionManager.getInstance().getAction(EditTableAction.ID);
            if (action == null) {
                CommonUITool.openErrorBox(Messages.errPlanEditNoAction);
                return;
            }
            action.run((ISchemaNode) node);
        }
    });
    editIndexItem = new ToolItem(toolBar, SWT.None);
    editIndexItem.setImage(CommonUIPlugin.getImage("icons/navigator/table_index_item.png"));
    editIndexItem.setText(Messages.lblPlanEditIndex);
    editIndexItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            QueryPlanComposite comp = getSelectedQueryPlanComposite();
            String tableName = comp.getSelectedTable();
            //				String indexName = comp.getSelectedIndex();
            if (StringUtil.isEmpty(tableName)) {
                CommonUITool.openErrorBox(Messages.msgPlanEditIndex);
                return;
            }
            ISchemaNode node = new DefaultSchemaNode(tableName, tableName, null);
            node.setDatabase(editor.getSelectedDatabase());
            EditTableAction action = (EditTableAction) ActionManager.getInstance().getAction(EditTableAction.ID);
            if (action == null) {
                CommonUITool.openErrorBox(Messages.errPlanEditNoAction);
                return;
            }
            action.editIndexMode((ISchemaNode) node);
        }
    });
    ToolItem comparePlanItem = new ToolItem(toolBar, SWT.None);
    comparePlanItem.setImage(CommonUIPlugin.getImage("icons/queryplan/use_compare_queryplan.png"));
    comparePlanItem.setText(Messages.lblComparePlan);
    comparePlanItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            QueryPlanComposite comp = getSelectedQueryPlanComposite();
            StructQueryPlan sq = comp.getQueryPlan();
            TuneModeModel tuneModeModel = new TuneModeModel(sq, null);
            editor.displayTuneModeResult(tuneModeModel);
        }
    });
    ToolBar delHistoryToolBar = new ToolBar(toolBarComposite, SWT.FLAT);
    delHistoryToolBar.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, true));
    // Show/hide of the history pane
    historyShowHideItem = new ToolItem(delHistoryToolBar, SWT.PUSH);
    historyShowHideItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_history_hide.png"));
    historyShowHideItem.setToolTipText(Messages.tooltip_qedit_explain_history_show_hide);
    historyShowHideItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            boolean isShow = !planHistoryTable.getVisible();
            if (isShow) {
                showHistoryPane();
            } else {
                hideHistoryPane();
            }
        }
    });
    new ToolItem(delHistoryToolBar, SWT.SEPARATOR);
    // Collecting histories switch
    historySwitchItem = new ToolItem(delHistoryToolBar, SWT.CHECK);
    historySwitchItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_history_switch.png"));
    historySwitchItem.setToolTipText(Messages.tooltip_qedit_explain_history_switch);
    historySwitchItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            collectToHistoryFlag = !historySwitchItem.getSelection();
        }
    });
    historySwitchItem.setSelection(true);
    new ToolItem(delHistoryToolBar, SWT.SEPARATOR);
    delHistory = new ToolItem(delHistoryToolBar, SWT.PUSH);
    delHistory.setImage(CommonUIPlugin.getImage("icons/action/table_record_delete.png"));
    delHistory.setDisabledImage(CommonUIPlugin.getImage("icons/action/table_record_delete_disabled.png"));
    delHistory.setToolTipText(Messages.tooltip_qedit_explain_history_delete);
    delHistory.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (planHistoryTable.getSelectionIndices().length == 0) {
                MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.error, Messages.explain_history_delete_error);
                return;
            }
            deleteHistory();
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) QueryPlanComposite(com.cubrid.common.ui.query.control.queryplan.QueryPlanComposite) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) EditTableAction(com.cubrid.common.ui.cubrid.table.action.EditTableAction) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) QueryPlanComposite(com.cubrid.common.ui.query.control.queryplan.QueryPlanComposite) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) TuneModeModel(com.cubrid.common.ui.query.control.tunemode.TuneModeModel) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem) StructQueryPlan(com.cubrid.common.core.queryplan.StructQueryPlan)

Aggregations

StructQueryPlan (com.cubrid.common.core.queryplan.StructQueryPlan)3 TuneModeModel (com.cubrid.common.ui.query.control.tunemode.TuneModeModel)3 SQLException (java.sql.SQLException)2 Date (java.util.Date)2 Point (org.eclipse.swt.graphics.Point)2 EditTableAction (com.cubrid.common.ui.cubrid.table.action.EditTableAction)1 QueryResultComposite (com.cubrid.common.ui.query.control.QueryResultComposite)1 SQLEditorComposite (com.cubrid.common.ui.query.control.SQLEditorComposite)1 QueryPlanComposite (com.cubrid.common.ui.query.control.queryplan.QueryPlanComposite)1 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)1 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)1 CUBRIDStatementProxy (com.cubrid.jdbc.proxy.driver.CUBRIDStatementProxy)1 IOException (java.io.IOException)1 NumberFormat (java.text.NumberFormat)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 StyledText (org.eclipse.swt.custom.StyledText)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1