Search in sources :

Example 6 with JobFamily

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

the class StopServiceAction method doRun.

/**
	 * Perform do run
	 * 
	 * @param servers
	 */
public void doRun(CubridServer[] servers) {
    CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
    final TreeViewer viewer = view.getViewer();
    if (servers.length > 0) {
        CubridServer server = servers[0];
        if (isSupported(server)) {
            final JobFamily jobFamily = new JobFamily();
            final String serverName = server.getName();
            String dbName = JobFamily.ALL_DB;
            jobFamily.setServerName(serverName);
            jobFamily.setDbName(dbName);
            Job[] jobs = Job.getJobManager().find(jobFamily);
            if (jobs.length > 0) {
                CommonUITool.openWarningBox(Messages.bind(Messages.msgStopServiceWithJob, serverName));
                return;
            }
            TaskExecutor taskExcutor = new StopServiceExecutor(server, getShell(), viewer);
            ServerInfo serverInfo = server.getServerInfo();
            GetCubridConfParameterTask task = new GetCubridConfParameterTask(serverInfo);
            taskExcutor.addTask(task);
            new ExecTaskWithProgress(taskExcutor).exec();
        }
    }
//		for(CubridServer server : servers) {
//			final JobFamily jobFamily = new JobFamily();
//			final String serverName = server.getName();
//			String dbName = JobFamily.ALL_DB;
//			jobFamily.setServerName(serverName);
//			jobFamily.setDbName(dbName);
//			Job[] jobs = Job.getJobManager().find(jobFamily);
//			if (jobs.length > 0) {
//				CommonUITool.openWarningBox(Messages.bind(
//						Messages.msgStopServiceWithJob, serverName));
//				return;
//			}
//
//			TaskExecutor taskExcutor = new StopServiceExecutor(server, getShell(),
//					viewer);
//			ServerInfo serverInfo = server.getServerInfo();
//			GetCubridConfParameterTask task = new GetCubridConfParameterTask(
//					serverInfo);
//			taskExcutor.addTask(task);
//			new ExecTaskWithProgress(taskExcutor).exec();
//		}
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) Job(org.eclipse.core.runtime.jobs.Job)

Example 7 with JobFamily

use of com.cubrid.common.ui.spi.progress.JobFamily 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)

Example 8 with JobFamily

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

the class CheckDatabaseDialog method buttonPressed.

/**
	 * When press button in button bar,call this method
	 * 
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
        if (!verify()) {
            return;
        }
        CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.CHECK_DATABASE_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCheckDbSendMsg());
        task.setDbName(database.getName());
        task.setRepairDb(repairButton.getSelection() ? YesNoType.Y : YesNoType.N);
        String serverName = database.getServer().getName();
        String dbName = database.getName();
        jobName = Messages.msgCheckDbRearName + " - " + dbName + "@" + serverName;
        TaskJobExecutor taskExec = new CommonTaskJobExec(this);
        taskExec.addTask(task);
        JobFamily jobFamily = new JobFamily();
        jobFamily.setServerName(serverName);
        jobFamily.setDbName(dbName);
        taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
        return;
    }
    super.buttonPressed(buttonId);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily)

Example 9 with JobFamily

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

the class CompactDatabaseDialog method buttonPressed.

/**
	 * When press button in button bar,call this method
	 * 
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
        if (!verify()) {
            return;
        }
        if (CommonUITool.openConfirmBox(parentComp.getShell(), Messages.msgCompactConfirm)) {
            CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.COMPACT_DATABASE_TASK_NANE, database.getServer().getServerInfo(), CommonSendMsg.getCompactDbSendMsg());
            task.setDbName(database.getName());
            if (verboseBtn != null) {
                task.setVerbose(verboseBtn.getSelection() ? YesNoType.Y : YesNoType.N);
            }
            String serverName = database.getServer().getName();
            String dbName = database.getName();
            jobName = Messages.msgCompactDbRearJobName + " - " + dbName + "@" + serverName;
            TaskJobExecutor taskExec = new CommonTaskJobExec(this);
            taskExec.addTask(task);
            JobFamily jobFamily = new JobFamily();
            jobFamily.setServerName(serverName);
            jobFamily.setDbName(dbName);
            taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
            return;
        } else {
            return;
        }
    }
    super.buttonPressed(buttonId);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily)

Example 10 with JobFamily

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

the class DeleteTableAction method doRun.

/**
	 * Do run
	 * 
	 * @param obj
	 */
private void doRun(Object[] obj) {
    StringBuilder sb = new StringBuilder();
    final List<String> tableList = new ArrayList<String>();
    CubridDatabase database = null;
    for (int i = 0; i < obj.length; i++) {
        DefaultSchemaNode table = (DefaultSchemaNode) obj[i];
        database = table.getDatabase();
        final String tableName = table.getName();
        tableList.add(tableName);
        if (i < 100) {
            if (sb.length() > 0) {
                sb.append(", ");
            }
            sb.append(tableName);
        }
    }
    if (obj.length > 100) {
        sb.append("...");
    }
    String message = Messages.bind(Messages.confirmTableDeleteWarn, sb.toString());
    if (!CommonUITool.openConfirmBox(message)) {
        return;
    }
    final DelAllRecordsTask task = new DelAllRecordsTask(database.getDatabaseInfo());
    TaskJobExecutor taskExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            int[] rowCount = task.getDeleteRecordsCount();
            List<String> rowCountList = new ArrayList<String>();
            for (int i = 0; i < rowCount.length; i++) {
                rowCountList.add(String.valueOf(rowCount[i]));
            }
            String message = Messages.bind(Messages.resultTableDeleteInformantion, tableList, rowCountList);
            CommonUITool.openInformationBox(Messages.msg_information, message);
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    String[] tableNames = new String[tableList.size()];
    tableNames = tableList.toArray(tableNames);
    task.setTableName(tableNames);
    taskExec.addTask(task);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgDeleteTableDataJobName + " - " + tableList.toString() + "@" + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) DelAllRecordsTask(com.cubrid.cubridmanager.core.cubrid.table.task.DelAllRecordsTask) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) ArrayList(java.util.ArrayList) List(java.util.List) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

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