Search in sources :

Example 16 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class CreateViewDialog method execTask.

/**
	 * execute the task.
	 *
	 * @param buttonId int
	 * @param tasks ITask[]
	 * @param cancelable boolean
	 * @param shell Shell
	 */
public void execTask(final int buttonId, final ITask[] tasks, boolean cancelable, final Shell shell) {
    if (tasks == null || tasks.length == 0) {
        return;
    }
    TaskExecutor taskExecutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            for (ITask task : tasks) {
                if (task instanceof GetAllClassListTask) {
                    ((GetAllClassListTask) task).getClassInfoTaskExcute();
                } else if (task instanceof GetViewAllColumnsTask) {
                    ((GetViewAllColumnsTask) task).getAllVclassListTaskExcute();
                } else if (task instanceof GetAllAttrTask) {
                    ((GetAllAttrTask) task).getAttrList();
                } else {
                    task.execute();
                }
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            return true;
        }
    };
    taskExecutor.setTask(tasks);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (taskExecutor.isSuccess() && buttonId > 0) {
        setReturnCode(buttonId);
        close();
    }
}
Also used : TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) GetViewAllColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)

Example 17 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class ERSchemaEditor method compareTableSchemas.

public void compareTableSchemas(final String modelName, final Map<String, TableSchema> tableSchema, final Map<String, SchemaInfo> schemaInfos) {
    final List<TableSchemaCompareModelInputLazy> input = new ArrayList<TableSchemaCompareModelInputLazy>();
    ITask reportBugTask = new AbstractUITask() {

        private boolean success = false;

        public void cancel() {
        }

        public void finish() {
        }

        public boolean isCancel() {
            return false;
        }

        public boolean isSuccess() {
            return success;
        }

        public void execute(IProgressMonitor monitor) {
            CubridDatabase database = erSchema.getCubridDatabase();
            List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(database);
            final CubridDatabase virtualDb = new CubridDatabase(modelName, modelName);
            virtualDb.setVirtual(true);
            DatabaseInfo info = database.getDatabaseInfo();
            virtualDb.setDatabaseInfo(info);
            WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info);
            wrappedDatabaseInfo.addSchemaInfos(schemaInfos);
            wrappedDatabaseInfo.addTableSchemas(tableSchema);
            ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
            TableSchemaModel leftModel = TableSchemaCompareUtil.createTableSchemaModel(leftDbTableInfoList);
            TableSchemaModel rightModel = new TableSchemaModel();
            rightModel.getTableSchemaMap().putAll(tableSchema);
            TableSchemaComparator comparator = new TableSchemaComparator(database, virtualDb);
            TableSchemaCompareModel model = comparator.compare(leftModel, rightModel);
            model.setSourceDB(database);
            model.setTargetDB(virtualDb);
            input.add(new TableSchemaCompareModelInputLazy(model));
            success = true;
        }
    };
    TaskExecutor taskExecutor = new CommonTaskExec(com.cubrid.common.ui.common.Messages.titleSchemaComparison);
    taskExecutor.addTask(reportBugTask);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (taskExecutor.isSuccess()) {
        try {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input.get(0), TableSchemaCompareInfoPart.ID);
        } catch (Exception e) {
        }
    }
}
Also used : TableSchemaCompareModelInputLazy(com.cubrid.common.ui.compare.schema.control.TableSchemaCompareModelInputLazy) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) ERVirtualDatabaseInfo(com.cubrid.common.ui.er.model.ERVirtualDatabaseInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) TableSchemaComparator(com.cubrid.common.ui.compare.schema.TableSchemaComparator) ArrayList(java.util.ArrayList) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) TableSchemaModel(com.cubrid.common.ui.compare.schema.model.TableSchemaModel) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 18 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class CubridNodeLoader method monitorCancel.

/**
	 * 
	 * Monitoring cancel operation
	 * 
	 * @param monitor IProgressMonitor
	 * @param tasks ITask[]
	 */
public void monitorCancel(final IProgressMonitor monitor, final ITask[] tasks) {
    String name = getClass().getName() == null ? "loading" : getClass().getName();
    Thread thread = new Thread(name + " monitoring thread") {

        public void run() {
            while (!monitor.isCanceled() && !isLoaded()) {
                try {
                    sleep(WAIT_TIME);
                } catch (InterruptedException e) {
                }
            }
            if (monitor.isCanceled() && tasks != null && tasks.length > 0) {
                for (ITask task : tasks) {
                    if (task != null) {
                        task.cancel();
                    }
                }
            }
        }
    };
    thread.start();
}
Also used : ITask(com.cubrid.common.core.task.ITask)

Example 19 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class ShardsTaskFactory method generateTasks.

public ITask[] generateTasks() {
    ITask[] tasks = new ITask[deletes.size() + updates.size()];
    List<ITask> taskList = new ArrayList<ITask>();
    // if the shard has changed the name?
    for (Shard model : updates) {
        taskList.add(new SaveShardConfTask(this.serverInfo, model.getShardConnectionFile()));
        taskList.add(new SaveShardConfTask(this.serverInfo, model.getShardKeysFile()));
    }
    // Then, update shard.conf file.
    taskList.add(new SaveShardConfTask(this.serverInfo, shards));
    // Finally, delete the connection and key files.
    for (Shard model : deletes) {
        taskList.add(new DeleteShardFileTask(this.serverInfo, model.getName() + "_connection.txt"));
        taskList.add(new DeleteShardFileTask(this.serverInfo, model.getName() + "_key.txt"));
    }
    for (String deleteFileName : deleteFileNames) {
        taskList.add(new DeleteShardFileTask(this.serverInfo, deleteFileName + "_connection.txt"));
        taskList.add(new DeleteShardFileTask(this.serverInfo, deleteFileName + "_key.txt"));
    }
    tasks = taskList.toArray(tasks);
    return tasks;
}
Also used : ITask(com.cubrid.common.core.task.ITask) ArrayList(java.util.ArrayList) Shard(com.cubrid.cubridmanager.core.shard.model.Shard)

Example 20 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class UserManagementWizard method performFinish.

/**
	 * Called when user clicks Finish
	 * 
	 * @return boolean
	 */
public boolean performFinish() {
    final String userId = generalInfoPage.getUserId();
    final String password = generalInfoPage.getPassword();
    final String dbCreationAuth = generalInfoPage.getDbCreationAuth();
    final String brokerAuth = generalInfoPage.getBrokerAuth();
    final String statusMonitorAuth = generalInfoPage.getStatusMonitorAuth();
    final List<DatabaseInfo> authDatabaselist = new ArrayList<DatabaseInfo>();
    final Shell shell = getShell();
    final String taskName = Messages.bind(Messages.updateUserTaskName, userId);
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(taskName, 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;
                }
            }
            ServerUserInfo loginedUserInfo = server.getServerInfo().getLoginedUserInfo();
            if (userInfo == null) {
                userInfo = new ServerUserInfo(userId, password);
            } else {
                userInfo.setPassword(password);
            }
            if (userInfo.getUserName().equals(loginedUserInfo.getUserName())) {
                loginedUserInfo.setPassword(password);
            }
            if (!userInfo.isAdmin()) {
                if (dbCreationAuth.equals(DbCreateAuthType.AUTH_NONE.getText())) {
                    userInfo.setDbCreateAuthType(DbCreateAuthType.AUTH_NONE);
                } else if (dbCreationAuth.equals(DbCreateAuthType.AUTH_ADMIN.getText())) {
                    userInfo.setDbCreateAuthType(DbCreateAuthType.AUTH_ADMIN);
                }
                if (brokerAuth.equals(CasAuthType.AUTH_NONE.getText())) {
                    userInfo.setCasAuth(CasAuthType.AUTH_NONE);
                } else if (brokerAuth.equals(CasAuthType.AUTH_ADMIN.getText())) {
                    userInfo.setCasAuth(CasAuthType.AUTH_ADMIN);
                } else if (brokerAuth.equals(CasAuthType.AUTH_MONITOR.getText())) {
                    userInfo.setCasAuth(CasAuthType.AUTH_MONITOR);
                }
                if (statusMonitorAuth.equals(StatusMonitorAuthType.AUTH_NONE.getText())) {
                    userInfo.setStatusMonitorAuth(StatusMonitorAuthType.AUTH_NONE);
                } else if (statusMonitorAuth.equals(StatusMonitorAuthType.AUTH_ADMIN.getText())) {
                    userInfo.setStatusMonitorAuth(StatusMonitorAuthType.AUTH_ADMIN);
                } else if (statusMonitorAuth.equals(StatusMonitorAuthType.AUTH_MONITOR.getText())) {
                    userInfo.setStatusMonitorAuth(StatusMonitorAuthType.AUTH_MONITOR);
                }
                userInfo.removeAllDatabaseInfo();
                userInfo.setDatabaseInfoList(authDatabaselist);
            }
            return true;
        }
    };
    if (userInfo != null && userInfo.isAdmin()) {
        ChangeCMUserPasswordTask changeCMUserPasswordTask = new ChangeCMUserPasswordTask(server.getServerInfo());
        changeCMUserPasswordTask.setUserName(userId);
        changeCMUserPasswordTask.setPassword(password);
        taskExcutor.addTask(changeCMUserPasswordTask);
    } else if (userInfo != null && !userInfo.isAdmin()) {
        DeleteCMUserTask deleteCMUserTask = new DeleteCMUserTask(server.getServerInfo());
        deleteCMUserTask.setUserId(userId);
        taskExcutor.addTask(deleteCMUserTask);
    }
    if (userInfo == null || !userInfo.isAdmin()) {
        AddCMUserTask addCMUserTask = new AddCMUserTask(server.getServerInfo());
        addCMUserTask.setUserId(userId);
        addCMUserTask.setPassword(password);
        addCMUserTask.setDbcreate(dbCreationAuth);
        addCMUserTask.setCasAuth(brokerAuth);
        addCMUserTask.setStautsMonitorAuth(statusMonitorAuth);
        taskExcutor.addTask(addCMUserTask);
    }
    ServerType serverType = server.getServerInfo().getServerType();
    if ((userInfo == null || !userInfo.isAdmin()) && (serverType == ServerType.BOTH || serverType == ServerType.DATABASE)) {
        List<Map<String, Object>> dbAuthInfoList = authDbInfoPage.getDbAuthInfoList();
        List<String> dbNameList = new ArrayList<String>();
        List<String> dbUserList = new ArrayList<String>();
        List<String> dbPasswordList = new ArrayList<String>();
        List<String> dbBrokerPortList = new ArrayList<String>();
        if (dbAuthInfoList != null && !dbAuthInfoList.isEmpty()) {
            int size = dbAuthInfoList.size();
            for (int i = 0; i < size; i++) {
                Map<String, Object> map = dbAuthInfoList.get(i);
                String allowConnectedStr = (String) map.get("1");
                if ("Yes".equals(allowConnectedStr)) {
                    String dbName = (String) map.get("0");
                    dbNameList.add(dbName);
                    String dbUser = (String) map.get("2");
                    dbUserList.add(dbUser);
                    String brokerIP = (String) map.get("3");
                    String brokerPort = (String) map.get("4");
                    String port = "";
                    if (brokerPort.matches("^\\d+$")) {
                        port = brokerPort;
                    } else {
                        port = brokerPort.substring(brokerPort.indexOf("[") + 1, brokerPort.indexOf("/"));
                    }
                    dbBrokerPortList.add(brokerIP + "," + port);
                    dbPasswordList.add("");
                    DatabaseInfo databaseInfo = new DatabaseInfo(dbName, server.getServerInfo());
                    databaseInfo.setBrokerPort(brokerPort);
                    databaseInfo.setBrokerIP(brokerIP);
                    DbUserInfo dbUserInfo = new DbUserInfo();
                    dbUserInfo.setName(dbUser);
                    databaseInfo.setAuthLoginedDbUserInfo(dbUserInfo);
                    authDatabaselist.add(databaseInfo);
                }
            }
        }
        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 updateTask = new UpdateCMUserTask(server.getServerInfo());
        updateTask.setCmUserName(userId);
        updateTask.setDbAuth(dbNameList.toArray(dbNameArr), dbUserList.toArray(dbUserArr), dbPasswordList.toArray(dbPasswordArr), dbBrokerPortList.toArray(dbBrokerPortArr));
        updateTask.setCasAuth(brokerAuth);
        updateTask.setDbCreator(dbCreationAuth);
        updateTask.setStatusMonitorAuth(statusMonitorAuth);
        taskExcutor.addTask(updateTask);
    }
    new ExecTaskWithProgress(taskExcutor).exec(true, true);
    return taskExcutor.isSuccess();
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ChangeCMUserPasswordTask(com.cubrid.cubridmanager.core.common.task.ChangeCMUserPasswordTask) ArrayList(java.util.ArrayList) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DeleteCMUserTask(com.cubrid.cubridmanager.core.common.task.DeleteCMUserTask) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) Map(java.util.Map) AddCMUserTask(com.cubrid.cubridmanager.core.common.task.AddCMUserTask)

Aggregations

ITask (com.cubrid.common.core.task.ITask)85 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)49 IStatus (org.eclipse.core.runtime.IStatus)37 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)35 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)35 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)28 ArrayList (java.util.ArrayList)27 Status (org.eclipse.core.runtime.Status)23 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)20 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)17 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)15 Map (java.util.Map)15 Display (org.eclipse.swt.widgets.Display)15 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)14 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)14 List (java.util.List)14 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)13 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)13 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)12 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)11