Search in sources :

Example 91 with DatabaseInfo

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

the class CubridDatabasesFolderLoader 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;
        }
        ServerInfo serverInfo = parent.getServer().getServerInfo();
        final GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
        final GetCMUserListTask getUserInfoTask = new GetCMUserListTask(serverInfo);
        monitorCancel(monitor, new ITask[] { getUserInfoTask, getDatabaseListTask });
        getUserInfoTask.execute();
        final String msg1 = getUserInfoTask.getErrorMsg();
        if (!monitor.isCanceled() && msg1 != null && msg1.trim().length() > 0) {
            parent.removeAllChild();
            openErrorBox(msg1);
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        List<ServerUserInfo> serverUserInfoList = getUserInfoTask.getServerUserInfoList();
        List<DatabaseInfo> oldDatabaseInfoList = null;
        if (serverInfo.getLoginedUserInfo() != null) {
            oldDatabaseInfoList = serverInfo.getLoginedUserInfo().getDatabaseInfoList();
        }
        for (int i = 0; serverUserInfoList != null && i < serverUserInfoList.size(); i++) {
            ServerUserInfo userInfo = serverUserInfoList.get(i);
            if (userInfo != null && userInfo.getUserName().equals(serverInfo.getUserName())) {
                serverInfo.setLoginedUserInfo(userInfo);
                break;
            }
        }
        getDatabaseListTask.execute();
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        final String msg2 = getDatabaseListTask.getErrorMsg();
        if (!monitor.isCanceled() && msg2 != null && msg2.trim().length() > 0) {
            parent.removeAllChild();
            openErrorBox(msg2);
            setLoaded(true);
            return;
        }
        List<DatabaseInfo> newDatabaseInfoList = getDatabaseListTask.loadDatabaseInfo();
        List<ICubridNode> oldNodeList = new ArrayList<ICubridNode>();
        oldNodeList.addAll(parent.getChildren());
        parent.removeAllChild();
        //Construct the database folder children
        buildDatabasesFolder(parent, monitor, serverInfo, oldDatabaseInfoList, newDatabaseInfoList, oldNodeList);
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ArrayList(java.util.ArrayList) GetCMUserListTask(com.cubrid.cubridmanager.core.common.task.GetCMUserListTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 92 with DatabaseInfo

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

the class CubridDatabasesFolderLoader method filterDatabaseList.

/**
	 *
	 * Add or delete database for author database list
	 *
	 * @param serverInfo the server information
	 * @param databaseInfoList the database information list
	 * @param authorDatabaseList the authorize database list
	 * @return whether this authorDatabaseList is updated
	 */
public static boolean filterDatabaseList(ServerInfo serverInfo, List<DatabaseInfo> databaseInfoList, List<DatabaseInfo> authorDatabaseList) {
    if (databaseInfoList == null || authorDatabaseList == null) {
        return false;
    }
    boolean isUpdated = false;
    //Check the authorization database whether already deleted
    List<DatabaseInfo> deletedDbList = new ArrayList<DatabaseInfo>();
    for (int i = 0; i < authorDatabaseList.size(); i++) {
        DatabaseInfo databaseInfo = authorDatabaseList.get(i);
        if (databaseInfo == null) {
            continue;
        }
        DatabaseInfo dbInfo = getDatabaseInfo(databaseInfoList, databaseInfo.getDbName());
        if (dbInfo == null) {
            deletedDbList.add(databaseInfo);
            isUpdated = true;
        } else {
            databaseInfo.setDbDir(dbInfo.getDbDir());
            databaseInfo.setRunningType(dbInfo.getRunningType());
        }
    }
    List<DatabaseInfo> addedDbList = new ArrayList<DatabaseInfo>();
    boolean isAdminLogin = serverInfo.getLoginedUserInfo().isAdmin();
    //if user is admin,add all database to authorization database list
    if (isAdminLogin) {
        for (int i = 0; i < databaseInfoList.size(); i++) {
            DatabaseInfo databaseInfo = databaseInfoList.get(i);
            if (databaseInfo != null && getDatabaseInfo(authorDatabaseList, databaseInfo.getDbName()) == null) {
                addedDbList.add(databaseInfo);
                isUpdated = true;
            }
        }
    }
    authorDatabaseList.removeAll(deletedDbList);
    authorDatabaseList.addAll(addedDbList);
    // update the admin user the latest access broker port and IP
    if (isAdminLogin) {
        String defaultBrokerPort = getDefaultPort(serverInfo);
        for (int i = 0; i < authorDatabaseList.size(); i++) {
            DatabaseInfo databaseInfo = authorDatabaseList.get(i);
            String serverBrokerPort = databaseInfo.getBrokerPort();
            if (serverBrokerPort == null || serverBrokerPort.trim().length() == 0 || !isExistPort(serverInfo, serverBrokerPort)) {
                serverBrokerPort = defaultBrokerPort;
                isUpdated = true;
            }
            databaseInfo.setBrokerPort(serverBrokerPort);
            String localBrokerPort = QueryOptions.getBrokerPort(databaseInfo);
            if (localBrokerPort != null && localBrokerPort.trim().length() > 0 && !serverBrokerPort.equals(localBrokerPort) && isExistPort(serverInfo, localBrokerPort)) {
                databaseInfo.setBrokerPort(localBrokerPort);
                isUpdated = true;
            }
            String serverBrokerIp = databaseInfo.getBrokerIP();
            String localBrokerIp = QueryOptions.getBrokerIp(databaseInfo);
            if (!localBrokerIp.equals(serverBrokerIp)) {
                databaseInfo.setBrokerIP(localBrokerIp);
                isUpdated = true;
            }
            if (databaseInfo.getAuthLoginedDbUserInfo() == null) {
                DbUserInfo userInfo = new DbUserInfo(databaseInfo.getDbName(), "dba", "", "", true);
                databaseInfo.setAuthLoginedDbUserInfo(userInfo);
                isUpdated = true;
            }
        }
    }
    //Set charset and database ip from local preference file
    for (DatabaseInfo databaseInfo : authorDatabaseList) {
        databaseInfo.setCharSet(QueryOptions.getCharset(databaseInfo));
        DbUserInfo dbUserInfo = databaseInfo.getAuthLoginedDbUserInfo();
        if (dbUserInfo != null) {
            String password = CMDBNodePersistManager.getInstance().getDbPassword(serverInfo.getHostAddress(), String.valueOf(serverInfo.getHostMonPort()), databaseInfo.getDbName(), dbUserInfo.getName());
            dbUserInfo.setNoEncryptPassword(password);
        }
    }
    return isUpdated;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList)

Example 93 with DatabaseInfo

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

the class CubridDbSpaceFolderLoader 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();
        HashMap<String, FolderInformationContainer> foldersInformation;
        HashMap<String, ICubridNode> foldersHashMap = new HashMap<String, ICubridNode>();
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        CommonQueryTask<? extends DbSpaceInfoList> task;
        DbSpaceInfoList dbSpaceInfoList;
        if (DbSpaceInfoList.useOld(database.getDatabaseInfo().getServerInfo().getEnvInfo())) {
            foldersInformation = foldersInformationOldFormat;
            task = new CommonQueryTask<DbSpaceInfoListOld>(parent.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoListOld());
        } else {
            foldersInformation = foldersInformationNewFormat;
            task = new CommonQueryTask<DbSpaceInfoListNew>(parent.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoListNew());
        }
        for (Map.Entry<String, FolderInformationContainer> entry : foldersInformation.entrySet()) {
            String key = entry.getKey();
            FolderInformationContainer value = entry.getValue();
            ICubridNode folder = addFolder(parent, key, value.volumeFolderName, value.volumeFolder, value.type);
            foldersHashMap.put(value.volumeType, folder);
        }
        ICubridNode logFolder = addFolder(parent, LOG_VOLUME_FOLDER_ID, LOG_VOLUME_FOLDER_NAME, CubridNodeType.LOG_VOLUEM_FOLDER, null);
        foldersHashMap.put(VolumeType.ACTIVE_LOG.getText(), addFolder(logFolder, ACTIVE_LOG_FOLDER_ID, ACTIVE_LOG_FOLDER_NAME, CubridNodeType.ACTIVE_LOG_FOLDER, CubridNodeType.ACTIVE_LOG));
        foldersHashMap.put(VolumeType.ARCHIVE_LOG.getText(), addFolder(logFolder, ARCHIVE_LOG_FOLDER_ID, ARCHIVE_LOG_FOLDER_NAME, CubridNodeType.ARCHIVE_LOG_FOLDER, CubridNodeType.ARCHIVE_LOG));
        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) {
            for (ICubridNode folder : foldersHashMap.values()) {
                folder.removeAllChild();
            }
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    CommonUITool.openErrorBox(null, errorMsg);
                }
            });
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        for (ICubridNode folder : foldersHashMap.values()) {
            folder.removeAllChild();
        }
        dbSpaceInfoList = task.getResultModel();
        List<DbSpaceInfo> spaceInfoList = dbSpaceInfoList == null ? null : dbSpaceInfoList.getSpaceinfo();
        for (int i = 0; spaceInfoList != null && i < spaceInfoList.size(); i++) {
            DbSpaceInfo spaceInfo = spaceInfoList.get(i);
            ICubridNode volumeNode = new DefaultSchemaNode("", spaceInfo.getShortVolumeName(), "");
            volumeNode.setContainer(false);
            volumeNode.setModelObj(spaceInfo);
            volumeNode.setEditorId(VolumeInformationEditor.ID);
            String key = null;
            String type = spaceInfo.getType();
            if (spaceInfo.getPurpose() != null) {
                key = type + "_" + spaceInfo.getPurpose();
            } else {
                key = type;
            }
            if (type == null) {
                continue;
            }
            ICubridNode folder = foldersHashMap.get(key);
            if (folder != null) {
                String id = folder.getId() + NODE_SEPARATOR + spaceInfo.getShortVolumeName();
                volumeNode.setId(id);
                volumeNode.setType(folder.getType());
                volumeNode.setIconPath("icons/navigator/volume_item.png");
                folder.addChild(volumeNode);
            }
        }
        if (spaceInfoList != null && !spaceInfoList.isEmpty()) {
            for (ICubridNode folder : foldersHashMap.values()) {
                Collections.sort(folder.getChildren());
            }
        }
        databaseInfo.setDbSpaceInfoList(dbSpaceInfoList);
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) HashMap(java.util.HashMap) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DbSpaceInfoListOld(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoListOld) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) DbSpaceInfoListNew(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoListNew) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) DbSpaceInfo(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) HashMap(java.util.HashMap) Map(java.util.Map) Display(org.eclipse.swt.widgets.Display)

Example 94 with DatabaseInfo

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

the class CubridBackupPlanFolderLoader 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();
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        final GetBackupPlanListTask task = new GetBackupPlanListTask(parent.getServer().getServerInfo());
        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();
        List<BackupPlanInfo> backupPlanInfoList = task.getBackupPlanInfoList();
        if (backupPlanInfoList != null && !backupPlanInfoList.isEmpty()) {
            for (BackupPlanInfo backupPlanInfo : backupPlanInfoList) {
                String id = parent.getId() + NODE_SEPARATOR + backupPlanInfo.getBackupid();
                ICubridNode backupPlanInfoNode = new DefaultSchemaNode(id, backupPlanInfo.getBackupid(), "icons/navigator/auto_backup_item.png");
                backupPlanInfoNode.setContainer(false);
                backupPlanInfoNode.setType(CubridNodeType.BACKUP_PLAN);
                backupPlanInfoNode.setModelObj(backupPlanInfo);
                parent.addChild(backupPlanInfoNode);
            }
        }
        databaseInfo.setBackupPlanInfoList(backupPlanInfoList);
        Collections.sort(parent.getChildren());
        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) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) BackupPlanInfo(com.cubrid.cubridmanager.core.cubrid.jobauto.model.BackupPlanInfo) GetBackupPlanListTask(com.cubrid.cubridmanager.core.cubrid.jobauto.task.GetBackupPlanListTask)

Example 95 with DatabaseInfo

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

the class CubridDatabaseLogFolderLoader 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;
        }
        ServerInfo serverInfo = parent.getServer().getServerInfo();
        ServerUserInfo userInfo = serverInfo.getLoginedUserInfo();
        List<DatabaseInfo> databaseInfoList = userInfo.getDatabaseInfoList();
        if (databaseInfoList == null || databaseInfoList.size() <= 0) {
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        List<ICubridNode> oldNodeList = new ArrayList<ICubridNode>();
        oldNodeList.addAll(parent.getChildren());
        parent.removeAllChild();
        for (int i = 0; i < databaseInfoList.size() && !monitor.isCanceled(); i++) {
            DatabaseInfo databaseInfo = databaseInfoList.get(i);
            String id = parent.getId() + NODE_SEPARATOR + databaseInfo.getDbName();
            ICubridNode logDatabaseNode = isContained(oldNodeList, id);
            if (logDatabaseNode == null) {
                logDatabaseNode = new DefaultCubridNode(id, databaseInfo.getDbName(), "icons/navigator/folder.png");
                logDatabaseNode.setType(CubridNodeType.LOGS_SERVER_DATABASE_FOLDER);
                logDatabaseNode.setModelObj(databaseInfo);
                logDatabaseNode.setContainer(true);
                ICubridNodeLoader loader = new CubridDatabaseLogLoader();
                loader.setLevel(getLevel());
                logDatabaseNode.setLoader(loader);
                parent.addChild(logDatabaseNode);
                if (getLevel() == DEFINITE_LEVEL) {
                    logDatabaseNode.getChildren(monitor);
                }
            } else {
                parent.addChild(logDatabaseNode);
                if (logDatabaseNode.getLoader() != null && logDatabaseNode.getLoader().isLoaded()) {
                    logDatabaseNode.getLoader().setLoaded(false);
                    logDatabaseNode.getChildren(monitor);
                }
            }
        }
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : DefaultCubridNode(com.cubrid.common.ui.spi.model.DefaultCubridNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

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