Search in sources :

Example 1 with GetClassListTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetClassListTask in project cubrid-manager by CUBRID.

the class UnloadDatabaseAction method run.

public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    final CubridDatabase database = node.getDatabase();
    final UnloadDatabaseDialog dialog = new UnloadDatabaseDialog(getShell());
    dialog.setDatabase(database);
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(Messages.loadAllClassTaskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (task instanceof GetClassListTask) {
                    GetClassListTask getClassListTask = (GetClassListTask) task;
                    List<String> allUserClassList = new ArrayList<String>();
                    DBClasses dbClasses = getClassListTask.getDbClassInfo();
                    List<ClassItem> userClassList = dbClasses == null ? null : dbClasses.getUserClassList().getClassList();
                    if (userClassList != null && !userClassList.isEmpty()) {
                        for (ClassItem userClass : userClassList) {
                            allUserClassList.add(userClass.getClassname());
                        }
                    }
                    Collections.sort(allUserClassList);
                    dialog.setUserClassList(allUserClassList);
                }
            }
            return true;
        }
    };
    ServerInfo serverInfo = database.getServer().getServerInfo();
    GetClassListTask task = new GetClassListTask(serverInfo, database.getDatabaseInfo().getCharSet());
    task.setDbName(database.getLabel());
    task.setDbStatus(OnOffType.OFF);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (taskExcutor.isSuccess()) {
        dialog.open();
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ArrayList(java.util.ArrayList) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ClassItem(com.cubrid.cubridmanager.core.cubrid.table.model.ClassItem) GetClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetClassListTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) UnloadDatabaseDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.UnloadDatabaseDialog) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DBClasses(com.cubrid.cubridmanager.core.cubrid.table.model.DBClasses)

Example 2 with GetClassListTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetClassListTask in project cubrid-manager by CUBRID.

the class OptimizeAction method run.

public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    final CubridDatabase database = node.getDatabase();
    if (database == null) {
        CommonUITool.openErrorBox(getShell(), Messages.msgSelectDB);
        return;
    }
    OptimizeDialog dlg = new OptimizeDialog();
    GetClassListTask task = new GetClassListTask(database.getServer().getServerInfo(), database.getDatabaseInfo().getCharSet());
    task.setDbName(database.getName());
    if (database.getDatabaseInfo().getRunningType() == DbRunningType.STANDALONE) {
        task.setDbStatus(OnOffType.OFF);
    } else {
        task.setDbStatus(OnOffType.ON);
    }
    dlg.executeGetClassListTask(-1, task, true, getShell());
    if (task.getErrorMsg() != null || task.isCancel()) {
        return;
    }
    dlg.setDatabase(database);
    dlg.setUserClassList(task.getDbClassInfo().getUserClassList().getClassList());
    if (dlg.open() == DeleteDatabaseDialog.DELETE_ID) {
        ISelectionProvider provider = getSelectionProvider();
        if (provider instanceof TreeViewer) {
            TreeViewer treeViewer = (TreeViewer) provider;
            CommonUITool.refreshNavigatorTree(treeViewer, database.getParent());
            setEnabled(false);
        }
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) GetClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetClassListTask) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) OptimizeDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.OptimizeDialog)

Example 3 with GetClassListTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetClassListTask in project cubrid-manager by CUBRID.

the class GetAllClassesTaskExecutor method init.

/**
	 * initialize some values
	 */
private void init() {
    ServerInfo serverInfo = new ServerInfo();
    boolean isConnected = ServerManager.getInstance().isConnected(ip, Integer.parseInt(port), userName);
    DatabaseInfo dbInfo = null;
    OnOffType status = OnOffType.OFF;
    if (isConnected) {
        serverInfo = CMHostNodePersistManager.getInstance().getServerInfo(ip, Integer.parseInt(port), userName);
        dbInfo = serverInfo.getLoginedUserInfo().getDatabaseInfo(dbName);
        if (dbInfo.getRunningType() == DbRunningType.CS) {
            status = OnOffType.ON;
        }
    } else {
        serverInfo.setHostAddress(ip);
        serverInfo.setHostMonPort(Integer.parseInt(port));
        serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
        serverInfo.setUserName(userName);
        serverInfo.setUserPassword(password);
        CMHostNodePersistManager.getInstance().addServer(ip, Integer.parseInt(port), userName, serverInfo);
        MonitoringTask monitoringTask = new MonitoringTask(serverInfo);
        addTask(monitoringTask);
        GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
        addTask(getDatabaseListTask);
        GetCMUserListTask getUserInfoTask = new GetCMUserListTask(serverInfo);
        addTask(getUserInfoTask);
    }
    if (dbInfo == null || (dbInfo != null && !dbInfo.isLogined())) {
        LoginDatabaseTask loginDbTask = new LoginDatabaseTask(serverInfo);
        loginDbTask.setCMUser("admin");
        loginDbTask.setDbName(dbName);
        loginDbTask.setDbUser("dba");
        loginDbTask.setDbPassword(dbaPassword);
        addTask(loginDbTask);
        UpdateCMUserTask updateCMUserTask = new UpdateCMUserTask(serverInfo);
        updateCMUserTask.setCmUserName("admin");
        updateCMUserTask.setCasAuth(CasAuthType.AUTH_ADMIN.getText());
        updateCMUserTask.setDbCreator(DbCreateAuthType.AUTH_ADMIN.getText());
        updateCMUserTask.setStatusMonitorAuth(StatusMonitorAuthType.AUTH_ADMIN.getText());
        addTask(updateCMUserTask);
    }
    GetClassListTask getClassListTask = new GetClassListTask(serverInfo);
    getClassListTask.setDbName(dbName);
    getClassListTask.setDbStatus(status);
    addTask(getClassListTask);
}
Also used : GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) LoginDatabaseTask(com.cubrid.cubridmanager.core.cubrid.database.task.LoginDatabaseTask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) OnOffType(com.cubrid.cubridmanager.core.common.model.OnOffType) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetClassListTask) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) GetCMUserListTask(com.cubrid.cubridmanager.core.common.task.GetCMUserListTask)

Example 4 with GetClassListTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetClassListTask in project cubrid-manager by CUBRID.

the class GetAllClassesTaskExecutor method exec.

/**
	 * @see com.cubrid.common.ui.spi.progress.TaskExecutor#exec(org.eclipse.core.runtime.IProgressMonitor)
	 * @param monitor IProgressMonitor
	 * @return boolean
	 */
public boolean exec(final IProgressMonitor monitor) {
    if (monitor.isCanceled()) {
        return false;
    }
    boolean isConnected = false;
    OnOffType status = OnOffType.OFF;
    MonitorDashboardPreference monPref = new MonitorDashboardPreference();
    for (ITask task : taskList) {
        if (task instanceof MonitoringTask) {
            MonitoringTask monitoringTask = (MonitoringTask) task;
            monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
            isConnected = true;
        } else if (task instanceof UpdateCMUserTask) {
            UpdateCMUserTask updateCMUserTask = (UpdateCMUserTask) task;
            ServerInfo serverInfo = updateCMUserTask.getServerInfo();
            if (serverInfo != null && serverInfo.isConnected()) {
                List<String> dbNameList = new ArrayList<String>();
                List<String> dbUserList = new ArrayList<String>();
                List<String> dbPasswordList = new ArrayList<String>();
                List<String> dbBrokerPortList = new ArrayList<String>();
                ServerUserInfo userInfo = serverInfo.getLoginedUserInfo();
                if (userInfo != null) {
                    List<DatabaseInfo> authDatabaseList = userInfo.getDatabaseInfoList();
                    if (authDatabaseList != null && !authDatabaseList.isEmpty()) {
                        int size = authDatabaseList.size();
                        for (int i = 0; i < size; i++) {
                            DatabaseInfo databaseInfo = authDatabaseList.get(i);
                            dbNameList.add(databaseInfo.getDbName());
                            dbBrokerPortList.add(QueryOptions.getBrokerIp(databaseInfo) + "," + databaseInfo.getBrokerPort());
                            String password = databaseInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
                            if (databaseInfo.getDbName().equalsIgnoreCase(dbName)) {
                                password = dbaPassword;
                                dbUserList.add("dba");
                            } else {
                                dbUserList.add(databaseInfo.getAuthLoginedDbUserInfo().getName());
                            }
                            dbPasswordList.add(password == null ? "" : password);
                        }
                    }
                }
                String[] dbNameArr = new String[dbNameList.size()];
                String[] dbUserArr = new String[dbUserList.size()];
                String[] dbPasswordArr = new String[dbPasswordList.size()];
                String[] dbBrokerPortArr = new String[dbBrokerPortList.size()];
                updateCMUserTask.setDbAuth(dbNameList.toArray(dbNameArr), dbUserList.toArray(dbUserArr), dbPasswordList.toArray(dbPasswordArr), dbBrokerPortList.toArray(dbBrokerPortArr));
                updateCMUserTask.execute();
            }
        } else if (task instanceof GetClassListTask) {
            GetClassListTask getClassListTask = (GetClassListTask) task;
            if (status != OnOffType.OFF) {
                getClassListTask.setDbStatus(status);
            }
            getClassListTask.execute();
            dbClasses = getClassListTask.getDbClassInfo();
        } else {
            task.execute();
        }
        final String msg = task.getErrorMsg();
        if (monitor.isCanceled()) {
            if (isConnected) {
                disConnect();
            }
            return false;
        }
        if (openErrorBox(shell, msg, monitor)) {
            if (isConnected) {
                disConnect();
            }
            return false;
        }
        if (task instanceof GetDatabaseListTask) {
            GetDatabaseListTask getDatabaseListTask = (GetDatabaseListTask) task;
            List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
            for (int i = 0; databaseInfoList != null && i < databaseInfoList.size(); i++) {
                DatabaseInfo dbInfo = databaseInfoList.get(i);
                if (dbName.equalsIgnoreCase(dbInfo.getDbName())) {
                    DbRunningType type = dbInfo.getRunningType();
                    if (type == DbRunningType.CS) {
                        status = OnOffType.ON;
                    }
                }
            }
        } else if (task instanceof GetCMUserListTask) {
            ServerInfo serverInfo = ((GetCMUserListTask) task).getServerInfo();
            if (serverInfo != null && serverInfo.isConnected()) {
                GetCMUserListTask getUserInfoTask = (GetCMUserListTask) task;
                List<ServerUserInfo> serverUserInfoList = getUserInfoTask.getServerUserInfoList();
                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;
                    }
                }
            }
        }
    }
    if (isConnected) {
        disConnect();
    }
    return true;
}
Also used : MonitorDashboardPreference(com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetCMUserListTask(com.cubrid.cubridmanager.core.common.task.GetCMUserListTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) OnOffType(com.cubrid.cubridmanager.core.common.model.OnOffType) GetClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetClassListTask) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) ArrayList(java.util.ArrayList) List(java.util.List) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) DbRunningType(com.cubrid.cubridmanager.core.common.model.DbRunningType)

Aggregations

GetClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetClassListTask)4 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)3 ITask (com.cubrid.common.core.task.ITask)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)2 OnOffType (com.cubrid.cubridmanager.core.common.model.OnOffType)2 GetCMUserListTask (com.cubrid.cubridmanager.core.common.task.GetCMUserListTask)2 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)2 UpdateCMUserTask (com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)2 ArrayList (java.util.ArrayList)2 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 DbRunningType (com.cubrid.cubridmanager.core.common.model.DbRunningType)1 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)1 LoginDatabaseTask (com.cubrid.cubridmanager.core.cubrid.database.task.LoginDatabaseTask)1 ClassItem (com.cubrid.cubridmanager.core.cubrid.table.model.ClassItem)1 DBClasses (com.cubrid.cubridmanager.core.cubrid.table.model.DBClasses)1 OptimizeDialog (com.cubrid.cubridmanager.ui.cubrid.database.dialog.OptimizeDialog)1