Search in sources :

Example 1 with RenameDbTask

use of com.cubrid.cubridmanager.core.cubrid.database.task.RenameDbTask 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)

Aggregations

ITask (com.cubrid.common.core.task.ITask)1 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)1 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)1 GetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask)1 SetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask)1 CheckDirTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)1 RenameDbTask (com.cubrid.cubridmanager.core.cubrid.database.task.RenameDbTask)1 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1