Search in sources :

Example 1 with SQLHistoryDetail

use of com.cubrid.common.ui.query.control.SQLHistoryDetail in project cubrid-manager by CUBRID.

the class RecentlyUsedSQLDetailPersistUtils method saveToXML.

/**
	 * save the sql to preference
	 *
	 * @param id
	 * @param recentlyUsedSQLContentList
	 */
private static void saveToXML(String id, LinkedList<SQLHistoryDetail> sqlHistories) {
    if (sqlHistories == null) {
        return;
    }
    XMLMemento memento = XMLMemento.createWriteRoot("SQLHistoryDetails");
    for (int i = 0, len = sqlHistories.size(); i < len; i++) {
        IXMLMemento subNodes = memento.createChild("SQLHistoryDetail");
        SQLHistoryDetail historyDetail = (SQLHistoryDetail) sqlHistories.get(i);
        subNodes.putString("SQL", historyDetail.getSql());
        subNodes.putString("elapseTime", historyDetail.getElapseTime());
        subNodes.putString("executeTime", historyDetail.getExecuteTime());
        subNodes.putString("LOG", historyDetail.getExecuteInfo());
    }
    PersistUtils.saveXMLMemento(RecentlyUsedSQLComposite.ID, id, memento);
}
Also used : IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) XMLMemento(com.cubrid.cubridmanager.core.common.xml.XMLMemento) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) SQLHistoryDetail(com.cubrid.common.ui.query.control.SQLHistoryDetail)

Example 2 with SQLHistoryDetail

use of com.cubrid.common.ui.query.control.SQLHistoryDetail in project cubrid-manager by CUBRID.

the class RecentlyUsedSQLDetailPersistUtils method remove.

public static void remove(CubridDatabase cubridDatabase, List<SQLHistoryDetail> historyToRemove) {
    if (historyToRemove == null || historyToRemove.size() == 0) {
        return;
    }
    String id = getId(cubridDatabase);
    synchronized (LOCK) {
        LinkedList<SQLHistoryDetail> sqlHistories = logs.get(id);
        if (sqlHistories == null) {
            return;
        }
        for (SQLHistoryDetail remove : historyToRemove) {
            sqlHistories.remove(remove);
        }
        saveToXML(id, sqlHistories);
    }
}
Also used : SQLHistoryDetail(com.cubrid.common.ui.query.control.SQLHistoryDetail)

Example 3 with SQLHistoryDetail

use of com.cubrid.common.ui.query.control.SQLHistoryDetail in project cubrid-manager by CUBRID.

the class RecentlyUsedSQLDetailPersistUtils method load.

public static void load(CubridDatabase cubridDatabase) {
    String id = getId(cubridDatabase);
    synchronized (LOCK) {
        if (logs.containsKey(id)) {
            return;
        }
        LinkedList<SQLHistoryDetail> sqlHistories = logs.get(id);
        if (sqlHistories == null) {
            sqlHistories = new LinkedList<SQLHistoryDetail>();
            logs.put(id, sqlHistories);
            IXMLMemento memento = PersistUtils.getXMLMemento(RecentlyUsedSQLComposite.ID, id);
            if (memento == null) {
                return;
            }
            try {
                List<SQLHistoryDetail> list = loadFromXML(memento);
                sqlHistories.addAll(list);
            } catch (Exception e) {
                LOGGER.error("parse recently used SQL error", e);
            }
        }
    }
}
Also used : IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) SQLHistoryDetail(com.cubrid.common.ui.query.control.SQLHistoryDetail)

Example 4 with SQLHistoryDetail

use of com.cubrid.common.ui.query.control.SQLHistoryDetail in project cubrid-manager by CUBRID.

the class RecentlyUsedSQLDetailPersistUtils method loadFromXML.

/**
	 * read SQLHistoryDetail List 
	 *
	 * @param memento IXMLMemento
	 * @return
	 */
private static List<SQLHistoryDetail> loadFromXML(IXMLMemento memento) throws Exception {
    List<SQLHistoryDetail> recentlyUsedSQLContentsList = new LinkedList<SQLHistoryDetail>();
    try {
        int index = 1;
        for (IXMLMemento xmlDetail : memento.getChildren("SQLHistoryDetail")) {
            SQLHistoryDetail historyDetail = new SQLHistoryDetail();
            historyDetail.setSql(xmlDetail.getString("SQL"));
            historyDetail.setElapseTime(xmlDetail.getString("elapseTime"));
            historyDetail.setExecuteTime(xmlDetail.getString("executeTime"));
            historyDetail.setExecuteInfo(xmlDetail.getString("LOG"));
            historyDetail.setIndex(index++);
            recentlyUsedSQLContentsList.add(historyDetail);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return recentlyUsedSQLContentsList;
}
Also used : IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) SQLHistoryDetail(com.cubrid.common.ui.query.control.SQLHistoryDetail) LinkedList(java.util.LinkedList)

Aggregations

SQLHistoryDetail (com.cubrid.common.ui.query.control.SQLHistoryDetail)4 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)3 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)1 LinkedList (java.util.LinkedList)1