Search in sources :

Example 36 with DbUserInfo

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

the class CQBDatabaseFactory method modifyDatabaseByJDBCConnectInfo.

/**
	 * Modify the database by the jdbcconnectinfo
	 * s
	 * @param oldCon
	 * @param newCon
	 * @return
	 */
public static CubridDatabase modifyDatabaseByJDBCConnectInfo(IJDBCConnecInfo oldCon, IJDBCConnecInfo newCon) {
    if (oldCon == null || StringUtil.isEmpty(oldCon.getConName()) || newCon == null || StringUtil.isEmpty(newCon.getConName())) {
        return null;
    }
    String connName = newCon.getConName();
    if (!StringUtil.isEqual(oldCon.getConName(), newCon.getConName())) {
        connName = getUniqueName(newCon.getConName());
    }
    CubridDatabase database = CQBDatabaseFactory.getDatabaseJDBCConnectInfo(oldCon);
    if (database != null) {
        String newDBId = connName + ICubridNodeLoader.NODE_SEPARATOR + connName;
        database.setId(newDBId);
        database.setLabel(connName);
        if (!StringUtil.isEqualNotIgnoreNull(oldCon.getConName(), connName)) {
            if (database.getServer() != null) {
                database.getServer().setId(connName);
                database.getServer().setLabel(connName);
            }
        }
        if (database.getServer().getServerInfo() != null) {
            database.getServer().getServerInfo().setServerName(connName);
            database.getServer().getServerInfo().setHostAddress(newCon.getHost());
            database.getServer().getServerInfo().setUserName(newCon.getDbName() + "@" + newCon.getHost());
            if (StringUtil.isNotEmpty(newCon.getVersion())) {
                database.getServer().getServerInfo().setJdbcDriverVersion(newCon.getVersion());
            } else {
                try {
                    database.getServer().getServerInfo().setJdbcDriverVersion(JdbcClassLoaderFactory.getJdbcJarVersion(newCon.getDriverFileName()));
                } catch (IOException e) {
                //Ignore
                }
            }
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        if (databaseInfo != null) {
            databaseInfo.setBrokerIP(newCon.getHost());
            databaseInfo.setBrokerPort(String.valueOf(newCon.getPort()));
            databaseInfo.setCharSet(newCon.getCharset());
            databaseInfo.setJdbcAttrs(newCon.getJDBCAttrs());
            databaseInfo.setDbName(newCon.getDbName());
            DbUserInfo userInfo = databaseInfo.getAuthLoginedDbUserInfo();
            if (userInfo == null) {
                userInfo = new DbUserInfo();
            }
            userInfo.setDbName(newCon.getDbName());
            userInfo.setName(newCon.getConUser());
            userInfo.setNoEncryptPassword(newCon.getConPassword());
            databaseInfo.setAuthLoginedDbUserInfo(userInfo);
        }
    }
    return database;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) IOException(java.io.IOException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 37 with DbUserInfo

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

the class MultiQueryConnEditDialog method cloneMultiEditQueryConnInfo.

/**
	 * clone edit database
	 *
	 * @param cloneDB
	 * @return
	 */
public CubridDatabase cloneMultiEditQueryConnInfo(CubridDatabase cloneDB) {
    CubridDatabase newCubridDatabase = new CubridDatabase(cloneDB.getId(), cloneDB.getLabel());
    DatabaseInfo cloneDBInfo = cloneDB.getDatabaseInfo();
    ServerInfo cloneServerInfo = cloneDBInfo.getServerInfo();
    String databaseName = cloneDBInfo.getDbName();
    String brokerIp = cloneDBInfo.getBrokerIP();
    String brokerPort = cloneDBInfo.getBrokerPort();
    String userName = cloneDBInfo.getAuthLoginedDbUserInfo().getName();
    String userPassword = cloneDBInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
    String charset = cloneDBInfo.getCharSet();
    String jdbcAttrs = cloneDBInfo.getJdbcAttrs();
    String jdbcVersion = cloneServerInfo.getJdbcDriverVersion();
    ServerInfo newServerInfo = new ServerInfo();
    newServerInfo.setServerName(databaseName);
    newServerInfo.setHostAddress(brokerIp);
    newServerInfo.setHostMonPort(Integer.parseInt(brokerPort));
    newServerInfo.setHostJSPort(Integer.parseInt(brokerPort) + 1);
    newServerInfo.setUserName(databaseName + "@" + brokerIp);
    newServerInfo.setJdbcDriverVersion(jdbcVersion);
    DatabaseInfo newDBInfo = new DatabaseInfo(databaseName, newServerInfo);
    newDBInfo.setBrokerIP(brokerIp);
    newDBInfo.setBrokerPort(brokerPort);
    newDBInfo.setCharSet(charset);
    newDBInfo.setJdbcAttrs(jdbcAttrs);
    DbUserInfo newUserInfo = new DbUserInfo();
    newUserInfo.setDbName(databaseName);
    newUserInfo.setName(userName);
    newUserInfo.setNoEncryptPassword(userPassword);
    newDBInfo.setAuthLoginedDbUserInfo(newUserInfo);
    newCubridDatabase.setAutoSavePassword(cloneDB.isAutoSavePassword());
    newCubridDatabase.setServer(cloneDB.getServer());
    newCubridDatabase.setDatabaseInfo(newDBInfo);
    DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(cloneDB, false);
    if (editorConfig != null) {
        newCubridDatabase.setData(COMMENTKEY, editorConfig.getDatabaseComment());
    } else {
        newCubridDatabase.setData(COMMENTKEY, "");
    }
    return newCubridDatabase;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 38 with DbUserInfo

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

the class QueryConnDialog method buttonPressed.

/**
	 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
	 * @param buttonId the id of the button that was pressed (see
	 *        <code>IDialogConstants.*_ID</code> constants)
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == TEST_CONNECT_ID || buttonId == CONNECT_ID || buttonId == SAVE_ID) {
        String name = queryConnNameText.getText();
        String dbName = connectionComp.getDatabaseText().getText();
        String brokerIp = connectionComp.getBrokerIpText().getText();
        String brokerPort = connectionComp.getBrokerPortText().getText();
        String userName = connectionComp.getUserNameText().getText();
        String password = connectionComp.getPasswordText().getText();
        String charset = connectionComp.getCharsetCombo().getText();
        String jdbcDriver = connectionComp.getJdbcCombo().getText();
        String jdbcAttrs = connectionComp.getAttrText().getText().trim();
        boolean isAutoCommit = connectionComp.isAutoCommit();
        // [TOOLS-2425]Support shard broker
        boolean isShard = connectionComp.getBtnShard().getSelection();
        int currentShardId = connectionComp.getCurShardId();
        int currentShardVal = connectionComp.getCurShardVal();
        int defaultShardQueryType = connectionComp.getShardQueryType();
        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);
        DatabaseInfo dbInfo = new DatabaseInfo(dbName, serverInfo);
        dbInfo.setBrokerIP(brokerIp);
        dbInfo.setBrokerPort(brokerPort);
        dbInfo.setCharSet(charset);
        dbInfo.setJdbcAttrs(jdbcAttrs);
        // [TOOLS-2425]Support shard broker
        dbInfo.setShard(isShard);
        dbInfo.setCurrentShardId(currentShardId);
        dbInfo.setCurrentShardVal(currentShardVal);
        dbInfo.setShardQueryType(defaultShardQueryType);
        DbUserInfo userInfo = new DbUserInfo();
        userInfo.setDbName(dbName);
        userInfo.setName(userName);
        userInfo.setNoEncryptPassword(password);
        dbInfo.setAuthLoginedDbUserInfo(userInfo);
        if (buttonId == TEST_CONNECT_ID || buttonId == CONNECT_ID) {
            TaskExecutor taskExcutor = new ConnectDatabaseExecutor(dbInfo);
            new ExecTaskWithProgress(taskExcutor).exec();
            if (!taskExcutor.isSuccess()) {
                return;
            }
            if (buttonId == TEST_CONNECT_ID) {
                CommonUITool.openInformationBox(Messages.titleSuccess, Messages.msgTestConnSuccess);
                return;
            }
        }
        if (buttonId == CONNECT_ID) {
            // check whether dba authorization
            IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
            checkTask.execute();
            userInfo.setDbaAuthority(checkTask.isDBAUser());
            dbInfo.setRunningType(DbRunningType.CS);
            dbInfo.getServerInfo().setConnected(true);
            dbInfo.setLogined(true);
            boolean userChanged = !name.equals(oldLoginUserName);
            fireLogoutEvent = oldDatabaseIsLogin && userChanged;
        }
        if (!isNewQueryConn && database != null) {
            boolean isContinue = CQBConnectionUtils.processConnectionLogout(database);
            if (!isContinue) {
                return;
            }
        }
        // If this is new connection,then warning charset setting
        if (isNewQueryConn) {
            boolean sureCharset = CommonUITool.openConfirmBox(Messages.bind(com.cubrid.cubridquery.ui.connection.Messages.msgConfirmCharset, charset));
            if (!sureCharset) {
                connectionComp.getCharsetCombo().setFocus();
                return;
            }
        }
        if (isNewQueryConn && (buttonId == CONNECT_ID || buttonId == SAVE_ID) && EditorConstance.getDefaultBackground().equals(getSelectedBackground())) {
            boolean surePurpose = CommonUITool.openConfirmBox(Messages.msgUseDefaultPurpose);
            if (!surePurpose) {
                selectColorCombo.expandMenu();
                return;
            }
        }
        CubridServer server = new CubridServer(name, name, null, null);
        server.setServerInfo(serverInfo);
        server.setType(NodeType.SERVER);
        String dbId = name + ICubridNodeLoader.NODE_SEPARATOR + name;
        if (isNewQueryConn) {
            database = new CubridDatabase(dbId, name);
        } else {
            database.setId(dbId);
            database.setLabel(name);
        }
        database.setDatabaseInfo(dbInfo);
        database.setServer(server);
        database.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
        database.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
        CubridNodeLoader loader = new CQBDbConnectionLoader();
        loader.setLevel(ICubridNodeLoader.FIRST_LEVEL);
        database.setLoader(loader);
        database.setAutoSavePassword(connectionComp.isAutoSavePassword());
        if (buttonId == CONNECT_ID || buttonId == SAVE_ID) {
            if (database != null) {
                DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, false);
                if (editorConfig == null) {
                    editorConfig = new DatabaseEditorConfig();
                }
                editorConfig.setBackGround(getSelectedBackground());
                editorConfig.setDatabaseComment(getDatabaseComment());
                QueryOptions.putEditorConfig(database, editorConfig, false);
            }
            newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
            if (isNewQueryConn) {
                CQBDBNodePersistManager.getInstance().fireAddDatabase(database);
            } else if (oldInfo != null) {
                CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
            }
        }
        QueryOptions.setAutoCommit(serverInfo, isAutoCommit);
    }
    setReturnCode(buttonId);
    close();
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) 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) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) IsDBAUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask) ConnectDatabaseExecutor(com.cubrid.common.ui.spi.util.ConnectDatabaseExecutor) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 39 with DbUserInfo

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

the class CubridTitleLineContrItem method getTitleForNavigator.

/**
	 * 
	 * Get title of CUBRID Query application for navigator
	 * 
	 * @param cubridNode the ICubridNode object
	 * @return String
	 */
protected String getTitleForNavigator(ICubridNode cubridNode) {
    if (cubridNode == null) {
        return "";
    }
    StringBuffer titleStrBuffer = new StringBuffer();
    if (cubridNode instanceof ISchemaNode) {
        ISchemaNode schemaNode = (ISchemaNode) cubridNode;
        CubridDatabase database = schemaNode.getDatabase();
        if (database != null) {
            titleStrBuffer.append(database.getLabel() + " / ");
        }
        DatabaseInfo dbInfo = database == null ? null : database.getDatabaseInfo();
        if (dbInfo == null) {
            return "";
        }
        StringBuffer dbInfoStrBuffer = new StringBuffer();
        DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
        if (dbUserInfo == null || dbUserInfo.getName() == null || dbUserInfo.getName().trim().length() == 0) {
            dbInfoStrBuffer.append(dbInfo.getDbName());
        } else {
            dbInfoStrBuffer.append(dbUserInfo.getName() + "@" + dbInfo.getDbName());
        }
        String brokerPort = dbInfo.getBrokerPort();
        if (brokerPort != null && brokerPort.trim().length() > 0) {
            dbInfoStrBuffer.append(":").append(brokerPort);
        }
        String charset = dbInfo.getCharSet();
        if (charset != null && charset.trim().length() > 0) {
            dbInfoStrBuffer.append(":charset=").append(charset);
        }
        titleStrBuffer.append(dbInfoStrBuffer);
    } else {
        titleStrBuffer.append(cubridNode.getLabel());
    }
    return titleStrBuffer.toString();
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 40 with DbUserInfo

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

the class LoginQueryEditorDialog method buttonPressed.

/**
	 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
	 * @param buttonId the id of the button that was pressed (see
	 *        <code>IDialogConstants.*_ID</code> constants)
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == TEST_CONNECT_ID || buttonId == IDialogConstants.OK_ID) {
        String dbName = connectionComp.getDatabaseText().getText();
        String brokerIp = connectionComp.getBrokerIpText().getText();
        String brokerPort = connectionComp.getBrokerPortText().getText();
        String userName = connectionComp.getUserNameText().getText();
        String password = connectionComp.getPasswordText().getText();
        String charset = connectionComp.getCharsetCombo().getText();
        String jdbcDriver = connectionComp.getJdbcCombo().getText();
        String jdbcAttrs = connectionComp.getAttrText().getText().trim();
        boolean isShard = connectionComp.getBtnShard().getSelection();
        int currentShardId = connectionComp.getCurShardId();
        ServerInfo serverInfo = new ServerInfo();
        serverInfo.setServerName(DatabaseNavigatorMenu.SELF_DATABASE_ID);
        serverInfo.setHostAddress(brokerIp);
        serverInfo.setHostMonPort(Integer.parseInt(brokerPort));
        serverInfo.setHostJSPort(Integer.parseInt(brokerPort) + 1);
        serverInfo.setJdbcDriverVersion(jdbcDriver);
        DatabaseInfo dbInfo = new DatabaseInfo(dbName, serverInfo);
        dbInfo.setBrokerIP(brokerIp);
        dbInfo.setBrokerPort(brokerPort);
        dbInfo.setCharSet(charset);
        dbInfo.setJdbcAttrs(jdbcAttrs);
        dbInfo.setShard(isShard);
        dbInfo.setCurrentShardId(currentShardId);
        DbUserInfo userInfo = new DbUserInfo();
        userInfo.setDbName(dbName);
        userInfo.setName(userName);
        userInfo.setNoEncryptPassword(password);
        dbInfo.setAuthLoginedDbUserInfo(userInfo);
        TaskExecutor taskExcutor = new ConnectDatabaseExecutor(dbInfo);
        new ExecTaskWithProgress(taskExcutor).exec();
        if (!taskExcutor.isSuccess()) {
            return;
        }
        if (buttonId == TEST_CONNECT_ID) {
            CommonUITool.openInformationBox(com.cubrid.cubridquery.ui.connection.Messages.titleSuccess, com.cubrid.cubridquery.ui.connection.Messages.msgTestConnSuccess);
            return;
        }
        // check whether dba authorization
        IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
        checkTask.execute();
        userInfo.setDbaAuthority(checkTask.isDBAUser());
        dbInfo.setLogined(true);
        dbInfo.setRunningType(DbRunningType.CS);
        dbInfo.getServerInfo().setConnected(true);
        dbInfo.setLogined(true);
        CubridServer server = new CubridServer(DatabaseNavigatorMenu.SELF_DATABASE_ID, DatabaseNavigatorMenu.SELF_DATABASE_SELECTED_LABEL, null, null);
        server.setServerInfo(serverInfo);
        server.setType(NodeType.SERVER);
        DatabaseNavigatorMenu.SELF_DATABASE.setDatabaseInfo(dbInfo);
        DatabaseNavigatorMenu.SELF_DATABASE.setServer(server);
        DatabaseNavigatorMenu.SELF_DATABASE.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
        DatabaseNavigatorMenu.SELF_DATABASE.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
        DatabaseNavigatorMenu.SELF_DATABASE.setLoader(new CQBDbConnectionLoader());
    }
    super.buttonPressed(buttonId);
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CQBDbConnectionLoader(com.cubrid.cubridmanager.ui.spi.model.loader.CQBDbConnectionLoader) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) IsDBAUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask) ConnectDatabaseExecutor(com.cubrid.common.ui.spi.util.ConnectDatabaseExecutor) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

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