Search in sources :

Example 16 with XMLMemento

use of com.cubrid.cubridmanager.core.common.xml.XMLMemento in project cubrid-manager by CUBRID.

the class MonitorDashboardPersistManager method saveDashboard.

/**
	 * 
	 * Save dash boards
	 * 
	 */
public void saveDashboard() {
    synchronized (this) {
        XMLMemento memento = XMLMemento.createWriteRoot("dashboards");
        Iterator<ICubridNode> iterator = monitorDashboardList.iterator();
        while (iterator.hasNext()) {
            ICubridNode node = (ICubridNode) iterator.next();
            if (node instanceof MonitorStatistic) {
                continue;
            }
            Dashboard dashboard = (Dashboard) node.getAdapter(Dashboard.class);
            IXMLMemento dashboardChild = memento.createChild("dashboard");
            dashboardChild.putString("name", node.getName());
            Iterator<HostNode> nodeIte = dashboard.getHostNodeList().iterator();
            while (nodeIte.hasNext()) {
                //save host node
                HostNode hostNode = nodeIte.next();
                IXMLMemento hostNodeChild = dashboardChild.createChild("host");
                hostNodeChild.putString("aliasname", hostNode.getName());
                hostNodeChild.putString("ip", hostNode.getIp());
                hostNodeChild.putString("port", hostNode.getPort());
                hostNodeChild.putString("username", hostNode.getUserName());
                hostNodeChild.putString("password", CipherUtils.encrypt(hostNode.getPassword()));
                hostNodeChild.putString("location", hostNode.getLocation().x + "," + hostNode.getLocation().y);
                hostNodeChild.putString("visible", hostNode.isVisible() ? "true" : "false");
                //save the database node list
                List<DatabaseNode> dbNodeList = hostNode.getDbNodeList();
                Iterator<DatabaseNode> dbNodeIte = dbNodeList.iterator();
                while (dbNodeIte.hasNext()) {
                    DatabaseNode dbNode = (DatabaseNode) dbNodeIte.next();
                    IXMLMemento databaseNodeChild = hostNodeChild.createChild("database");
                    databaseNodeChild.putString("aliasname", dbNode.getName());
                    databaseNodeChild.putString("dbname", dbNode.getDbName());
                    databaseNodeChild.putString("username", dbNode.getDbUser());
                    databaseNodeChild.putString("password", CipherUtils.encrypt(dbNode.getDbPassword()));
                    databaseNodeChild.putString("location", dbNode.getLocation().x + "," + dbNode.getLocation().y);
                }
                //save broker node list
                List<BrokerNode> brokerNodeList = hostNode.getBrokerNodeList();
                Iterator<BrokerNode> brokerNodeIte = brokerNodeList.iterator();
                while (brokerNodeIte.hasNext()) {
                    BrokerNode brokerNode = (BrokerNode) brokerNodeIte.next();
                    IXMLMemento brokerNodeChild = hostNodeChild.createChild("broker");
                    brokerNodeChild.putString("aliasname", brokerNode.getName());
                    brokerNodeChild.putString("brokername", brokerNode.getBrokerName());
                    brokerNodeChild.putString("location", brokerNode.getLocation().x + "," + brokerNode.getLocation().y);
                    //save the client IP list
                    ClientNode ipListNode = dashboard.getClientNodeByBroker(brokerNode);
                    Point point = null;
                    String clientIpName = null;
                    if (ipListNode == null) {
                        brokerNodeChild.putString("show_ip_list", "false");
                        point = brokerNode.getClientsLocation();
                    } else {
                        brokerNodeChild.putString("show_ip_list", ipListNode.isVisible() ? "true" : "false");
                        point = ipListNode.getLocation();
                        clientIpName = ipListNode.getName();
                    }
                    if (point != null) {
                        brokerNodeChild.putString("client_ip_location", point.x + "," + point.y);
                    }
                    if (clientIpName != null) {
                        brokerNodeChild.putString("client_ip_name", clientIpName);
                    }
                    //save the database list
                    BrokerDBListNode dbListNode = dashboard.getBrokerDBListNodeByBroker(brokerNode);
                    String clientDbName = null;
                    if (dbListNode == null) {
                        brokerNodeChild.putString("show_db_list", "false");
                        point = brokerNode.getDatabasesLocation();
                    } else {
                        brokerNodeChild.putString("show_db_list", dbListNode.isVisible() ? "true" : "false");
                        point = dbListNode.getLocation();
                        clientDbName = dbListNode.getName();
                    }
                    if (point != null) {
                        brokerNodeChild.putString("client_db_location", point.x + "," + point.y);
                    }
                    if (clientDbName != null) {
                        brokerNodeChild.putString("client_db_name", clientDbName);
                    }
                }
            }
        }
        PersistUtils.saveXMLMemento(CubridManagerUIPlugin.PLUGIN_ID, MONITOR_DASHBOARD_XML_CONTENT, memento);
    }
}
Also used : IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) HostNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode) ClientNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.ClientNode) BrokerDBListNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.BrokerDBListNode) Dashboard(com.cubrid.cubridmanager.ui.mondashboard.editor.model.Dashboard) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Point(org.eclipse.draw2d.geometry.Point) BrokerNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.BrokerNode) DatabaseNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode) XMLMemento(com.cubrid.cubridmanager.core.common.xml.XMLMemento) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) MonitorStatistic(com.cubrid.common.ui.spi.model.MonitorStatistic)

Example 17 with XMLMemento

use of com.cubrid.cubridmanager.core.common.xml.XMLMemento in project cubrid-manager by CUBRID.

the class MonitorStatisticPersistManager method saveStatistic.

/**
	 *
	 * Save MonitorStatistic nodes
	 *
	 */
public void saveStatistic() {
    synchronized (this) {
        XMLMemento memento = XMLMemento.createWriteRoot("monitors");
        Iterator<String> keySetIterator = monitorStatisticMap.keySet().iterator();
        while (keySetIterator.hasNext()) {
            String hostId = keySetIterator.next();
            boolean isMultiHost = HOST_ID_FOR_MULTI_HOST.equals(hostId);
            IXMLMemento monsPerHostMemento = memento.createChild("monitorsPerHost");
            monsPerHostMemento.putBoolean("isMultihost", isMultiHost);
            if (!isMultiHost) {
                monsPerHostMemento.putString("hostId", hostId);
            }
            List<MonitorStatistic> monitorStatisticList = monitorStatisticMap.get(hostId);
            if (monitorStatisticList == null) {
                continue;
            }
            Iterator<MonitorStatistic> nodeIterator = monitorStatisticList.iterator();
            while (nodeIterator.hasNext()) {
                MonitorStatistic node = nodeIterator.next();
                IXMLMemento monMemento = monsPerHostMemento.createChild("monitor");
                monMemento.putString("name", node.getId());
                //save StatisticItem list
                List<StatisticChartItem> statisticItemList = node.getStatisticItemList();
                Iterator<StatisticChartItem> itemIterator = statisticItemList.iterator();
                while (itemIterator.hasNext()) {
                    if (!node.isMultiHost()) {
                        SingleHostChartItem item = (SingleHostChartItem) itemIterator.next();
                        IXMLMemento chartMemento = monMemento.createChild("chart");
                        chartMemento.putInteger("series", item.getSeries());
                        chartMemento.putString("name", item.getName());
                        chartMemento.putString("type", item.getType().toString());
                        chartMemento.putString("dtype", item.getDType());
                        chartMemento.putString("metrics", ArrayUtil.collectionToCSString(item.getMetricList()));
                        switch(item.getType()) {
                            case DB:
                                chartMemento.putString("dbname", item.getDbName());
                                break;
                            case DB_VOL:
                                chartMemento.putString("dbname", item.getDbName());
                                chartMemento.putString("volname", item.getVolName());
                                break;
                            case BROKER:
                                chartMemento.putString("bname", item.getBrokerName());
                                break;
                            case OS:
                                break;
                            default:
                                break;
                        }
                    } else {
                        MultiHostChartItem item = (MultiHostChartItem) itemIterator.next();
                        IXMLMemento chartMemento = monMemento.createChild("chart");
                        chartMemento.putInteger("series", item.getSeries());
                        chartMemento.putString("name", item.getName());
                        chartMemento.putString("type", item.getType().toString());
                        chartMemento.putString("dtype", item.getDType());
                        //save HostInfo list
                        List<StatisticChartHost> hostList = item.getHostList();
                        Iterator<StatisticChartHost> hostIterator = hostList.iterator();
                        while (hostIterator.hasNext()) {
                            StatisticChartHost host = (StatisticChartHost) hostIterator.next();
                            IXMLMemento hostMemento = chartMemento.createChild("host");
                            hostMemento.putString("cubridServerId", host.getCubridServerId());
                            hostMemento.putString("ip", host.getIp());
                            hostMemento.putInteger("port", host.getPort());
                            hostMemento.putString("user", host.getUser());
                            hostMemento.putString("password", CipherUtils.encrypt(host.getPassword()));
                            hostMemento.putString("metric", host.getMetric());
                            switch(item.getType()) {
                                case DB:
                                    hostMemento.putString("dbname", host.getDbName());
                                    break;
                                case DB_VOL:
                                    hostMemento.putString("dbname", host.getDbName());
                                    hostMemento.putString("volname", host.getVolName());
                                    break;
                                case BROKER:
                                    hostMemento.putString("bname", host.getBrokerName());
                                    break;
                                case OS:
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                }
            }
        }
        PersistUtils.saveXMLMemento(CubridManagerUIPlugin.PLUGIN_ID, MONITOR_STATISTIC_XML_CONTENT, memento);
    }
}
Also used : SingleHostChartItem(com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) StatisticChartItem(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartItem) MultiHostChartItem(com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem) XMLMemento(com.cubrid.cubridmanager.core.common.xml.XMLMemento) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) MonitorStatistic(com.cubrid.common.ui.spi.model.MonitorStatistic) StatisticChartHost(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartHost)

Example 18 with XMLMemento

use of com.cubrid.cubridmanager.core.common.xml.XMLMemento in project cubrid-manager by CUBRID.

the class CQBGroupNodePersistManager method saveAllGroupNode.

/**
	 * Save all group node.
	 *
	 */
public void saveAllGroupNode() {
    synchronized (this) {
        XMLMemento memento = XMLMemento.createWriteRoot("groups");
        for (CubridGroupNode group : groupNodeList) {
            IXMLMemento child = memento.createChild("group");
            child.putString("id", group.getId());
            child.putString("name", group.getName());
            for (ICubridNode cn : group.getChildren()) {
                IXMLMemento childHost = child.createChild("item");
                childHost.putString("id", cn.getId());
            }
        }
        PersistUtils.saveXMLMemento(ApplicationUtil.CQB_UI_PLUGIN_ID, COM_CUBRID_QB_DBGROUP, memento);
    }
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) XMLMemento(com.cubrid.cubridmanager.core.common.xml.XMLMemento) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 19 with XMLMemento

use of com.cubrid.cubridmanager.core.common.xml.XMLMemento in project cubrid-manager by CUBRID.

the class CQBDBNodePersistManager method saveServer.

public void saveServer(List<CubridDatabase> servers, String path) {
    synchronized (this) {
        XMLMemento memento = XMLMemento.createWriteRoot("databases");
        Iterator<CubridDatabase> iterator = servers.iterator();
        while (iterator.hasNext()) {
            CubridDatabase db = (CubridDatabase) iterator.next();
            DatabaseInfo dbInfo = db.getDatabaseInfo();
            IXMLMemento child = memento.createChild("database");
            child.putString("name", db.getLabel());
            child.putString("dbName", dbInfo.getDbName());
            child.putString("brokerPort", dbInfo.getBrokerPort());
            child.putString("brokerIp", dbInfo.getBrokerIP());
            child.putString("charset", dbInfo.getCharSet());
            child.putString("jdbcAttrs", dbInfo.getJdbcAttrs());
            child.putString("dbUser", db.getUserName());
            child.putBoolean("savePassword", false);
            child.putString("jdbcDriver", db.getServer().getJdbcDriverVersion());
            /*Save the database editor config*/
            DatabaseEditorConfig config = QueryOptions.getEditorConfig(db, false);
            if (config != null) {
                IXMLMemento editorConfigChild = child.createChild("editorConfig");
                editorConfigChild.putString("database-comment", config.getDatabaseComment() == null ? "" : config.getDatabaseComment());
                if (config.getBackGround() != null) {
                    RGB background = config.getBackGround();
                    int bgPos = EditorConstance.getBGPos(background);
                    editorConfigChild.putInteger("purpose-code", bgPos);
                }
            }
        }
        FileOutputStream fout = null;
        try {
            fout = new FileOutputStream(path);
            fout.write(memento.getContents());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fout.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : XMLMemento(com.cubrid.cubridmanager.core.common.xml.XMLMemento) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) RGB(org.eclipse.swt.graphics.RGB) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig) IOException(java.io.IOException)

Aggregations

IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)19 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)19 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 HashMap (java.util.HashMap)3 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)3 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)3 RGB (org.eclipse.swt.graphics.RGB)3 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)2 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)2 MonitorStatistic (com.cubrid.common.ui.spi.model.MonitorStatistic)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 Map (java.util.Map)2 PstmtParameter (com.cubrid.common.ui.cubrid.table.dialog.PstmtParameter)1 ExportConfig (com.cubrid.common.ui.cubrid.table.progress.ExportConfig)1 SQLHistoryDetail (com.cubrid.common.ui.query.control.SQLHistoryDetail)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1