Search in sources :

Example 16 with IXMLMemento

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento)

Example 17 with IXMLMemento

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;
}
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 18 with IXMLMemento

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());
                    }
                }
            }
        }
    }
}
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 19 with IXMLMemento

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);
    }
}
Also used : IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) IOException(java.io.IOException)

Example 20 with IXMLMemento

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)54 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)18 ByteArrayInputStream (java.io.ByteArrayInputStream)10 IOException (java.io.IOException)10 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)8 ArrayList (java.util.ArrayList)7 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)6 HashMap (java.util.HashMap)6 RGB (org.eclipse.swt.graphics.RGB)6 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)5 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)5 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)5 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)5 PreferenceStore (org.eclipse.jface.preference.PreferenceStore)5 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)4 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)4 SQLHistoryDetail (com.cubrid.common.ui.query.control.SQLHistoryDetail)3 QueryRecord (com.cubrid.common.ui.query.tuner.QueryRecord)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 MonitorStatistic (com.cubrid.common.ui.spi.model.MonitorStatistic)3