Search in sources :

Example 96 with DatabaseInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo 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 97 with DatabaseInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.

the class ChangeShardAction method isSupported.

/**
	 * Return whether this action support this object,if not support,this action
	 * will be disabled
	 * 
	 * @param obj the Object
	 * @return <code>true</code> if support this obj;<code>false</code>
	 *         otherwise
	 */
public boolean isSupported(Object obj) {
    if (obj == null) {
        return false;
    }
    if (!(obj instanceof ICubridNode)) {
        return false;
    }
    ICubridNode cubridNode = (ICubridNode) obj;
    String nodeType = cubridNode.getType();
    if (!NodeType.DATABASE.equals(nodeType)) {
        return false;
    }
    ISchemaNode schemaNode = (ISchemaNode) cubridNode;
    DatabaseInfo dbInfo = schemaNode.getDatabase().getDatabaseInfo();
    if (!schemaNode.getDatabase().isLogined()) {
        return false;
    }
    if (!dbInfo.isShard()) {
        return false;
    }
    return true;
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 98 with DatabaseInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo 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 99 with DatabaseInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.

the class CQBDBNodePersistManager method isContainedByHostAddress.

/**
	 *
	 * Return whether this server has been existed and exclude this server
	 *
	 * @param address the ip address
	 * @param port the port
	 * @param server the CubridServer object
	 * @return <code>true</code> if contain this server;<code>false</code>
	 *         otherwise
	 */
public boolean isContainedByHostAddress(String address, String port, CubridDatabase server) {
    // FIXME extract
    for (int i = 0; i < databaseList.size(); i++) {
        CubridDatabase serv = databaseList.get(i);
        if (server != null && server.getId().equals(serv.getId())) {
            continue;
        }
        DatabaseInfo serverInfo = serv.getDatabaseInfo();
        if (serverInfo.getBrokerIP().equals(address) && serverInfo.getBrokerPort().equals(port)) {
            return true;
        }
    }
    return false;
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 100 with DatabaseInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.

the class CQBDBNodePersistManager method getConnectionInfo.

/**
	 * Retrives a connection information instance.
	 *
	 * @param database CubridDatabase
	 * @return ConnectionInfo
	 */
public ConnectionInfo getConnectionInfo(CubridDatabase database) {
    // FIXME extract
    DatabaseInfo dbInfo = database.getDatabaseInfo();
    String user = "";
    String password = "";
    if (dbInfo.getAuthLoginedDbUserInfo() != null) {
        user = dbInfo.getAuthLoginedDbUserInfo().getName();
        password = dbInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
    }
    String version = dbInfo.getServerInfo() == null ? "" : dbInfo.getServerInfo().getJdbcDriverVersion();
    String driverFileName = CubridJdbcManager.getInstance().getDriverFileByVersion(version);
    ConnectionInfo ci = new ConnectionInfo(database.getName(), dbInfo.getBrokerIP(), StringUtil.intValue(dbInfo.getBrokerPort(), -1), dbInfo.getDbName(), user, password, driverFileName, dbInfo.getCharSet());
    return ci;
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ConnectionInfo(com.cubrid.common.ui.common.persist.ConnectionInfo)

Aggregations

DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)188 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)79 ArrayList (java.util.ArrayList)45 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)35 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)31 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)30 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)30 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)25 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)24 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)24 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)23 ITask (com.cubrid.common.core.task.ITask)20 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)18 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)18 Map (java.util.Map)15 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)14 HashMap (java.util.HashMap)14 Composite (org.eclipse.swt.widgets.Composite)14 UpdateCMUserTask (com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask)13 GridLayout (org.eclipse.swt.layout.GridLayout)13