Search in sources :

Example 21 with IXMLMemento

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

the class CQBDBNodePersistManager method saveDatabases.

/**
	 *
	 * Save added database to plug-in preference
	 *
	 */
public void saveDatabases() {
    synchronized (this) {
        XMLMemento memento = XMLMemento.createWriteRoot("databases");
        Iterator<CubridDatabase> iterator = databaseList.iterator();
        while (iterator.hasNext()) {
            CubridDatabase database = (CubridDatabase) iterator.next();
            DatabaseInfo dbInfo = database.getDatabaseInfo();
            ServerInfo serverInfo = dbInfo.getServerInfo();
            DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
            IXMLMemento child = memento.createChild("database");
            child.putString("name", database.getLabel());
            child.putString("dbName", dbInfo.getDbName());
            child.putString("dbUser", dbUserInfo.getName());
            if (database.isAutoSavePassword()) {
                child.putString("dbPassword", CipherUtils.encrypt(dbUserInfo.getNoEncryptPassword()));
            } else {
                child.putString("dbPassword", "");
            }
            child.putString("savePassword", String.valueOf(database.isAutoSavePassword()));
            // [TOOLS-2425]Support shard broker
            child.putString("isShard", String.valueOf(dbInfo.isShard()));
            child.putString("shardQueryType", String.valueOf(dbInfo.getShardQueryType()));
            child.putString("jdbcDriver", serverInfo.getJdbcDriverVersion());
            child.putString("brokerIp", dbInfo.getBrokerIP());
            child.putString("brokerPort", dbInfo.getBrokerPort());
            child.putString("charset", dbInfo.getCharSet());
            child.putString("jdbcAttrs", dbInfo.getJdbcAttrs());
            /*Save the database editor config*/
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, false);
            if (editorConfig != null) {
                IXMLMemento editorConfigChild = child.createChild("editorConfig");
                editorConfigChild.putString("database-comment", editorConfig.getDatabaseComment() == null ? "" : editorConfig.getDatabaseComment());
                if (editorConfig.getBackGround() != null) {
                    RGB background = editorConfig.getBackGround();
                    int bgPos = EditorConstance.getBGPos(background);
                    editorConfigChild.putInteger("purpose-code", bgPos);
                }
            }
        }
        PersistUtils.saveXMLMemento(ApplicationUtil.CQB_UI_PLUGIN_ID, DATABASE_XML_CONTENT, memento);
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) 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) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) RGB(org.eclipse.swt.graphics.RGB) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 22 with IXMLMemento

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

the class CQBDBNodePersistManager method loadDatabases.

/**
	 *
	 * Load databases from xml memento
	 *
	 * @param memento IXMLMemento
	 * @param isLoadOptions boolean
	 * @param optionPath String
	 */
protected void loadDatabases(IXMLMemento memento, boolean isLoadOptions, String optionPath) {
    //when import connections, load the global preference
    if (isLoadOptions) {
        QueryOptions.load(optionPath, null);
    }
    IXMLMemento[] children = memento == null ? null : memento.getChildren("database");
    for (int i = 0; children != null && i < children.length; i++) {
        String name = children[i].getString("name");
        String dbName = children[i].getString("dbName");
        String dbUser = children[i].getString("dbUser");
        String dbPassword = children[i].getString("dbPassword");
        String jdbcDriver = children[i].getString("jdbcDriver");
        boolean savePassword = children[i].getBoolean("savePassword");
        // [TOOLS-2425]Support shard broker
        Boolean isShardObj = children[i].getBoolean("isShard");
        boolean isShard = isShardObj == null ? false : isShardObj;
        String shardQueryTypeStr = children[i].getString("shardQueryType");
        int shardQueryType = StringUtil.intValue(shardQueryTypeStr, 0);
        if (shardQueryType == 0) {
            shardQueryType = DatabaseInfo.SHARD_QUERY_TYPE_VAL;
        }
        String brokerIp = children[i].getString("brokerIp");
        String brokerPort = children[i].getString("brokerPort");
        String charset = children[i].getString("charset");
        String jdbcAttrs = children[i].getString("jdbcAttrs");
        DatabaseEditorConfig editorConfig = null;
        IXMLMemento editorConfigElement = children[i].getChild("editorConfig");
        if (editorConfigElement != null) {
            editorConfig = new DatabaseEditorConfig();
            String strBGPos = editorConfigElement.getString("purpose-code");
            if (strBGPos == null) {
                strBGPos = "0";
            }
            int bgPos = StringUtil.intValue(strBGPos, 0);
            RGB background = EditorConstance.getRGBByPos(bgPos);
            editorConfig.setBackGround(background);
            editorConfig.setDatabaseComment(editorConfigElement.getString("database-comment"));
        }
        ServerInfo serverInfo = new ServerInfo();
        serverInfo.setServerName(name);
        serverInfo.setHostAddress(brokerIp);
        serverInfo.setHostMonPort(Integer.parseInt(brokerPort));
        serverInfo.setHostJSPort(Integer.parseInt(brokerPort) + 1);
        serverInfo.setUserName(dbName + "@" + brokerIp);
        serverInfo.setJdbcDriverVersion(jdbcDriver);
        CubridServer server = new CubridServer(name, name, null, null);
        server.setServerInfo(serverInfo);
        server.setType(NodeType.SERVER);
        DatabaseInfo dbInfo = new DatabaseInfo(dbName, serverInfo);
        dbInfo.setBrokerIP(brokerIp);
        dbInfo.setBrokerPort(brokerPort);
        dbInfo.setCharSet(charset);
        dbInfo.setJdbcAttrs(jdbcAttrs);
        dbInfo.setRunningType(DbRunningType.CS);
        // [TOOLS-2425]Support shard broker
        dbInfo.setShard(isShard);
        dbInfo.setShardQueryType(shardQueryType);
        String decDbPassword = null;
        if (dbPassword != null && dbPassword.trim().length() > 0) {
            decDbPassword = CipherUtils.decrypt(dbPassword);
        }
        DbUserInfo dbUserInfo = new DbUserInfo(dbName, dbUser, dbPassword, decDbPassword, false);
        dbInfo.setAuthLoginedDbUserInfo(dbUserInfo);
        String dbId = name + ICubridNodeLoader.NODE_SEPARATOR + name;
        if (this.getDatabase(dbId) != null) {
            continue;
        }
        CubridDatabase database = new CubridDatabase(dbId, name);
        database.setServer(server);
        database.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
        database.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
        database.setDatabaseInfo(dbInfo);
        CubridNodeLoader loader = new CQBDbConnectionLoader();
        loader.setLevel(ICubridNodeLoader.FIRST_LEVEL);
        database.setLoader(loader);
        database.setAutoSavePassword(savePassword);
        if (isLoadOptions) {
            QueryOptions.load(optionPath, serverInfo);
        }
        /*Save the DatabaseEditorConfig to the memory*/
        QueryOptions.putEditorConfig(database, editorConfig, false);
        databaseList.add(database);
        fireAddDatabase(database);
    }
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CQBDbConnectionLoader(com.cubrid.cubridmanager.ui.spi.model.loader.CQBDbConnectionLoader) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) CubridNodeLoader(com.cubrid.common.ui.spi.model.CubridNodeLoader) RGB(org.eclipse.swt.graphics.RGB) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 23 with IXMLMemento

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

the class CMGroupNodePersistManager 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.CM_UI_PLUGIN_ID, COM_CUBRID_MANAGER_HOSTGROUP, 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 24 with IXMLMemento

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

the class CMHostNodePersistManager method saveServer.

public void saveServer(List<CubridServer> servers, String f) {
    synchronized (this) {
        XMLMemento memento = XMLMemento.createWriteRoot("hosts");
        Iterator<CubridServer> iterator = servers.iterator();
        while (iterator.hasNext()) {
            CubridServer server = (CubridServer) iterator.next();
            IXMLMemento child = memento.createChild("host");
            child.putString("id", server.getId());
            child.putString("name", server.getLabel());
            child.putString("port", String.valueOf(server.getMonPort()));
            child.putString("address", server.getHostAddress());
            child.putString("user", server.getUserName());
            //				String pwd = server.isAutoSavePassword() ? CipherUtils.encrypt(server.getPassword())
            //						: "";
            //				child.putString("password", pwd);
            //				child.putBoolean("savePassword", false);
            child.putString("jdbcDriver", server.getJdbcDriverVersion());
            if (server.getServerInfo() != null) {
                child.putInteger("soTimeOut", server.getServerInfo().getSoTimeOut());
            }
        }
        FileOutputStream fout = null;
        try {
            fout = new FileOutputStream(f);
            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) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) IOException(java.io.IOException)

Example 25 with IXMLMemento

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

the class DBParameter method loadDatabases.

/**
	 *
	 * Load added databases from workspace path
	 *
	 * @param workspacePath String
	 * @return boolean whether imported
	 */
public boolean loadDatabases(String workspacePath) {
    synchronized (this) {
        String settingPath = workspacePath + File.separator + ".metadata" + File.separator + ".plugins" + File.separator + "org.eclipse.core.runtime" + File.separator + ".settings" + File.separator;
        String serverPath = settingPath + File.separator + "com.cubrid.cubridmanager.ui.prefs";
        PreferenceStore preference = new PreferenceStore(serverPath);
        int size = databaseMap.size();
        try {
            preference.load();
            String xmlString = preference.getString(DATABASE_XML_CONTENT);
            if (xmlString == null || xmlString.trim().length() == 0) {
                return false;
            }
            ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
            IXMLMemento memento = XMLMemento.loadMemento(in);
            loadDatabases(memento);
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
        boolean isImported = size != databaseMap.size();
        if (isImported) {
            saveDatabases();
        }
        return isImported;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) IOException(java.io.IOException) PreferenceStore(org.eclipse.jface.preference.PreferenceStore)

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