Search in sources :

Example 6 with ITask

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

the class EditUserDialog method buttonPressed.

/**
	 * When press button,call it
	 * 
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
        if (!valid()) {
            return;
        }
        boolean isChangePassword = false;
        if (newFlag) {
            isChangePassword = true;
        } else if (changePwdBtn.getSelection()) {
            isChangePassword = true;
        }
        String password = null;
        if (isChangePassword) {
            password = pwdText.getText();
            if (password == null) {
                password = "";
            }
        }
        this.inputtedPassword = password;
        boolean isNoDbaAuthUser = database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName) && !database.getDatabaseInfo().getAuthLoginedDbUserInfo().isDbaAuthority();
        String taskName = Messages.bind(Messages.addOrUpdateUserTaskName, userNameText.getText());
        TaskExecutor taskExecutor = new CommonTaskExec(taskName);
        ITask task = null;
        boolean isDropAndCreateUser = false;
        if (isNoDbaAuthUser) {
            if (isChangePassword) {
                task = new ChangeDbUserPwdTask(database.getDatabaseInfo());
                ChangeDbUserPwdTask changeDbUserPwdTask = (ChangeDbUserPwdTask) task;
                changeDbUserPwdTask.setDbUserName(userName);
                changeDbUserPwdTask.setNewPwd(password);
                taskExecutor.addTask(changeDbUserPwdTask);
            } else {
                super.buttonPressed(IDialogConstants.CANCEL_ID);
                return;
            }
        } else {
            if (newFlag) {
                List<String> groupList = new ArrayList<String>();
                for (int i = 0; i < userGroupTable.getItemCount(); i++) {
                    groupList.add(userGroupTable.getItem(i).getText(0));
                }
                List<String> memberList = new ArrayList<String>();
                for (Map<String, String> map : memberListData) {
                    memberList.add(map.get("0").toLowerCase(Locale.getDefault()));
                }
                task = new CreateUserTask(database.getDatabaseInfo(), userNameText.getText(), pwdText.getText(), groupList, memberList);
                taskExecutor.addTask(task);
            } else {
                if (!groupChange()) {
                    task = new DropUserTask(database.getDatabaseInfo(), userName);
                    taskExecutor.addTask(task);
                    List<String> groupList = new ArrayList<String>();
                    for (int i = 0; i < userGroupTable.getItemCount(); i++) {
                        groupList.add(userGroupTable.getItem(i).getText(0));
                    }
                    List<String> memberList = new ArrayList<String>();
                    for (Map<String, String> map : memberListData) {
                        memberList.add(map.get("0").toLowerCase(Locale.getDefault()));
                    }
                    task = new CreateUserTask(database.getDatabaseInfo(), userNameText.getText(), pwdText.getText(), groupList, memberList);
                    taskExecutor.addTask(task);
                    isDropAndCreateUser = true;
                } else if (isChangePassword) {
                    task = new ChangeDbUserPwdTask(database.getDatabaseInfo());
                    ChangeDbUserPwdTask changeDbUserPwdTask = (ChangeDbUserPwdTask) task;
                    changeDbUserPwdTask.setDbUserName(userName);
                    changeDbUserPwdTask.setNewPwd(password);
                    taskExecutor.addTask(task);
                }
            }
        }
        task = new UpdateAddUserJdbcTask(database.getDatabaseInfo(), userNameText.getText(), classGrantMap, authListData, authListDataOld, isDBAGroup(), isDropAndCreateUser);
        taskExecutor.addTask(task);
        new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
        if (taskExecutor.isSuccess() && isChangePassword && database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName)) {
            database.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(password);
        }
        if (taskExecutor.isSuccess()) {
            String message = null;
            if (newFlag) {
                message = Messages.msgAddUserSuccess;
            } else {
                message = Messages.msgModifyUserSuccess;
            }
            CommonUITool.openInformationBox(Messages.msgInformation, message);
        } else {
            return;
        }
    }
    super.buttonPressed(buttonId);
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ITask(com.cubrid.common.core.task.ITask) ArrayList(java.util.ArrayList) CreateUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.CreateUserTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ChangeDbUserPwdTask(com.cubrid.cubridmanager.core.cubrid.user.task.ChangeDbUserPwdTask) DropUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.DropUserTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) UpdateAddUserJdbcTask(com.cubrid.cubridmanager.core.cubrid.user.task.UpdateAddUserJdbcTask)

Example 7 with ITask

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

the class AlterTriggerAction method run.

/**
	 * edit trigger
	 * @param database
	 * @param node
	 * @return
	 */
public int run(final CubridDatabase database, final ISchemaNode node) {
    // FIXME move this logic to core module
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                Trigger trigger = null;
                if (task instanceof GetTriggerListTask) {
                    GetTriggerListTask getTriggerListTask = (GetTriggerListTask) task;
                    List<Trigger> triggerList = getTriggerListTask.getTriggerInfoList();
                    for (int i = 0; triggerList != null && i < triggerList.size(); i++) {
                        Trigger trig = triggerList.get(i);
                        if (node.getName().equals(trig.getName())) {
                            trigger = trig;
                            break;
                        }
                    }
                } else if (task instanceof JDBCGetTriggerInfoTask) {
                    JDBCGetTriggerInfoTask getTriggerInfoTask = (JDBCGetTriggerInfoTask) task;
                    trigger = getTriggerInfoTask.getTriggerInfo(node.getLabel());
                }
                if (trigger == null) {
                    openErrorBox(shell, Messages.errNameNoExist, monitor);
                    return false;
                }
                // getting comment for version after 10.0
                if (CompatibleUtil.isCommentSupports(database.getDatabaseInfo())) {
                    try {
                        SchemaComment schemaComment = SchemaCommentHandler.loadObjectDescription(database.getDatabaseInfo(), JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true), trigger.getName(), CommentType.TRIGGER);
                        trigger.setDescription(schemaComment.getDescription());
                    } catch (SQLException e) {
                        CommonUITool.openErrorBox(e.getMessage());
                    }
                }
                node.setModelObj(trigger);
            }
            return true;
        }
    };
    ITask task = null;
    if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
        task = new GetTriggerListTask(database.getServer().getServerInfo());
        ((GetTriggerListTask) task).setDbName(database.getName());
    } else {
        task = new JDBCGetTriggerInfoTask(database.getDatabaseInfo());
    }
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return IDialogConstants.CANCEL_ID;
    }
    CreateTriggerDialog dialog = new CreateTriggerDialog(getShell(), node.getDatabase(), (Trigger) node.getAdapter(Trigger.class));
    if (dialog.open() != IDialogConstants.CANCEL_ID) {
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        return IDialogConstants.OK_ID;
    }
    return IDialogConstants.CANCEL_ID;
}
Also used : ITask(com.cubrid.common.core.task.ITask) JDBCGetTriggerInfoTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerInfoTask) SQLException(java.sql.SQLException) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Trigger(com.cubrid.common.core.common.model.Trigger) GetTriggerListTask(com.cubrid.cubridmanager.core.cubrid.trigger.task.GetTriggerListTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CreateTriggerDialog(com.cubrid.common.ui.cubrid.trigger.dialog.CreateTriggerDialog) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment)

Example 8 with ITask

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

the class CommonTaskExec method exec.

/**
	 * Execute the task
	 * 
	 * @param monitor the monitor
	 * @return <code>true</code>if success;<code>false</code> otherwise
	 */
public boolean exec(final IProgressMonitor monitor) {
    if (monitor.isCanceled()) {
        return false;
    }
    if (taskName != null) {
        monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
    }
    for (final ITask task : taskList) {
        if (task instanceof AbstractUITask) {
            ((AbstractUITask) task).execute(monitor);
        } else {
            task.execute();
        }
        String errorMsg = task.getErrorMsg();
        if (messageHandler != null) {
            errorMsg = messageHandler.translate(task.getErrorMsg());
        }
        if (openErrorBox(null, errorMsg, monitor)) {
            return false;
        }
        //			});
        if (taskExeStatus != null && taskExeStatus == Status.CANCEL_STATUS) {
            return false;
        }
        if (taskExeStatus != null && taskExeStatus != Status.OK_STATUS) {
            errorMsg = taskExeStatus.getMessage();
            if (messageHandler != null) {
                errorMsg = messageHandler.translate(taskExeStatus.getMessage());
            }
            openErrorBox(null, errorMsg, monitor);
            return false;
        }
        if (monitor.isCanceled()) {
            return false;
        }
    }
    //		});
    return true;
}
Also used : AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) AbstractUITask(com.cubrid.common.core.task.AbstractUITask)

Example 9 with ITask

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

the class CommonTaskJobExec method exec.

/**
	 * Execute the task
	 * 
	 * @param monitor the monitor
	 * @return <code>true</code>if success;<code>false</code> otherwise
	 */
public IStatus exec(IProgressMonitor monitor) {
    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            setDialogVisible(false);
        }
    });
    if (monitor.isCanceled()) {
        cancel();
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                closeDialog();
            }
        });
        return Status.CANCEL_STATUS;
    }
    for (final ITask task : taskList) {
        if (task instanceof AbstractUITask) {
            ((AbstractUITask) task).execute(monitor);
        } else {
            task.execute();
        }
        final String msg = task.getErrorMsg();
        if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    setDialogVisible(true);
                }
            });
            return new Status(IStatus.ERROR, CommonUIPlugin.PLUGIN_ID, msg);
        } else {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    taskExeStatus = refresh(task);
                }
            });
        }
        if (taskExeStatus != Status.OK_STATUS) {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    setDialogVisible(true);
                }
            });
            return taskExeStatus;
        }
        if (monitor.isCanceled()) {
            cancel();
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    closeDialog();
                }
            });
            return Status.CANCEL_STATUS;
        }
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) AbstractUITask(com.cubrid.common.core.task.AbstractUITask)

Example 10 with ITask

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

the class BackupDatabaseDialog method backupDb.

/**
	 *
	 * Execute task and backup database
	 *
	 * @param buttonId the button id
	 */
private void backupDb(final int buttonId) {
    isCanFinished = true;
    TaskJobExecutor taskExcutor = new TaskJobExecutor() {

        private String backupVolInfo;

        public IStatus exec(final IProgressMonitor monitor) {
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    getShell().setVisible(false);
                }
            });
            if (monitor.isCanceled()) {
                cancel();
                display.syncExec(new Runnable() {

                    public void run() {
                        setReturnCode(buttonId);
                        close();
                    }
                });
                return Status.CANCEL_STATUS;
            }
            for (ITask task : taskList) {
                if (!(task instanceof GetBackupVolInfoTask) || database.getRunningType() != DbRunningType.CS) {
                    task.execute();
                    final String msg = task.getErrorMsg();
                    if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                        display.syncExec(new Runnable() {

                            public void run() {
                                getShell().setVisible(true);
                            }
                        });
                        return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                    }
                }
                if (isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (task instanceof CheckDirTask) {
                    CheckDirTask checkDirTask = (CheckDirTask) task;
                    final String[] dirs = checkDirTask.getNoExistDirectory();
                    if (dirs != null && dirs.length > 0) {
                        display.syncExec(new Runnable() {

                            public void run() {
                                CreateDirDialog dialog = new CreateDirDialog(getShell());
                                dialog.setDirs(dirs);
                                if (dialog.open() != IDialogConstants.OK_ID) {
                                    isCanFinished = false;
                                    getShell().setVisible(true);
                                }
                            }
                        });
                    }
                } else if (task instanceof CheckFileTask) {
                    CheckFileTask checkFileTask = (CheckFileTask) task;
                    final String[] files = checkFileTask.getExistFiles();
                    if (files != null && files.length > 0) {
                        display.syncExec(new Runnable() {

                            public void run() {
                                OverrideFileDialog dialog = new OverrideFileDialog(getShell());
                                dialog.setFiles(files);
                                if (dialog.open() != IDialogConstants.OK_ID) {
                                    isCanFinished = false;
                                    getShell().setVisible(true);
                                }
                            }
                        });
                    }
                } else if (task instanceof GetBackupVolInfoTask && database.getRunningType() == DbRunningType.STANDALONE) {
                    GetBackupVolInfoTask getBackupVolInfoTask = (GetBackupVolInfoTask) task;
                    backupVolInfo = getBackupVolInfoTask.getDbBackupVolInfo();
                }
                if (!isCanFinished) {
                    return Status.CANCEL_STATUS;
                }
                if (monitor.isCanceled()) {
                    cancel();
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            close();
                        }
                    });
                    return Status.CANCEL_STATUS;
                }
            }
            return Status.OK_STATUS;
        }

        public void done(IJobChangeEvent event) {
            if (event.getResult() == Status.OK_STATUS) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        if (database.getRunningType() == DbRunningType.CS) {
                            Display.getDefault().syncExec(new Runnable() {

                                public void run() {
                                    CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgBackupSuccess);
                                }
                            });
                        } else {
                            if (backupVolInfo != null && backupVolInfo.length() > 0) {
                                Display.getDefault().syncExec(new Runnable() {

                                    public void run() {
                                        BackupDbVolumeInfoDialog backupDbResultInfoDialog = new BackupDbVolumeInfoDialog(getShell());
                                        backupDbResultInfoDialog.setResultInfoStr(backupVolInfo);
                                        backupDbResultInfoDialog.open();
                                    }
                                });
                            }
                        }
                        close();
                    }
                });
            }
        }
    };
    String backupDir = backupDirText.getText();
    CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
    checkDirTask.setDirectory(new String[] { backupDir });
    CheckFileTask checkFileTask = new CheckFileTask(database.getServer().getServerInfo());
    String fileName = backupDirText.getText() + database.getServer().getServerInfo().getPathSeparator() + volumeNameText.getText();
    checkFileTask.setFile(new String[] { fileName });
    String databaseName = databaseNameText.getText();
    String level = backupLevelCombo.getText().replaceAll("Level", "");
    String volName = volumeNameText.getText();
    boolean isRemoveLog = archiveLogButton.getSelection();
    boolean isCheckDbCons = consistentButton.getSelection();
    boolean isZip = useCompressButton.getSelection();
    boolean isSafeReplication = safeBackupButton.getSelection();
    int threadNum = spnThreadNum.getSelection();
    BackupDbTask backupDbTask = new BackupDbTask(database.getServer().getServerInfo());
    backupDbTask.setDbName(databaseName);
    backupDbTask.setLevel(level);
    backupDbTask.setVolumeName(volName);
    backupDbTask.setBackupDir(backupDir);
    backupDbTask.setRemoveLog(isRemoveLog);
    backupDbTask.setCheckDatabaseConsist(isCheckDbCons);
    backupDbTask.setThreadCount(String.valueOf(threadNum));
    backupDbTask.setZiped(isZip);
    backupDbTask.setSafeReplication(isSafeReplication);
    GetBackupVolInfoTask getBackupVolInfoTask = new GetBackupVolInfoTask(database.getServer().getServerInfo());
    getBackupVolInfoTask.setDbName(databaseName);
    taskExcutor.addTask(checkDirTask);
    taskExcutor.addTask(checkFileTask);
    taskExcutor.addTask(backupDbTask);
    taskExcutor.addTask(getBackupVolInfoTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgBackupDBRearJobName + " - " + dbName + "@" + serverName;
    taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITask(com.cubrid.common.core.task.ITask) GetBackupVolInfoTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetBackupVolInfoTask) BackupDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.BackupDbTask) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) Display(org.eclipse.swt.widgets.Display)

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