use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class EditUserDialog method buttonPressed.
/**
* When press button,call it
*
* @param buttonId the button id
*/
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
if (!valid()) {
return;
}
boolean isChangePassword = false;
if (newFlag) {
isChangePassword = true;
} else if (changePwdBtn.getSelection()) {
isChangePassword = true;
}
String password = null;
if (isChangePassword) {
password = pwdText.getText();
if (password == null) {
password = "";
}
}
this.inputtedPassword = password;
boolean isNoDbaAuthUser = database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName) && !database.getDatabaseInfo().getAuthLoginedDbUserInfo().isDbaAuthority();
String taskName = Messages.bind(Messages.addOrUpdateUserTaskName, userNameText.getText());
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
ITask task = null;
boolean isDropAndCreateUser = false;
if (isNoDbaAuthUser) {
if (isChangePassword) {
task = new ChangeDbUserPwdTask(database.getDatabaseInfo());
ChangeDbUserPwdTask changeDbUserPwdTask = (ChangeDbUserPwdTask) task;
changeDbUserPwdTask.setDbUserName(userName);
changeDbUserPwdTask.setNewPwd(password);
taskExecutor.addTask(changeDbUserPwdTask);
} else {
super.buttonPressed(IDialogConstants.CANCEL_ID);
return;
}
} else {
if (newFlag) {
List<String> groupList = new ArrayList<String>();
for (int i = 0; i < userGroupTable.getItemCount(); i++) {
groupList.add(userGroupTable.getItem(i).getText(0));
}
List<String> memberList = new ArrayList<String>();
for (Map<String, String> map : memberListData) {
memberList.add(map.get("0").toLowerCase(Locale.getDefault()));
}
task = new CreateUserTask(database.getDatabaseInfo(), userNameText.getText(), pwdText.getText(), groupList, memberList);
taskExecutor.addTask(task);
} else {
if (!groupChange()) {
task = new DropUserTask(database.getDatabaseInfo(), userName);
taskExecutor.addTask(task);
List<String> groupList = new ArrayList<String>();
for (int i = 0; i < userGroupTable.getItemCount(); i++) {
groupList.add(userGroupTable.getItem(i).getText(0));
}
List<String> memberList = new ArrayList<String>();
for (Map<String, String> map : memberListData) {
memberList.add(map.get("0").toLowerCase(Locale.getDefault()));
}
task = new CreateUserTask(database.getDatabaseInfo(), userNameText.getText(), pwdText.getText(), groupList, memberList);
taskExecutor.addTask(task);
isDropAndCreateUser = true;
} else if (isChangePassword) {
task = new ChangeDbUserPwdTask(database.getDatabaseInfo());
ChangeDbUserPwdTask changeDbUserPwdTask = (ChangeDbUserPwdTask) task;
changeDbUserPwdTask.setDbUserName(userName);
changeDbUserPwdTask.setNewPwd(password);
taskExecutor.addTask(task);
}
}
}
task = new UpdateAddUserJdbcTask(database.getDatabaseInfo(), userNameText.getText(), classGrantMap, authListData, authListDataOld, isDBAGroup(), isDropAndCreateUser);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
if (taskExecutor.isSuccess() && isChangePassword && database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName)) {
database.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(password);
}
if (taskExecutor.isSuccess()) {
String message = null;
if (newFlag) {
message = Messages.msgAddUserSuccess;
} else {
message = Messages.msgModifyUserSuccess;
}
CommonUITool.openInformationBox(Messages.msgInformation, message);
} else {
return;
}
}
super.buttonPressed(buttonId);
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class AlterTriggerAction method run.
/**
* edit trigger
* @param database
* @param node
* @return
*/
public int run(final CubridDatabase database, final ISchemaNode node) {
// FIXME move this logic to core module
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
for (ITask task : taskList) {
task.execute();
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
Trigger trigger = null;
if (task instanceof GetTriggerListTask) {
GetTriggerListTask getTriggerListTask = (GetTriggerListTask) task;
List<Trigger> triggerList = getTriggerListTask.getTriggerInfoList();
for (int i = 0; triggerList != null && i < triggerList.size(); i++) {
Trigger trig = triggerList.get(i);
if (node.getName().equals(trig.getName())) {
trigger = trig;
break;
}
}
} else if (task instanceof JDBCGetTriggerInfoTask) {
JDBCGetTriggerInfoTask getTriggerInfoTask = (JDBCGetTriggerInfoTask) task;
trigger = getTriggerInfoTask.getTriggerInfo(node.getLabel());
}
if (trigger == null) {
openErrorBox(shell, Messages.errNameNoExist, monitor);
return false;
}
// getting comment for version after 10.0
if (CompatibleUtil.isCommentSupports(database.getDatabaseInfo())) {
try {
SchemaComment schemaComment = SchemaCommentHandler.loadObjectDescription(database.getDatabaseInfo(), JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true), trigger.getName(), CommentType.TRIGGER);
trigger.setDescription(schemaComment.getDescription());
} catch (SQLException e) {
CommonUITool.openErrorBox(e.getMessage());
}
}
node.setModelObj(trigger);
}
return true;
}
};
ITask task = null;
if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
task = new GetTriggerListTask(database.getServer().getServerInfo());
((GetTriggerListTask) task).setDbName(database.getName());
} else {
task = new JDBCGetTriggerInfoTask(database.getDatabaseInfo());
}
taskExcutor.addTask(task);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (!taskExcutor.isSuccess()) {
return IDialogConstants.CANCEL_ID;
}
CreateTriggerDialog dialog = new CreateTriggerDialog(getShell(), node.getDatabase(), (Trigger) node.getAdapter(Trigger.class));
if (dialog.open() != IDialogConstants.CANCEL_ID) {
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
ActionManager.getInstance().fireSelectionChanged(getSelection());
return IDialogConstants.OK_ID;
}
return IDialogConstants.CANCEL_ID;
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class CommonTaskExec method exec.
/**
* Execute the task
*
* @param monitor the monitor
* @return <code>true</code>if success;<code>false</code> otherwise
*/
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
if (taskName != null) {
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
}
for (final ITask task : taskList) {
if (task instanceof AbstractUITask) {
((AbstractUITask) task).execute(monitor);
} else {
task.execute();
}
String errorMsg = task.getErrorMsg();
if (messageHandler != null) {
errorMsg = messageHandler.translate(task.getErrorMsg());
}
if (openErrorBox(null, errorMsg, monitor)) {
return false;
}
// });
if (taskExeStatus != null && taskExeStatus == Status.CANCEL_STATUS) {
return false;
}
if (taskExeStatus != null && taskExeStatus != Status.OK_STATUS) {
errorMsg = taskExeStatus.getMessage();
if (messageHandler != null) {
errorMsg = messageHandler.translate(taskExeStatus.getMessage());
}
openErrorBox(null, errorMsg, monitor);
return false;
}
if (monitor.isCanceled()) {
return false;
}
}
// });
return true;
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class CommonTaskJobExec method exec.
/**
* Execute the task
*
* @param monitor the monitor
* @return <code>true</code>if success;<code>false</code> otherwise
*/
public IStatus exec(IProgressMonitor monitor) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
setDialogVisible(false);
}
});
if (monitor.isCanceled()) {
cancel();
Display.getDefault().syncExec(new Runnable() {
public void run() {
closeDialog();
}
});
return Status.CANCEL_STATUS;
}
for (final ITask task : taskList) {
if (task instanceof AbstractUITask) {
((AbstractUITask) task).execute(monitor);
} else {
task.execute();
}
final String msg = task.getErrorMsg();
if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
setDialogVisible(true);
}
});
return new Status(IStatus.ERROR, CommonUIPlugin.PLUGIN_ID, msg);
} else {
Display.getDefault().syncExec(new Runnable() {
public void run() {
taskExeStatus = refresh(task);
}
});
}
if (taskExeStatus != Status.OK_STATUS) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
setDialogVisible(true);
}
});
return taskExeStatus;
}
if (monitor.isCanceled()) {
cancel();
Display.getDefault().syncExec(new Runnable() {
public void run() {
closeDialog();
}
});
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
use of com.cubrid.common.core.task.ITask 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);
}
Aggregations