use of com.cubrid.cubridmanager.core.cubrid.database.task.UnloadDatabaseTask 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);
}
Aggregations