Search in sources :

Example 6 with QueryRecord

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

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

use of com.cubrid.common.ui.query.tuner.QueryRecord in project cubrid-manager by CUBRID.

the class ApplicationPersistUtil method loadQueryRecordList.

/**
	 * Load query record list
	 *
	 * @param element
	 */
private void loadQueryRecordList(IXMLMemento element) {
    DateFormat formater = DateUtil.getDateFormat(DATE_PATTERN, Locale.ENGLISH);
    IXMLMemento[] dataArray = element.getChildren("query_redord_list");
    if (dataArray != null && dataArray.length > 0) {
        for (int i = 0; i < dataArray.length; i++) {
            IXMLMemento child = dataArray[i];
            String key = child.getString("database_key");
            String dateStr = child.getString("create_date");
            String name = child.getString("name");
            QueryRecordProject recordList = new QueryRecordProject();
            recordList.setDatabaseKey(key);
            recordList.setName(name);
            try {
                recordList.setCreateDate(formater.parse(dateStr));
            } catch (ParseException e) {
                recordList.setCreateDate(new Date());
            }
            IXMLMemento[] queryRecordArray = child.getChildren("query_record");
            if (queryRecordArray != null && queryRecordArray.length > 0) {
                for (int j = 0; j < queryRecordArray.length; j++) {
                    IXMLMemento memen = queryRecordArray[j];
                    QueryRecord queryRecord = loadQueryRecord(memen);
                    recordList.addQueryRecord(queryRecord);
                }
            }
            List<QueryRecordProject> list = queryRecordMap.get(key);
            if (list == null) {
                list = new ArrayList<QueryRecordProject>();
                queryRecordMap.put(key, list);
            }
            list.add(recordList);
        }
    }
}
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) ParseException(java.text.ParseException) Date(java.util.Date)

Example 9 with QueryRecord

use of com.cubrid.common.ui.query.tuner.QueryRecord in project cubrid-manager by CUBRID.

the class QueryRecordListComparator method runQuery.

/**
	 * Run query
	 */
private void runQuery() {
    String query = getFirstSelectedQuery();
    if (StringUtil.isEmpty(query)) {
        return;
    }
    runItem.setEnabled(false);
    runPlanItem.setEnabled(false);
    List<String> queryList = new ArrayList<String>();
    queryList.add(query);
    QueryTunerJob job = new QueryTunerJob(IQueryJob.RUN_QUERY | IQueryJob.RUN_PLAN | IQueryJob.COLLECT_STAT | IQueryJob.AUTO_COMMIT, database.getDatabaseInfo(), queryList, new TextRecordProcessor(), QueryTunerDialog.this);
    job.schedule();
    try {
        job.join();
        List<QueryRecord> queryRecordList = job.getQueryRecordList();
        if (queryRecordList.size() > 0) {
            lastRecord = currentRecord;
            currentRecord = queryRecordList.get(0);
            displayQuery(currentRecord);
            displayQueryPlan(currentRecord);
        }
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage());
    }
    runItem.setEnabled(true);
    runPlanItem.setEnabled(true);
}
Also used : TextRecordProcessor(com.cubrid.common.ui.query.tuner.TextRecordProcessor) ArrayList(java.util.ArrayList) QueryTunerJob(com.cubrid.common.ui.query.tuner.QueryTunerJob) QueryRecord(com.cubrid.common.ui.query.tuner.QueryRecord)

Example 10 with QueryRecord

use of com.cubrid.common.ui.query.tuner.QueryRecord in project cubrid-manager by CUBRID.

the class QueryRecordListComparator method initQueryRecord.

/**
	 * Load query record
	 *
	 * @param queryRecordProject
	 * @param selectIndex
	 */
private void initQueryRecord(QueryRecordProject queryRecordProject) {
    String left = queryRecordLeftCombo.getText();
    String right = queryRecordRightCombo.getText();
    queryRecordLeftCombo.removeAll();
    queryRecordRightCombo.removeAll();
    if (queryRecordProject == null || queryRecordProject.getQueryRecordList().size() == 0) {
        return;
    }
    Collections.sort(queryRecordProject.getQueryRecordList(), new QueryRecordComparator());
    List<String> itemList = new ArrayList<String>();
    for (QueryRecord record : queryRecordProject.getQueryRecordList()) {
        itemList.add(record.getName());
    }
    String[] items = new String[itemList.size()];
    itemList.toArray(items);
    queryRecordLeftCombo.setItems(items);
    queryRecordRightCombo.setItems(items);
    int leftIndex = itemList.indexOf(left);
    if (leftIndex == -1) {
        leftIndex = 0;
    }
    queryRecordLeftCombo.select(leftIndex);
    int rightIndex = itemList.indexOf(right);
    if (rightIndex == -1) {
        rightIndex = 0;
    }
    queryRecordRightCombo.select(rightIndex);
}
Also used : ArrayList(java.util.ArrayList) QueryRecord(com.cubrid.common.ui.query.tuner.QueryRecord)

Aggregations

QueryRecord (com.cubrid.common.ui.query.tuner.QueryRecord)12 ArrayList (java.util.ArrayList)7 QueryTunerJob (com.cubrid.common.ui.query.tuner.QueryTunerJob)3 TextRecordProcessor (com.cubrid.common.ui.query.tuner.TextRecordProcessor)3 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)3 DateFormat (java.text.DateFormat)3 StructQueryPlan (com.cubrid.common.core.queryplan.StructQueryPlan)2 TextCompareInput (com.cubrid.common.ui.compare.schema.control.TextCompareInput)2 QueryPlanComposite (com.cubrid.common.ui.query.control.queryplan.QueryPlanComposite)2 QueryRecordProject (com.cubrid.common.ui.query.tuner.QueryRecordProject)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 DiffNode (org.eclipse.compare.structuremergeviewer.DiffNode)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 SashForm (org.eclipse.swt.custom.SashForm)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2