use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.
the class AbsExternalPersist method getXMLmemento.
// protected String getMapKey(String dbUser, String dbName, String address,
// String port, String connectionName) {
// StringBuffer sb = new StringBuffer();
// sb.append(dbUser);
// sb.append("@");
// sb.append(dbName);
// sb.append("@");
// sb.append(address);
// sb.append("@");
// sb.append(port);
//
// return sb.toString();
// }
protected IXMLMemento getXMLmemento(String nodeName) throws UnsupportedEncodingException {
String xmlString = preferenceStore.getString(nodeName);
if (xmlString == null || xmlString.trim().length() == 0) {
return null;
}
ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
IXMLMemento memento = XMLMemento.loadMemento(in);
return memento;
}
use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento 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.cubridmanager.core.common.xml.IXMLMemento 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.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.
the class ApplicationPersistUtil method load.
private void load() {
editorStatusList.clear();
editorStatusListAtLastSession.clear();
queryRecordMap.clear();
try {
root = (XMLMemento) XMLMemento.loadMemento(path);
} catch (IOException e) {
LOGGER.error(getClass().getName(), e);
}
IXMLMemento[] children = root == null ? null : root.getChildren("editor_status");
for (int i = 0; children != null && i < children.length; i++) {
IXMLMemento child = children[i];
editorStatusListAtLastSession.add(loadSQLTabItem(child));
}
IXMLMemento[] queryRecordChildren = root == null ? null : root.getChildren("query_record_list_data");
for (int i = 0; queryRecordChildren != null && i < queryRecordChildren.length; i++) {
IXMLMemento child = queryRecordChildren[i];
loadQueryRecordList(child);
}
}
use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.
the class UrlConnUtil method isExistNewCubridVersion.
/**
*
* Return whether CUBRID new version exist
*
* @param localVersion String
* @param userAgent String
* @return <code>true</code> if new cubrid version exist;<code>false</code>
* otherwise
*/
public static boolean isExistNewCubridVersion(String localVersion, String userAgent) {
String url = Platform.getNL().equals("ko_KR") ? CHECK_NEW_VERSION_URL_KO : CHECK_NEW_VERSION_URL_EN;
if (!isUrlExist(url)) {
return false;
}
String content = getContent(url, userAgent);
if (isBlank(content)) {
return false;
}
content = content.toUpperCase(Locale.getDefault());
if (content.indexOf("<HTML") >= 0) {
content = content.substring(content.indexOf("<HTML"));
}
try {
ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes("UTF-8"));
IXMLMemento memento = XMLMemento.loadMemento(in);
if (memento == null) {
return false;
}
IXMLMemento[] children = memento.getChildren("BODY");
if (children != null && children.length == 1) {
content = children[0].getTextData();
}
} catch (UnsupportedEncodingException e) {
LOGGER.error(e.getMessage(), e);
return false;
}
return compareVersion(content, localVersion);
}
Aggregations