Search in sources :

Example 31 with JobFamily

use of com.cubrid.common.ui.spi.progress.JobFamily in project cubrid-manager by CUBRID.

the class RenameDatabaseDialog method renameDb.

/**
	 * Execute task and rename database
	 */
private void renameDb() {
    newDBName = databaseNameText.getText();
    isCanFinished = true;
    TaskJobExecutor taskExec = new TaskJobExecutor() {

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

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

                    public void run() {
                        close();
                    }
                });
                return Status.CANCEL_STATUS;
            }
            List<String> cubridConfContentList = null;
            for (ITask task : taskList) {
                if (task instanceof SetCubridConfParameterTask) {
                    if (cubridConfContentList == null) {
                        LOGGER.warn("cubridConfContentList is null. Skip SetCubridConfParameterTask.");
                        continue;
                    }
                    SetCubridConfParameterTask setParaTask = (SetCubridConfParameterTask) task;
                    setParaTask.setConfContents(cubridConfContentList);
                }
                task.execute();
                final String msg = task.getErrorMsg();
                if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                    Display.getDefault().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.getDefault().syncExec(new Runnable() {

                            public void run() {
                                CreateDirDialog dialog = new CreateDirDialog(getShell());
                                dialog.setDirs(dirs);
                                if (dialog.open() != IDialogConstants.OK_ID) {
                                    isCanFinished = false;
                                }
                            }
                        });
                    }
                } else if (task instanceof GetCubridConfParameterTask) {
                    GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
                    cubridConfContentList = CoreUtils.renameDatabaseFromServiceServer(getCubridConfParameterTask, cubridConfContentList, database.getName(), newDBName);
                }
                if (!isCanFinished || 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() {
                        iUpdateUIWithJob.completeAll();
                        close();
                    }
                });
            }
        }
    };
    CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
    RenameDbTask renameDbTask = new RenameDbTask(database.getServer().getServerInfo());
    renameDbTask.setDbName(database.getLabel());
    renameDbTask.setNewDbName(newDBName);
    if (exVolumePathButton.getSelection()) {
        checkDirTask.setDirectory(new String[] { exVolumePathText.getText() });
        renameDbTask.setExVolumePath(exVolumePathText.getText());
        renameDbTask.setAdvanced(false);
    } else if (renameVolumeButton.getSelection()) {
        List<String> pathList = new ArrayList<String>();
        List<String> volumeChangedList = new ArrayList<String>();
        for (int i = 0; spaceInfoList != null && i < spaceInfoList.size(); i++) {
            Map<String, String> map = spaceInfoList.get(i);
            String oldName = map.get("0");
            String newName = map.get("1");
            String oldPath = map.get("2");
            String newPath = map.get("3");
            addVolumePath(pathList, newPath);
            oldPath = oldPath.replaceAll(":", "|");
            newPath = newPath.replaceAll(":", "|");
            volumeChangedList.add(oldPath + "/" + oldName + ":" + newPath + "/" + newName);
        }
        String[] checkedDirs = new String[pathList.size()];
        pathList.toArray(checkedDirs);
        checkDirTask.setDirectory(checkedDirs);
        renameDbTask.setAdvanced(true);
        renameDbTask.setIndividualVolume(volumeChangedList);
    }
    if (forceDelBackupVolumeButton.getSelection()) {
        renameDbTask.setForceDel(true);
    } else {
        renameDbTask.setForceDel(false);
    }
    taskExec.addTask(renameDbTask);
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(database.getServer().getServerInfo());
    taskExec.addTask(getCubridConfParameterTask);
    SetCubridConfParameterTask setCubridConfParameterTask = new SetCubridConfParameterTask(database.getServer().getServerInfo());
    taskExec.addTask(setCubridConfParameterTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgRenameDBRearJobName + " - " + dbName + "@" + serverName;
    taskExec.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) SetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask) RenameDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.RenameDbTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) ArrayList(java.util.ArrayList) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) Map(java.util.Map) HashMap(java.util.HashMap)

Example 32 with JobFamily

use of com.cubrid.common.ui.spi.progress.JobFamily in project cubrid-manager by CUBRID.

the class RestoreDatabaseDialog method restoreDb.

/**
	 * 
	 * Restore database
	 * 
	 * 
	 */
private void restoreDb() {
    if (!valid()) {
        return;
    }
    TaskJobExecutor taskExec = new CommonTaskJobExec(this);
    String databaseName = databaseNameText.getText();
    ServerInfo serverInfo = database.getServer().getServerInfo();
    boolean isLocalServer = serverInfo.isLocalServer();
    RestoreDbTask restoreDbTask = new RestoreDbTask(database.getServer().getServerInfo());
    restoreDbTask.setDbName(databaseName);
    String level = "0";
    String path = "none";
    if (selectBackupButton.getSelection()) {
        if (level0Button.getSelection()) {
            level = "0";
            path = level0Text.getText();
        } else if (level1Button.getSelection()) {
            level = "1";
            path = level1Text.getText();
        } else if (level2Button.getSelection()) {
            level = "2";
            path = level2Text.getText();
        }
        if (!isLocalServer) {
            CheckFileTask checkFileTask = new CheckFileTask(serverInfo);
            checkFileTask.setFile(new String[] { path });
            checkFileTask.putData("filePath", path);
            taskExec.addTask(checkFileTask);
        }
    }
    if (selectTimeButton.getSelection()) {
        if (backupTimeButton.getSelection()) {
            restoreDbTask.setDate("backuptime");
        } else if (restoredDataTimeButton.getSelection()) {
            NumberFormat nf = NumberFormat.getInstance();
            nf.setMinimumIntegerDigits(2);
            String timeStr = nf.format(hourSpn.getSelection()) + ":" + nf.format(minuteSpn.getSelection()) + ":" + nf.format(secondSpn.getSelection());
            String dateStr = nf.format(daySpn.getSelection()) + "-" + nf.format(monthSpn.getSelection()) + "-" + yearSpn.getSelection();
            dateStr += ":" + timeStr;
            restoreDbTask.setDate(dateStr);
        }
    } else {
        restoreDbTask.setDate("none");
    }
    if (!CompatibleUtil.isSupportRestorePath(database.getServer().getServerInfo())) {
        path = "none";
    }
    restoreDbTask.setLevel(level);
    restoreDbTask.setPathName(path);
    if (partialButton.getSelection()) {
        restoreDbTask.setPartial(true);
    } else {
        restoreDbTask.setPartial(false);
    }
    if (dbPathButton == null || !dbPathButton.getSelection()) {
        restoreDbTask.setRecoveryPath("none");
    } else {
        restoreDbTask.setRecoveryPath(dbPathText.getText());
        if (!isLocalServer) {
            CheckDirTask checkDirTask = new CheckDirTask(serverInfo);
            checkDirTask.setDirectory(new String[] { dbPathText.getText() });
            taskExec.addTask(checkDirTask);
        }
    }
    taskExec.addTask(restoreDbTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgRestoreDBRearJobName + " - " + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) RestoreDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.RestoreDbTask) NumberFormat(java.text.NumberFormat)

Example 33 with JobFamily

use of com.cubrid.common.ui.spi.progress.JobFamily in project cubrid-manager by CUBRID.

the class StopDatabaseAction method run.

public void run() {
    Object[] objArr = this.getSelectedObj();
    if (objArr == null || objArr.length <= 0) {
        setEnabled(false);
        return;
    }
    Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
    for (int i = 0; objArr != null && i < objArr.length; i++) {
        if (!isSupported(objArr[i])) {
            setEnabled(false);
            return;
        }
        ISchemaNode schemaNode = (ISchemaNode) objArr[i];
        CubridDatabase database = schemaNode.getDatabase();
        databaseSet.add(database);
    }
    StringBuffer dbNames = new StringBuffer();
    Iterator<CubridDatabase> it = databaseSet.iterator();
    while (it.hasNext()) {
        CubridDatabase database = it.next();
        dbNames.append(database.getLabel()).append(",");
    }
    dbNames = new StringBuffer(dbNames.substring(0, dbNames.length() - 1));
    boolean isStop = CommonUITool.openConfirmBox(getShell(), Messages.bind(Messages.msgConfirmStopDatabase, dbNames.toString()));
    if (!isStop) {
        return;
    }
    Iterator<CubridDatabase> iter = databaseSet.iterator();
    while (iter.hasNext()) {
        CubridDatabase database = iter.next();
        final JobFamily jobFamily = new JobFamily();
        String serverName = database.getServer().getName();
        String dbName = database.getName();
        jobFamily.setServerName(serverName);
        jobFamily.setDbName(dbName);
        Job[] jobs = Job.getJobManager().find(jobFamily);
        if (jobs.length > 0) {
            CommonUITool.openWarningBox(Messages.bind(Messages.msgStopDbWithJob, dbName));
            databaseSet.remove(database);
            continue;
        }
    }
    final Object[] dbObjectArr = new Object[databaseSet.size()];
    databaseSet.toArray(dbObjectArr);
    ISelectionProvider provider = getSelectionProvider();
    final Shell shell = getShell();
    if (provider instanceof TreeViewer && dbObjectArr.length > 0) {
        final TreeViewer viewer = (TreeViewer) provider;
        TaskExecutor taskExcutor = new TaskExecutor() {

            public boolean exec(final IProgressMonitor monitor) {
                Display display = Display.getDefault();
                if (monitor.isCanceled()) {
                    return false;
                }
                for (int i = 0; i < taskList.size(); i++) {
                    ISchemaNode node = (ISchemaNode) dbObjectArr[i];
                    final CubridDatabase database = node.getDatabase();
                    if (!isSupported(database)) {
                        continue;
                    }
                    monitor.subTask(Messages.bind(Messages.stopDbTaskName, database.getName()));
                    ITask task = taskList.get(i);
                    task.execute();
                    final String msg = task.getErrorMsg();
                    if (openErrorBox(shell, msg, monitor)) {
                        return false;
                    }
                    if (monitor.isCanceled()) {
                        return false;
                    }
                    database.removeAllChild();
                    if (database.getLoader() != null) {
                        database.getLoader().setLoaded(false);
                    }
                    database.setRunningType(DbRunningType.STANDALONE);
                    display.syncExec(new Runnable() {

                        public void run() {
                            viewer.refresh(database, true);
                        }
                    });
                    if (monitor.isCanceled()) {
                        return false;
                    }
                }
                return true;
            }
        };
        boolean isContinue = true;
        for (int i = 0; i < dbObjectArr.length; i++) {
            ISchemaNode node = (ISchemaNode) dbObjectArr[i];
            CubridDatabase database = node.getDatabase();
            if (!isSupported(database)) {
                setEnabled(false);
                return;
            }
            if (!LayoutUtil.checkAllQueryEditor(database)) {
                isContinue = false;
                break;
            }
            CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.STOP_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
            task.setDbName(database.getLabel());
            taskExcutor.addTask(task);
        }
        if (!isContinue) {
            return;
        }
        new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        for (int i = 0; i < dbObjectArr.length; i++) {
            CubridDatabase database = (CubridDatabase) dbObjectArr[i];
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_STOP));
        }
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) Shell(org.eclipse.swt.widgets.Shell) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) Job(org.eclipse.core.runtime.jobs.Job) HashSet(java.util.HashSet) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) Display(org.eclipse.swt.widgets.Display)

Example 34 with JobFamily

use of com.cubrid.common.ui.spi.progress.JobFamily in project cubrid-manager by CUBRID.

the class CreateDatabaseWizard method performFinish.

/**
	 * Called when user clicks Finish
	 * 
	 * @return boolean
	 */
public boolean performFinish() {
    isCanFinished = true;
    isOverride = true;
    final String databaseName = generalInfoPage.getDatabaseName();
    String pageSize = generalInfoPage.getPageSize();
    String logPageSize = generalInfoPage.getLogPageSize();
    String generalPageNum = generalInfoPage.getGenericPageNum();
    String generalVolumePath = generalInfoPage.getGenericVolumePath();
    String charset = generalInfoPage.getCharset();
    final boolean isAutoStart = generalInfoPage.isAutoStart();
    TaskJobExecutor taskExcutor = new TaskJobExecutor() {

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

                public void run() {
                    getShell().setVisible(false);
                }
            });
            if (monitor.isCanceled()) {
                isCanFinished = true;
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        cancel();
                        close();
                    }
                });
                return Status.CANCEL_STATUS;
            }
            List<String> cubridConfContentList = null;
            for (ITask task : taskList) {
                if (task instanceof CreateDbTask) {
                    CreateDbTask createDbTask = (CreateDbTask) task;
                    createDbTask.setOverwriteConfigFile(isOverride);
                } else if (task instanceof SetCubridConfParameterTask) {
                    if (cubridConfContentList == null) {
                        continue;
                    } else {
                        SetCubridConfParameterTask setParaTask = (SetCubridConfParameterTask) task;
                        setParaTask.setConfContents(cubridConfContentList);
                    }
                }
                task.execute();
                final String msg = task.getErrorMsg();
                if (monitor.isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            cancel();
                            close();
                        }
                    });
                    isCanFinished = true;
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                    //start database failed
                    if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.START_DB_TASK_NAME)) {
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                CommonUITool.openErrorBox(getShell(), msg + StringUtil.NEWLINE + Messages.createDBFailedMsg);
                            }
                        });
                        return Status.OK_STATUS;
                    }
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            CommonUITool.openErrorBox(getShell(), msg);
                            isCanFinished = false;
                            getShell().setVisible(true);
                        }
                    });
                    return Status.CANCEL_STATUS;
                }
                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.getDefault().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.getDefault().syncExec(new Runnable() {

                            public void run() {
                                OverrideFileDialog dialog = new OverrideFileDialog(getShell());
                                dialog.setFiles(files);
                                isOverride = dialog.open() == IDialogConstants.OK_ID;
                                getShell().setVisible(!isOverride);
                            }
                        });
                    }
                } else if (task instanceof GetCubridConfParameterTask) {
                    GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
                    List<String> cubridConfContentListCandidate1 = null;
                    if (isAutoStart) {
                        cubridConfContentListCandidate1 = CoreUtils.addDatabaseToServiceServer(getCubridConfParameterTask, null, databaseName);
                    }
                    List<String> cubridConfContentListCandidate2 = null;
                    if (CompatibleUtil.isNeedCheckHAModeOnNewDb(server.getServerInfo())) {
                        cubridConfContentListCandidate2 = CoreUtils.changeHAModeFromCubridConf(getCubridConfParameterTask, cubridConfContentListCandidate1, databaseName);
                    }
                    if (cubridConfContentListCandidate2 == null) {
                        cubridConfContentList = cubridConfContentListCandidate1;
                    } else {
                        cubridConfContentList = cubridConfContentListCandidate2;
                    }
                }
                if (!isCanFinished) {
                    return Status.CANCEL_STATUS;
                }
                if (monitor.isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

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

        public void cancel() {
            super.cancel();
            GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(server.getServerInfo());
            getDatabaseListTask.execute();
            boolean isExist = false;
            List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
            if (databaseInfoList != null) {
                for (int i = 0; i < databaseInfoList.size(); i++) {
                    DatabaseInfo dbInfo = databaseInfoList.get(i);
                    String dbName = dbInfo.getDbName();
                    if (dbName.equals(databaseName)) {
                        isExist = true;
                    }
                }
            }
            if (isExist) {
                CommonUpdateTask deleteTask = new CommonUpdateTask(CommonTaskName.DELETE_DATABASE_TASK_NAME, server.getServerInfo(), CommonSendMsg.getDeletedbSendMsg());
                deleteTask.setDbName(databaseName);
                deleteTask.setDelbackup(YesNoType.Y);
                deleteTask.execute();
            }
        }

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

                    public void run() {
                        completeAll();
                        close();
                    }
                });
            }
        }
    };
    CheckDirTask checkDirTask = new CheckDirTask(server.getServerInfo());
    CheckFileTask checkFileTask = new CheckFileTask(server.getServerInfo());
    CreateDbTask createDbTask = new CreateDbTask(server.getServerInfo());
    List<String> checkedDirsList = new ArrayList<String>();
    List<String> checkedFilesList = new ArrayList<String>();
    // add checked directory(general volume path)
    addVolumePath(checkedDirsList, generalVolumePath);
    String logPageNum = generalInfoPage.getLogPageNum();
    String logVolumePath = generalInfoPage.getLogVolumePath();
    // add checked directory(log volume path)
    addVolumePath(checkedDirsList, logVolumePath);
    List<Map<String, String>> volumeList = volumeInfoPage.getVolumeList();
    for (int i = 0; i < volumeList.size(); i++) {
        Map<String, String> map = volumeList.get(i);
        String volumeName = map.get("0");
        String volumePath = map.get("4");
        // add checked directory(additional volume path)
        addVolumePath(checkedDirsList, volumePath);
        // add checked file(additional volume)
        addVolumePath(checkedFilesList, volumePath + server.getServerInfo().getPathSeparator() + volumeName);
    }
    String[] dirs = new String[checkedDirsList.size()];
    checkDirTask.setDirectory(checkedDirsList.toArray(dirs));
    String[] files = new String[checkedFilesList.size()];
    checkFileTask.setFile(checkedFilesList.toArray(files));
    createDbTask.setDbName(databaseName);
    createDbTask.setPageSize(pageSize);
    if (logPageSize != null) {
        createDbTask.setLogPageSize(logPageSize);
    }
    if (charset != null) {
        createDbTask.setCharset(charset);
    }
    createDbTask.setNumPage(generalPageNum);
    createDbTask.setGeneralVolumePath(generalVolumePath);
    createDbTask.setLogSize(logPageNum);
    createDbTask.setLogVolumePath(logVolumePath);
    createDbTask.setExVolumes(volumeList);
    if (!checkedDirsList.isEmpty()) {
        taskExcutor.addTask(checkDirTask);
    }
    if (!checkedFilesList.isEmpty()) {
        taskExcutor.addTask(checkFileTask);
    }
    taskExcutor.addTask(createDbTask);
    //add set auto added volume
    GetAutoAddVolumeInfo returnInfo = setAutoAddVolumeInfoPage.getAutoAddVolumeInfo();
    if (returnInfo != null) {
        SetAutoAddVolumeTask setTask = new SetAutoAddVolumeTask(server.getServerInfo());
        setTask.setDbname(databaseName);
        setTask.setData(returnInfo.getData());
        setTask.setDataWarnOutofspace(returnInfo.getData_warn_outofspace());
        setTask.setDataExtPage(returnInfo.getData_ext_page());
        setTask.setIndex(returnInfo.getIndex());
        setTask.setIndexWarnOutofspace(returnInfo.getIndex_warn_outofspace());
        setTask.setIndexExtPage(returnInfo.getIndex_ext_page());
        taskExcutor.addTask(setTask);
    }
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(server.getServerInfo());
    taskExcutor.addTask(getCubridConfParameterTask);
    SetCubridConfParameterTask setCubridConfParameterTask = new SetCubridConfParameterTask(server.getServerInfo());
    taskExcutor.addTask(setCubridConfParameterTask);
    //start database
    CommonUpdateTask startDbTask = new CommonUpdateTask(CommonTaskName.START_DB_TASK_NAME, server.getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
    startDbTask.setDbName(databaseName);
    taskExcutor.addTask(startDbTask);
    //set dba password
    UpdateAddUserTask updateUserTask = new UpdateAddUserTask(server.getServerInfo(), false);
    UserSendObj userSendObj = new UserSendObj();
    userSendObj.setDbname(databaseName);
    userSendObj.setUsername("dba");
    String password = setDbaPasswordPage.getPassword();
    userSendObj.setUserpass(password);
    updateUserTask.setUserSendObj(userSendObj);
    taskExcutor.addTask(updateUserTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = server.getName();
    jobFamily.setServerName(serverName);
    String jobName = Messages.msgCreateDbrearJobName + " - " + serverName;
    taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
    //the close is in the job
    return false;
}
Also used : ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) UserSendObj(com.cubrid.cubridmanager.core.cubrid.database.model.UserSendObj) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) SetAutoAddVolumeTask(com.cubrid.cubridmanager.core.cubrid.dbspace.task.SetAutoAddVolumeTask) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) OverrideFileDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.OverrideFileDialog) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) CreateDirDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.CreateDirDialog) SetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask) UpdateAddUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.UpdateAddUserTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) CreateDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.CreateDbTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Map(java.util.Map) GetAutoAddVolumeInfo(com.cubrid.cubridmanager.core.cubrid.dbspace.model.GetAutoAddVolumeInfo)

Example 35 with JobFamily

use of com.cubrid.common.ui.spi.progress.JobFamily in project cubrid-manager by CUBRID.

the class UnloadDatabaseDialog method unloadDatabase.

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

        private List<String> unloadResultList = null;

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

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

                    public void run() {
                        setReturnCode(buttonId);
                        close();
                    }
                });
                isCanFinished = true;
                return Status.CANCEL_STATUS;
            }
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (monitor.isCanceled()) {
                    cancel();
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                    isCanFinished = true;
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            getShell().setVisible(true);
                        }
                    });
                    isCanFinished = false;
                    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.getDefault().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.getDefault().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 UnloadDatabaseTask) {
                    UnloadDatabaseTask unloadDatabaseTask = (UnloadDatabaseTask) task;
                    if (!isSchemaOnly) {
                        unloadResultList = unloadDatabaseTask.getUnloadDbResult();
                    }
                }
                if (!isCanFinished) {
                    return Status.CANCEL_STATUS;
                }
                if (monitor.isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

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

        /**
			 * Notification that a job has completed execution,
			 * 
			 * @param event the event details
			 */
        public void done(IJobChangeEvent event) {
            if (event.getResult() == Status.OK_STATUS) {
                if (isSchemaOnly) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgSuccessUnload);
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                } else {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            UnloadDatabaseResultDialog dialog = new UnloadDatabaseResultDialog(getShell());
                            dialog.setUnloadResulList(unloadResultList);
                            dialog.open();
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                }
            }
        }
    };
    CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
    CheckFileTask checkFileTask = new CheckFileTask(database.getServer().getServerInfo());
    final UnloadDatabaseTask unloadDatabaseTask = new UnloadDatabaseTask(database.getServer().getServerInfo(), database.getDatabaseInfo().getCharSet());
    fillTask(taskExcutor, checkDirTask, checkFileTask, unloadDatabaseTask);
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    String jobName = Messages.msgUnloadDbRearJobName + " - " + dbName + "@" + serverName;
    JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    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) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) List(java.util.List) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) UnloadDatabaseTask(com.cubrid.cubridmanager.core.cubrid.database.task.UnloadDatabaseTask)

Aggregations

JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)44 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)24 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)19 ITask (com.cubrid.common.core.task.ITask)14 Job (org.eclipse.core.runtime.jobs.Job)14 ArrayList (java.util.ArrayList)12 IStatus (org.eclipse.core.runtime.IStatus)12 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)7 List (java.util.List)7 CheckDirTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)6 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)5 CommonUpdateTask (com.cubrid.cubridmanager.core.common.task.CommonUpdateTask)5 GetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask)5 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)5 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)4 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)4 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)4 CheckFileTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask)4