Search in sources :

Example 51 with DbUserInfo

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

the class CubridWorkbenchContrItem method connectDatabase.

/**
	 *
	 * Connect the database
	 *
	 * @param dbInfo DatabaseInfo
	 * @return boolean
	 */
public static boolean connectDatabase(DatabaseInfo dbInfo) {
    // FIXME extract
    if (dbInfo == null || dbInfo.getServerInfo() == null) {
        return false;
    }
    Map<String, String> jdbcVersionMap = CubridJdbcManager.getInstance().getLoadedJdbc();
    if (jdbcVersionMap == null || jdbcVersionMap.get(dbInfo.getServerInfo().getJdbcDriverVersion()) == null) {
        return false;
    }
    CUBRIDConnectionProxy connection = null;
    try {
        connection = (CUBRIDConnectionProxy) JDBCConnectionManager.getConnection(dbInfo, false);
        DbUserInfo userInfo = dbInfo.getAuthLoginedDbUserInfo();
        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);
        return true;
    } catch (SQLException e) {
        CommonUITool.openErrorBox(Messages.bind(Messages.errCommonTip, e.getErrorCode(), e.getMessage()));
        return false;
    } catch (Exception e) {
        CommonUITool.openErrorBox(e.getMessage());
        return false;
    } finally {
        if (connection != null) {
            try {
                connection.close();
                connection = null;
            } catch (SQLException e) {
                connection = null;
            }
        }
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) SQLException(java.sql.SQLException) IsDBAUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask) CUBRIDConnectionProxy(com.cubrid.jdbc.proxy.driver.CUBRIDConnectionProxy) SQLException(java.sql.SQLException) PartInitException(org.eclipse.ui.PartInitException)

Example 52 with DbUserInfo

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

the class CubridStatusLineContrItem method updateStatusLine.

/**
	 *
	 * Update the status line information
	 *
	 * @param statusLineManager StatusLineManager
	 * @param cubridNode The selected ICubridNode object
	 */
protected void updateStatusLine(StatusLineManager statusLineManager, ICubridNode cubridNode) {
    clearStatusLine();
    updateStatusLineForRestoreQueryEditor();
    if (cubridNode == null || cubridNode.getServer() == null || cubridNode.getServer().getServerInfo() == null) {
        return;
    }
    String serverInfoStr = cubridNode.getServer().getLabel();
    if (!DatabaseNavigatorMenu.SELF_DATABASE_ID.equals(cubridNode.getId())) {
        ServerUserInfo userInfo = cubridNode.getServer().getServerInfo().getLoginedUserInfo();
        if (userInfo != null && userInfo.getUserName() != null && userInfo.getUserName().trim().length() > 0) {
            serverInfoStr = userInfo.getUserName() + "@" + serverInfoStr;
        }
        String monPort = cubridNode.getServer().getMonPort();
        if (monPort != null && monPort.trim().length() > 0) {
            serverInfoStr = serverInfoStr + ":" + monPort;
        }
    }
    StringBuffer dbInfoStrBuffer = new StringBuffer();
    if (cubridNode instanceof ISchemaNode) {
        ISchemaNode schemaNode = (ISchemaNode) cubridNode;
        CubridDatabase database = schemaNode.getDatabase();
        dbInfoStrBuffer.append(database.getDatabaseInfo().getDbName());
        DbUserInfo dbUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
        if (database.isLogined() && dbUserInfo != null && dbUserInfo.getName() != null && dbUserInfo.getName().trim().length() > 0) {
            dbInfoStrBuffer = new StringBuffer(dbUserInfo.getName() + "@" + dbInfoStrBuffer.toString());
        }
        String brokerPort = QueryOptions.getBrokerPort(database.getDatabaseInfo());
        BrokerInfos brokerInfos = database.getServer().getServerInfo().getBrokerInfos();
        List<BrokerInfo> brokerInfoList = brokerInfos == null || brokerInfos.getBorkerInfoList() == null ? null : brokerInfos.getBorkerInfoList().getBrokerInfoList();
        boolean isExist = false;
        for (int i = 0; brokerInfoList != null && i < brokerInfoList.size(); i++) {
            BrokerInfo brokerInfo = brokerInfoList.get(i);
            if (brokerPort == null || brokerInfo.getPort() == null || brokerInfo.getPort().trim().length() == 0 || !brokerPort.equals(brokerInfo.getPort())) {
                continue;
            }
            if (brokerPort.equals(brokerInfo.getPort())) {
                isExist = true;
                String status = brokerInfo.getState() == null || brokerInfo.getState().trim().equalsIgnoreCase("OFF") ? "OFF" : "ON";
                String text = brokerInfo.getName() + "[" + brokerInfo.getPort() + "/" + status + "]";
                dbInfoStrBuffer.append(":").append(text);
                break;
            }
        }
        if (!isExist && brokerPort != null && brokerPort.trim().length() > 0) {
            dbInfoStrBuffer.append(":").append(brokerPort);
        }
        String charset = database.getDatabaseInfo().getCharSet();
        if (charset != null && charset.trim().length() > 0) {
            dbInfoStrBuffer.append(":charset=").append(charset);
        }
    }
    String numberStr = getChilderenNumStr(cubridNode);
    if (numberStr != null && numberStr.length() > 0) {
        StatusLineContributionItem item = new StatusLineContributionItem(OBJ_NUM_INFO_CONTR_ID, numberStr.length() + 4);
        statusLineManager.add(item);
        item.setText(numberStr);
    }
    int addedWidth = 3;
    if (dbInfoStrBuffer == null || dbInfoStrBuffer.length() == 0) {
        addedWidth = 30;
    }
    StatusLineContributionItem item = new StatusLineContributionItem(SERVER_INFO_CONTR_ID, serverInfoStr.length() + addedWidth);
    statusLineManager.add(item);
    item.setText(serverInfoStr);
    if (dbInfoStrBuffer != null && dbInfoStrBuffer.length() > 0) {
        item = new StatusLineContributionItem(DB_INFO_CONTR_ID, dbInfoStrBuffer.length() + 3);
        statusLineManager.add(item);
        item.setText(dbInfoStrBuffer.toString());
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) StatusLineContributionItem(org.eclipse.jface.action.StatusLineContributionItem) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) BrokerInfo(com.cubrid.cubridmanager.core.broker.model.BrokerInfo)

Example 53 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 manager application for navigator
	 * 
	 * @param cubridNode the ICubridNode object
	 * @return the title
	 */
protected String getTitleForNavigator(ICubridNode cubridNode) {
    if (cubridNode == null) {
        return "";
    }
    String title = cubridNode.getLabel();
    CubridServer server = cubridNode.getServer();
    String serverTitle = server == null ? null : server.getLabel();
    if (server != null && server.isConnected()) {
        ServerInfo serverInfo = server.getServerInfo();
        ServerUserInfo userInfo = serverInfo == null ? null : serverInfo.getLoginedUserInfo();
        if (userInfo != null && userInfo.getUserName() != null && userInfo.getUserName().trim().length() > 0) {
            serverTitle = userInfo.getUserName() + "@" + serverTitle;
        }
        String monPort = server.getMonPort();
        if (monPort != null && monPort.trim().length() > 0) {
            serverTitle = serverTitle + ":" + monPort;
        }
    }
    StringBuffer dbTitleBuffer = new StringBuffer("");
    CubridDatabase database = cubridNode instanceof ISchemaNode ? ((ISchemaNode) cubridNode).getDatabase() : null;
    if (database != null && database.getDatabaseInfo() != null) {
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
        String userName = dbUserInfo == null ? null : dbUserInfo.getName();
        dbTitleBuffer = (userName != null && userName.trim().length() > 0) ? dbTitleBuffer.append(userName).append("@").append(dbInfo.getDbName()) : dbTitleBuffer;
        String brokerPort = QueryOptions.getBrokerPort(dbInfo);
        BrokerInfos brokerInfos = database.getServer().getServerInfo().getBrokerInfos();
        List<BrokerInfo> brokerInfoList = brokerInfos == null || brokerInfos.getBorkerInfoList() == null ? null : brokerInfos.getBorkerInfoList().getBrokerInfoList();
        boolean isExist = false;
        for (int i = 0; brokerInfoList != null && i < brokerInfoList.size(); i++) {
            BrokerInfo brokerInfo = brokerInfoList.get(i);
            if (brokerPort != null && brokerPort.equals(brokerInfo.getPort())) {
                isExist = true;
                String status = brokerInfo.getState() == null || brokerInfo.getState().trim().equalsIgnoreCase("OFF") ? "OFF" : "ON";
                String text = brokerInfo.getName() + "[" + brokerInfo.getPort() + "/" + status + "]";
                dbTitleBuffer.append(":").append(text);
                break;
            }
        }
        if (!isExist && brokerPort != null && brokerPort.trim().length() > 0) {
            dbTitleBuffer.append(":").append(brokerPort);
        }
        String charset = database.getDatabaseInfo().getCharSet();
        if (charset != null && charset.trim().length() > 0) {
            dbTitleBuffer.append(":charset=").append(charset);
        }
    }
    if (serverTitle != null && serverTitle.trim().length() > 0) {
        title = serverTitle;
    }
    if (dbTitleBuffer != null && dbTitleBuffer.toString().trim().length() > 0) {
        title = serverTitle + " / " + dbTitleBuffer.toString();
    }
    return title;
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) BrokerInfo(com.cubrid.cubridmanager.core.broker.model.BrokerInfo) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 54 with DbUserInfo

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

the class CubridDatabasesFolderLoader method buildDatabasesFolder.

/**
	 * Construct the database folder children
	 *
	 * @param parent the database folder node
	 * @param monitor the IProgressMonitor
	 * @param serverInfo the ServerInfo
	 * @param oldDatabaseInfoList the old database information list
	 * @param newDatabaseInfoList the new database information list
	 * @param oldNodeList the old node list
	 */
private void buildDatabasesFolder(ICubridNode parent, final IProgressMonitor monitor, ServerInfo serverInfo, List<DatabaseInfo> oldDatabaseInfoList, List<DatabaseInfo> newDatabaseInfoList, List<ICubridNode> oldNodeList) {
    ServerUserInfo userInfo = serverInfo.getLoginedUserInfo();
    List<DatabaseInfo> authorDatabaseList = userInfo.getDatabaseInfoList();
    if (authorDatabaseList == null) {
        authorDatabaseList = new ArrayList<DatabaseInfo>();
        userInfo.setDatabaseInfoList(authorDatabaseList);
    }
    filterDatabaseList(serverInfo, newDatabaseInfoList, authorDatabaseList);
    for (int i = 0; i < authorDatabaseList.size() && !monitor.isCanceled(); i++) {
        DatabaseInfo databaseInfo = authorDatabaseList.get(i);
        DatabaseInfo newDatabaseInfo = getDatabaseInfo(newDatabaseInfoList, databaseInfo.getDbName());
        if (newDatabaseInfo == null) {
            continue;
        } else {
            databaseInfo.setDbDir(newDatabaseInfo.getDbDir());
            databaseInfo.setRunningType(newDatabaseInfo.getRunningType());
            newDatabaseInfo = getDatabaseInfo(oldDatabaseInfoList, databaseInfo.getDbName());
            if (newDatabaseInfo != null) {
                DbUserInfo dbUserInfo = newDatabaseInfo.getAuthLoginedDbUserInfo();
                if (dbUserInfo != null && databaseInfo.getAuthLoginedDbUserInfo() != null) {
                    databaseInfo.getAuthLoginedDbUserInfo().setNoEncryptPassword(dbUserInfo.getNoEncryptPassword());
                }
            }
        }
        String name = databaseInfo.getDbName();
        String id = parent.getId() + NODE_SEPARATOR + name;
        ICubridNode databaseNode = isContained(oldNodeList, id);
        if (databaseNode == null) {
            databaseNode = new CubridDatabase(id, databaseInfo.getDbName());
            CubridDatabase database = (CubridDatabase) databaseNode;
            database.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
            database.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
            database.setStopAndLogoutIconPath("icons/navigator/database_stop_disconnected.png");
            database.setStopAndLoginIconPath("icons/navigator/database_stop_connected.png");
            ICubridNodeLoader loader = new CubridDatabaseLoader();
            loader.setLevel(getLevel());
            databaseNode.setLoader(loader);
            parent.addChild(databaseNode);
            if (getLevel() == DEFINITE_LEVEL) {
                databaseNode.getChildren(monitor);
            }
            databaseNode.setEditorId(DatabaseDashboardEditor.ID);
            ((CubridDatabase) databaseNode).setDatabaseInfo(databaseInfo);
            databaseNode.setContainer(true);
            ((CubridDatabase) databaseNode).setAutoSavePassword(CMDBNodePersistManager.getInstance().getDbSavePassword(serverInfo.getHostAddress(), String.valueOf(serverInfo.getHostMonPort()), databaseInfo.getDbName(), databaseInfo.getAuthLoginedDbUserInfo().getName()));
            String jdbcAttrs = CMDBNodePersistManager.getInstance().getJdbcAttrs((CubridDatabase) databaseNode);
            databaseInfo.setJdbcAttrs(jdbcAttrs);
        } else {
            parent.addChild(databaseNode);
            databaseInfo.setLogined(((CubridDatabase) databaseNode).isLogined());
            ((CubridDatabase) databaseNode).setDatabaseInfo(databaseInfo);
            if (databaseNode.getLoader() != null && databaseNode.getLoader().isLoaded()) {
                databaseNode.getLoader().setLoaded(false);
                databaseNode.getChildren(monitor);
            }
        }
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 55 with DbUserInfo

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

the class CubridDbUsersFolderLoader 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();
        final CommonQueryTask<DbUserInfoList> task = new CommonQueryTask<DbUserInfoList>(parent.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), dbUserInfoList, database.getDatabaseInfo().getCharSet());
        task.setDbName(database.getLabel());
        monitorCancel(monitor, new ITask[] { task });
        task.execute();
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            openErrorBox(errorMsg);
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        parent.removeAllChild();
        dbUserInfoList = task.getResultModel();
        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(CubridNodeType.USER);
            dbUserInfoNode.setModelObj(dbUserInfo);
            dbUserInfoNode.setContainer(false);
            dbUserInfoNode.setEditorId(UserEditor.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) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

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