Search in sources :

Example 31 with DbUserInfo

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.

the class CubridDbUsersFolderLoader method formatUserList.

/**
	 * 
	 * Format user list
	 * 
	 * @param list the DbUserInfo list
	 */
private void formatUserList(List<DbUserInfo> list) {
    if (list == null || list.size() < 2) {
        return;
    }
    DbUserInfo dbaUser = null;
    DbUserInfo publicUser = null;
    for (DbUserInfo bean : list) {
        if (bean.getName().equalsIgnoreCase("public")) {
            publicUser = bean;
        }
        if (bean.getName().equalsIgnoreCase("dba")) {
            dbaUser = bean;
        }
    }
    list.remove(dbaUser);
    list.remove(publicUser);
    if (dbaUser == null || publicUser == null) {
        return;
    }
    Collections.sort(list, new Comparator<DbUserInfo>() {

        public int compare(DbUserInfo o1, DbUserInfo o2) {
            if (o1 == null || o2 == null || o1.getName() == null || o2.getName() == null) {
                return 0;
            }
            int cc = o1.getName().compareToIgnoreCase(o2.getName());
            return (cc < 0 ? -1 : cc > 0 ? 1 : 0);
        }
    });
    list.add(0, publicUser);
    list.add(0, dbaUser);
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)

Example 32 with DbUserInfo

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.

the class CQBDbUsersFolderLoader method formatUserList.

/**
	 *
	 * Format user list
	 *
	 * @param list the DbUserInfo list
	 */
private void formatUserList(List<DbUserInfo> list) {
    // FIXME extract
    if (list == null || list.size() < 2) {
        return;
    }
    DbUserInfo dbaUser = null;
    DbUserInfo publicUser = null;
    for (DbUserInfo bean : list) {
        if (bean.getName().equalsIgnoreCase("public")) {
            publicUser = bean;
        }
        if (bean.getName().equalsIgnoreCase("dba")) {
            dbaUser = bean;
        }
    }
    list.remove(dbaUser);
    list.remove(publicUser);
    if (dbaUser == null || publicUser == null) {
        return;
    }
    Collections.sort(list, new Comparator<DbUserInfo>() {

        public int compare(DbUserInfo o1, DbUserInfo o2) {
            if (o1 == null || o2 == null || o1.getName() == null || o2.getName() == null) {
                return 0;
            }
            int cc = o1.getName().compareToIgnoreCase(o2.getName());
            return (cc < 0 ? -1 : cc > 0 ? 1 : 0);
        }
    });
    list.add(0, publicUser);
    list.add(0, dbaUser);
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)

Example 33 with DbUserInfo

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.

the class CQBDbUsersFolderLoader method load.

/**
	 *
	 * Load children object for parent
	 *
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        CubridDatabase database = ((ISchemaNode) parent).getDatabase();
        if (database.getRunningType() == DbRunningType.STANDALONE) {
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        DbUserInfoList dbUserInfoList = new DbUserInfoList();
        GetUserListTask task = new GetUserListTask(database.getDatabaseInfo());
        parent.removeAllChild();
        try {
            dbUserInfoList = task.getResultModel();
        } catch (Exception e) {
            LOGGER.error("load user failed", e);
        }
        DbUserInfo latestDLoginedbUserInfo = databaseInfo.getAuthLoginedDbUserInfo();
        List<DbUserInfo> dbUserList = dbUserInfoList == null ? null : dbUserInfoList.getUserList();
        formatUserList(dbUserList);
        for (int i = 0; dbUserList != null && dbUserList.size() > i; i++) {
            DbUserInfo dbUserInfo = dbUserList.get(i);
            if (dbUserInfo.getName().equals(latestDLoginedbUserInfo.getName())) {
                dbUserInfo.setDbaAuthority(latestDLoginedbUserInfo.isDbaAuthority());
            // databaseInfo.setAuthLoginedDbUserInfo(dbUserInfo);
            }
            String id = parent.getId() + NODE_SEPARATOR + dbUserInfo.getName();
            ICubridNode dbUserInfoNode = new DefaultSchemaNode(id, dbUserInfo.getName(), "icons/navigator/user_item.png");
            dbUserInfoNode.setType(NodeType.USER);
            dbUserInfoNode.setModelObj(dbUserInfo);
            dbUserInfoNode.setContainer(false);
            dbUserInfoNode.setEditorId(CQBUserEditor.ID);
            parent.addChild(dbUserInfoNode);
        }
        databaseInfo.setDbUserInfoList(dbUserInfoList);
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 34 with DbUserInfo

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo 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 35 with DbUserInfo

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo 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)

Aggregations

DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)80 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)36 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)30 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)22 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)16 ArrayList (java.util.ArrayList)14 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)10 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)10 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)9 DbUserInfoList (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)8 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)7 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)6 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)6 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)6 IsDBAUserTask (com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask)6 CQBDbConnectionLoader (com.cubrid.cubridmanager.ui.spi.model.loader.CQBDbConnectionLoader)6 HashMap (java.util.HashMap)6 CubridNodeLoader (com.cubrid.common.ui.spi.model.CubridNodeLoader)5 UpdateCMUserTask (com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask)5