Search in sources :

Example 26 with DatabaseEditorConfig

use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.

the class NavigatorTreeLabelProvider method getText.

public String getText(Object element) {
    if (element instanceof ICubridNode) {
        if (element instanceof CubridDatabase) {
            CubridDatabase database = (CubridDatabase) element;
            StringBuffer sbLabel = new StringBuffer();
            sbLabel.append(((ICubridNode) element).getLabel());
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, false);
            if (editorConfig != null && editorConfig.getDatabaseComment() != null && editorConfig.getDatabaseComment().length() > 0) {
                sbLabel.append("(").append(editorConfig.getDatabaseComment()).append(")");
                // [TOOLS-2425]Support shard broker
                DatabaseInfo dbInfo = database.getDatabaseInfo();
                if (dbInfo != null && dbInfo.isShard()) {
                    if (dbInfo.getShardQueryType() == DatabaseInfo.SHARD_QUERY_TYPE_ID) {
                        sbLabel.append("[SHARD-ID:").append(dbInfo.getCurrentShardId()).append("]");
                    } else {
                        sbLabel.append("[SHARD-VAL:").append(dbInfo.getCurrentShardVal()).append("]");
                    }
                }
                return sbLabel.toString();
            }
        }
        return ((ICubridNode) element).getLabel();
    } else if (element instanceof PendingUpdateAdapter) {
        return Messages.msgLoading;
    }
    return element == null ? "" : element.toString();
}
Also used : PendingUpdateAdapter(org.eclipse.ui.progress.PendingUpdateAdapter) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 27 with DatabaseEditorConfig

use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.

the class CQBDBNodePersistManager method parseDatabaseFromXML.

public List<CubridDatabase> parseDatabaseFromXML(File file) {
    // FIXME extract?
    List<CubridDatabase> list = new ArrayList<CubridDatabase>();
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(file);
        IXMLMemento xmlContent = XMLMemento.loadMemento(fis);
        IXMLMemento[] children = xmlContent == null ? null : xmlContent.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 brokerIp = children[i].getString("brokerIp");
            String brokerPort = children[i].getString("brokerPort");
            String charset = children[i].getString("charset");
            String jdbcAttrs = children[i].getString("jdbcAttrs");
            String dbUser = children[i].getString("dbUser");
            String dbPassword = children[i].getString("dbPassword");
            boolean savePassword = children[i].getBoolean("savePassword");
            String jdbcDriver = children[i].getString("jdbcDriver");
            // [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);
            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;
            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"));
            }
            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);
            /*Save DatabaseEditorConfig to database object*/
            if (editorConfig != null) {
                database.setData(CubridDatabase.DATA_KEY_EDITOR_CONFIG, editorConfig);
            }
            list.add(database);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        FileUtil.close(fis);
    }
    return list;
}
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) ArrayList(java.util.ArrayList) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) CubridNodeLoader(com.cubrid.common.ui.spi.model.CubridNodeLoader) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) RGB(org.eclipse.swt.graphics.RGB) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) 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 28 with DatabaseEditorConfig

use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig 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

DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)28 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)19 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)12 RGB (org.eclipse.swt.graphics.RGB)11 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)9 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)6 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)6 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)6 TreeViewer (org.eclipse.jface.viewers.TreeViewer)6 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)5 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)5 CubridNodeLoader (com.cubrid.common.ui.spi.model.CubridNodeLoader)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)3 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)3 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 SelectColorCombo (com.cubrid.common.ui.common.control.SelectColorCombo)2 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)2 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)2