Search in sources :

Example 6 with StructQueryPlan

use of com.cubrid.common.core.queryplan.StructQueryPlan in project cubrid-manager by CUBRID.

the class ApplicationPersistUtil method loadQueryRecord.

/**
	 * Load query record
	 *
	 * @param element
	 * @return
	 */
private QueryRecord loadQueryRecord(IXMLMemento element) {
    DateFormat formater = DateUtil.getDateFormat(DATE_PATTERN, Locale.ENGLISH);
    QueryRecord queryRecord = null;
    String name = element.getString("name");
    String dateStr = element.getString("create_date");
    long startTime = StringUtil.intValue(element.getString("start_time"), -1);
    long stopTime = StringUtil.intValue(element.getString("stop_time"), -1);
    String query = element.getString("query");
    StructQueryPlan queryPlan = null;
    IXMLMemento[] planArray = element.getChildren("query_plan");
    if (planArray != null && planArray.length > 0) {
        queryPlan = loadQueryPlan(planArray[0]);
    }
    LinkedHashMap<String, String> statistics = null;
    IXMLMemento[] statisticsArray = element.getChildren("statistics");
    if (statisticsArray != null && statisticsArray.length > 0) {
        statistics = loadPlanStatistics(statisticsArray[0]);
    }
    Date createDate = null;
    try {
        createDate = formater.parse(dateStr);
    } catch (ParseException e) {
        createDate = new Date();
    }
    queryRecord = new QueryRecord(query, startTime, stopTime, createDate);
    queryRecord.setName(name);
    queryRecord.setQueryPlan(queryPlan);
    queryRecord.setStatistics(statistics);
    return queryRecord;
}
Also used : IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) DateFormat(java.text.DateFormat) QueryRecord(com.cubrid.common.ui.query.tuner.QueryRecord) ParseException(java.text.ParseException) StructQueryPlan(com.cubrid.common.core.queryplan.StructQueryPlan) Date(java.util.Date)

Example 7 with StructQueryPlan

use of com.cubrid.common.core.queryplan.StructQueryPlan in project cubrid-manager by CUBRID.

the class ApplicationPersistUtil method saveToXmlFile.

private void saveToXmlFile(IXMLMemento parent) {
    if (editorStatusList == null) {
        return;
    }
    DateFormat formater = DateUtil.getDateFormat(DATE_PATTERN, Locale.ENGLISH);
    for (List<RestorableQueryEditorInfo> statusList : editorStatusList) {
        IXMLMemento memento = parent.createChild("editor_status");
        for (RestorableQueryEditorInfo status : statusList) {
            IXMLMemento tabItem = memento.createChild("sql_tabItem");
            tabItem.putString("content", status.getQueryContents());
            tabItem.putString("create_time", formater.format(status.getCreatedTime()));
            tabItem.putString("database", status.getDatabaseName() == null ? "" : status.getDatabaseName());
            tabItem.putString("server", status.getServerName() == null ? "" : status.getServerName());
        }
    }
    IXMLMemento queryListDataMemento = parent.createChild("query_record_list_data");
    for (Entry<String, List<QueryRecordProject>> entry : queryRecordMap.entrySet()) {
        String key = entry.getKey();
        List<QueryRecordProject> list = entry.getValue();
        for (QueryRecordProject queryRecordList : list) {
            IXMLMemento queryListMemento = queryListDataMemento.createChild("query_redord_list");
            String createDate = formater.format(queryRecordList.getCreateDate());
            queryListMemento.putString("database_key", key);
            queryListMemento.putString("create_date", createDate);
            queryListMemento.putString("name", queryRecordList.getName());
            for (QueryRecord queryRecord : queryRecordList.getQueryRecordList()) {
                IXMLMemento queryRecordMemento = queryListMemento.createChild("query_record");
                queryRecordMemento.putString("name", queryRecord.getName());
                queryRecordMemento.putString("create_date", formater.format(queryRecord.getCreateDate()));
                queryRecordMemento.putString("start_time", String.valueOf(queryRecord.getStartTime()));
                queryRecordMemento.putString("stop_time", String.valueOf(queryRecord.getStopTime()));
                queryRecordMemento.putString("query", queryRecord.getQuery());
                if (queryRecord.getQueryPlan() != null) {
                    StructQueryPlan queryPlan = queryRecord.getQueryPlan();
                    IXMLMemento queryPlanMemento = queryRecordMemento.createChild("query_plan");
                    queryPlanMemento.putString("query", queryPlan.getSql());
                    queryPlanMemento.putString("plan", queryPlan.getPlanRaw());
                    queryPlanMemento.putString("create_date", formater.format(queryPlan.getCreated()));
                }
                if (queryRecord.getStatistics() != null) {
                    IXMLMemento statisticsMemento = queryRecordMemento.createChild("statistics");
                    for (Entry<String, String> prop : queryRecord.getStatistics().entrySet()) {
                        statisticsMemento.putString(prop.getKey(), prop.getValue());
                    }
                }
            }
        }
    }
}
Also used : QueryRecordProject(com.cubrid.common.ui.query.tuner.QueryRecordProject) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) DateFormat(java.text.DateFormat) QueryRecord(com.cubrid.common.ui.query.tuner.QueryRecord) ArrayList(java.util.ArrayList) List(java.util.List) RestorableQueryEditorInfo(com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo) StructQueryPlan(com.cubrid.common.core.queryplan.StructQueryPlan)

Example 8 with StructQueryPlan

use of com.cubrid.common.core.queryplan.StructQueryPlan in project cubrid-manager by CUBRID.

the class ApplicationPersistUtil method loadQueryPlan.

/**
	 * Load query plan
	 *
	 * @param element
	 * @return
	 */
private StructQueryPlan loadQueryPlan(IXMLMemento element) {
    DateFormat formater = DateUtil.getDateFormat(DATE_PATTERN, Locale.ENGLISH);
    String query = element.getString("query");
    String dateStr = element.getString("create_date");
    String plan = element.getString("plan");
    Date date = null;
    try {
        date = formater.parse(dateStr);
    } catch (ParseException e) {
        LOGGER.error(e.getMessage());
        date = new Date();
    }
    return new StructQueryPlan(query, plan, date);
}
Also used : DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) Date(java.util.Date) StructQueryPlan(com.cubrid.common.core.queryplan.StructQueryPlan)

Example 9 with StructQueryPlan

use of com.cubrid.common.core.queryplan.StructQueryPlan in project cubrid-manager by CUBRID.

the class QueryTunerJob method run.

/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
	 */
protected IStatus run(IProgressMonitor arg0) {
    // FIXME move this logic to core module
    if (!initConnection()) {
        return Status.CANCEL_STATUS;
    }
    ServerInfo serverInfo = databaseInfo.getServerInfo() == null ? null : databaseInfo.getServerInfo();
    int pageLimit = QueryOptions.getPageLimit(serverInfo);
    for (String query : queryList) {
        long startTime = System.currentTimeMillis();
        if (query != null && query.trim().lastIndexOf(";") == -1) {
            query += ";";
        }
        fireQueryChanged(query, QueryEvent.QUERY_START);
        String sql = getWrapedSQL(query);
        if ((queryType & IQueryJob.COLLECT_STAT) > 0) {
            beginCollectExecStats();
        }
        try {
            stmt = getStatement(connection, sql, (queryType & IQueryJob.INCLUDE_OID) > 0, false);
        //				if (parameterList != null) {
        //					String charset = getSelectedDatabase().getDatabaseInfo().getCharSet();
        //					for (PstmtParameter pstmtParameter : parameterList) {
        //						FieldHandlerUtils.setPreparedStatementValue(pstmtParameter, stmt, charset);
        //					}
        //				}
        } catch (final SQLException ee) {
            LOGGER.error("", ee);
            queryRecordList.add(new QueryRecord(query, startTime, System.currentTimeMillis(), new Date(), ee));
            fireQueryChanged(query, QueryEvent.QUERY_FAILED);
            continue;
        }
        QueryRecord queryRecord = new QueryRecord(query, startTime, new Date());
        /*Run the query*/
        if ((queryType & IQueryJob.RUN_QUERY) > 0) {
            try {
                if (stmt.hasResultSet()) {
                    stmt.setQueryInfo(false);
                    stmt.setOnlyQueryPlan(false);
                    stmt.executeQuery();
                    resultSet = (CUBRIDResultSetProxy) stmt.getResultSet();
                    queryRecord.setColumnInfoList(getColumnData(resultSet));
                    QueryInfo queryInfo = new QueryInfo();
                    queryInfo.setPageSize(pageLimit);
                    queryRecord.setQueryInfo(queryInfo);
                    recordProcessor.process(resultSet, queryRecord);
                } else {
                    int threadExecResult = 0;
                    threadExecResult = stmt.executeUpdate();
                    queryRecord.setThreadExecResult(threadExecResult);
                }
            } catch (final SQLException ee) {
                LOGGER.error(ee.getMessage(), ee);
                queryRecord.setErrorException(ee);
            }
        }
        /*Run the query plan*/
        if ((queryType & IQueryJob.RUN_PLAN) > 0) {
            StructQueryPlan queryPlan = null;
            try {
                stmt.setOnlyQueryPlan(true);
                String plan = stmt.getQueryplan(sql);
                queryPlan = new StructQueryPlan(sql, plan, new Date());
                queryRecord.setQueryPlan(queryPlan);
            } catch (final SQLException ee) {
                LOGGER.error(ee.getMessage(), ee);
                queryRecord.setErrorException(ee);
            }
        }
        if ((queryType & IQueryJob.COLLECT_STAT) > 0) {
            queryRecord.setStatistics(CubridUtil.fetchStatistics(connection));
        } else {
            queryRecord.setStatistics(CubridUtil.makeBlankStatistics());
        }
        queryRecord.setStopTime(System.currentTimeMillis());
        queryRecordList.add(queryRecord);
        QueryUtil.freeQuery(stmt, resultSet);
        fireQueryChanged(query, QueryEvent.QUERY_FINISH);
    }
    /*Free the resource*/
    QueryUtil.freeQuery(connection);
    fireQueryChanged("", QueryEvent.QUERY_FINISH_ALL);
    return Status.OK_STATUS;
}
Also used : SQLException(java.sql.SQLException) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) QueryInfo(com.cubrid.common.ui.query.control.QueryInfo) Date(java.util.Date) StructQueryPlan(com.cubrid.common.core.queryplan.StructQueryPlan)

Example 10 with StructQueryPlan

use of com.cubrid.common.core.queryplan.StructQueryPlan in project cubrid-manager by CUBRID.

the class QueryPlanCompositeWithHistory method deleteHistory.

/**
	 * delete history
	 * only delete from tableItem in planHistoryTable and Preference
	 * don't delete it from planHistoryList 
	 * because planHistoryList keep the uid and index relationship
	 */
private void deleteHistory() {
    MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
    messageBox.setText(Messages.tooltip_qedit_explain_history_delete);
    messageBox.setMessage(Messages.explain_history_delete_message);
    // remove data, both view and model
    int buttonID = messageBox.open();
    if (buttonID == SWT.YES) {
        List<Integer> deleteIndex = new ArrayList<Integer>();
        for (int i = 0; i < planHistoryTable.getSelectionIndices().length; i++) {
            deleteIndex.add(planHistoryTable.getSelectionIndices()[i]);
        }
        List<StructQueryPlan> deleteList = new ArrayList<StructQueryPlan>();
        for (int i = 0; i < deleteIndex.size(); i++) {
            int seletectIndex = deleteIndex.get(i);
            int newIndex = seletectIndex - i;
            TableItem tableItem = planHistoryTable.getItem(newIndex);
            if (tableItem == null) {
                return;
            }
            int uid = Integer.valueOf(tableItem.getText(0));
            PlanTabItem tabItem = findPlanTab(uid);
            if (tabItem != null) {
                if (!tabItem.isDisposed()) {
                    tabItem.dispose();
                }
            }
            if (!tableItem.isDisposed()) {
                tableItem.dispose();
            }
            StructQueryPlan sq = planHistoryList.get(uid - 1);
            deleteList.add(sq);
        }
        PlanHistoryManager.deleteStructQuerysFromPreference(editor.getSelectedDatabase(), deleteList);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) StructQueryPlan(com.cubrid.common.core.queryplan.StructQueryPlan) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

StructQueryPlan (com.cubrid.common.core.queryplan.StructQueryPlan)12 Date (java.util.Date)5 TuneModeModel (com.cubrid.common.ui.query.control.tunemode.TuneModeModel)3 SQLException (java.sql.SQLException)3 DateFormat (java.text.DateFormat)3 QueryRecord (com.cubrid.common.ui.query.tuner.QueryRecord)2 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 CTabFolder (org.eclipse.swt.custom.CTabFolder)2 Point (org.eclipse.swt.graphics.Point)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 TableItem (org.eclipse.swt.widgets.TableItem)2 PlanResult (com.cubrid.common.core.queryplan.model.PlanResult)1 EditTableAction (com.cubrid.common.ui.cubrid.table.action.EditTableAction)1 QueryInfo (com.cubrid.common.ui.query.control.QueryInfo)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