Search in sources :

Example 6 with QueryRecordProject

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

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

the class ApplicationPersistUtil method getQueryRecordProject.

public List<QueryRecordProject> getQueryRecordProject(DatabaseInfo databaseInfo) {
    List<QueryRecordProject> list = queryRecordMap.get(getDBMapKey(databaseInfo));
    if (list == null) {
        list = new ArrayList<QueryRecordProject>();
        queryRecordMap.put(getDBMapKey(databaseInfo), list);
    }
    List<QueryRecordProject> result = new ArrayList<QueryRecordProject>();
    for (QueryRecordProject project : list) {
        result.add(project.clone());
    }
    return result;
}
Also used : QueryRecordProject(com.cubrid.common.ui.query.tuner.QueryRecordProject) ArrayList(java.util.ArrayList)

Example 8 with QueryRecordProject

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

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

the class AddQueryRecordProjectDialog method validate.

private boolean validate() {
    setErrorMessage(null);
    getButton(IDialogConstants.OK_ID).setEnabled(false);
    name = newText.getText();
    if (StringUtil.isEmpty(name)) {
        setErrorMessage(Messages.msgQueryTunerNameEmpty);
    }
    List<QueryRecordProject> queryRecordProjectList = ApplicationPersistUtil.getInstance().getQueryRecordProject(databaseInfo);
    if (newFlag) {
        for (QueryRecordProject list : queryRecordProjectList) {
            if (StringUtil.isEqual(name, list.getName())) {
                setErrorMessage(Messages.bind(Messages.msgQueryTunerNameExist, name));
                return false;
            }
        }
    } else {
        for (QueryRecordProject list : queryRecordProjectList) {
            if (StringUtil.isEqual(name, list.getName()) && list != queryRecordProect) {
                setErrorMessage(Messages.msgQueryTunerNameExist);
                return false;
            }
        }
    }
    getButton(IDialogConstants.OK_ID).setEnabled(true);
    return true;
}
Also used : QueryRecordProject(com.cubrid.common.ui.query.tuner.QueryRecordProject)

Example 10 with QueryRecordProject

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

the class QueryRecordListComparator method renameQueryRecordProject.

/**
	 * Rename selected query record list
	 *
	 */
private void renameQueryRecordProject() {
    String name = historyCombo.getText();
    QueryRecordProject queryRecordProject = ApplicationPersistUtil.getInstance().findQueryRecordProject(database.getDatabaseInfo(), name);
    if (queryRecordProject != null) {
        AddQueryRecordProjectDialog dialog = new AddQueryRecordProjectDialog(getShell(), queryRecordProject, false, database.getDatabaseInfo());
        if (dialog.open() == IDialogConstants.OK_ID) {
            /*Remove old list*/
            ApplicationPersistUtil.getInstance().removeQueryRecordProject(database.getDatabaseInfo(), name);
            /*Add new list*/
            queryRecordProject.setName(dialog.getName());
            ApplicationPersistUtil.getInstance().addQueryRecordProject(database.getDatabaseInfo(), queryRecordProject);
            /*Save*/
            ApplicationPersistUtil.getInstance().save();
            switchQueryRecordProject(queryRecordProject.getName());
        }
    }
}
Also used : QueryRecordProject(com.cubrid.common.ui.query.tuner.QueryRecordProject)

Aggregations

QueryRecordProject (com.cubrid.common.ui.query.tuner.QueryRecordProject)14 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 QueryRecord (com.cubrid.common.ui.query.tuner.QueryRecord)2 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)2 DateFormat (java.text.DateFormat)2 List (java.util.List)2 StructQueryPlan (com.cubrid.common.core.queryplan.StructQueryPlan)1 QueryPlanComposite (com.cubrid.common.ui.query.control.queryplan.QueryPlanComposite)1 RestorableQueryEditorInfo (com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo)1 ParseException (java.text.ParseException)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Combo (org.eclipse.swt.widgets.Combo)1