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;
}
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());
}
}
}
}
}
}
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);
}
}
}
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);
}
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);
}
Aggregations