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);
}
Aggregations