use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class LoginDatabaseTaskExecutor method exec.
/**
* Execute to login database
*
* @param monitor the IProgressMonitor
* @return <code>true</code> if successful;<code>false</code>otherwise;
*/
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
String taskName = Messages.bind(Messages.loginDbTaskName, dbName);
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
DbUserInfo dbUserInfo = null;
DatabaseInfo dbInfo = serverInfo.getLoginedUserInfo().getDatabaseInfo(dbName);
DbUserInfo preDbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
boolean isOldLogined = dbInfo.isLogined();
for (ITask task : taskList) {
if (task instanceof UpdateCMUserTask) {
UpdateCMUserTask updateCMUserTask = (UpdateCMUserTask) task;
ServerInfo serverInfo = dbInfo.getServerInfo();
if (serverInfo != null && serverInfo.isConnected()) {
ServerUserInfo userInfo = serverInfo.getLoginedUserInfo();
updateCMUserTask.setCasAuth(userInfo.getCasAuth().getText());
updateCMUserTask.setDbCreator(userInfo.getDbCreateAuthType().getText());
updateCMUserTask.setStatusMonitorAuth(userInfo.getStatusMonitorAuth().getText());
List<String> dbNameList = new ArrayList<String>();
List<String> dbUserList = new ArrayList<String>();
List<String> dbPasswordList = new ArrayList<String>();
List<String> dbBrokerPortList = new ArrayList<String>();
List<DatabaseInfo> authDatabaseList = userInfo.getDatabaseInfoList();
for (int i = 0; authDatabaseList != null && i < authDatabaseList.size(); i++) {
DatabaseInfo databaseInfo = authDatabaseList.get(i);
dbNameList.add(databaseInfo.getDbName());
dbUserList.add(databaseInfo.getAuthLoginedDbUserInfo().getName());
dbBrokerPortList.add(QueryOptions.getBrokerIp(databaseInfo) + "," + databaseInfo.getBrokerPort());
String password = databaseInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
dbPasswordList.add(password == null ? "" : password);
}
String[] dbNameArr = new String[dbNameList.size()];
String[] dbUserArr = new String[dbUserList.size()];
String[] dbPasswordArr = new String[dbPasswordList.size()];
String[] dbBrokerPortArr = new String[dbBrokerPortList.size()];
updateCMUserTask.setDbAuth(dbNameList.toArray(dbNameArr), dbUserList.toArray(dbUserArr), dbPasswordList.toArray(dbPasswordArr), dbBrokerPortList.toArray(dbBrokerPortArr));
}
}
task.execute();
final String msg = task.getErrorMsg();
if (showErrMsg) {
if (openErrorBox(shell, msg, monitor)) {
dbInfo.setLogined(isOldLogined);
dbInfo.setAuthLoginedDbUserInfo(preDbUserInfo);
// LOGGER.error("loggin failed task : " + infoMessage);
return false;
}
} else if (!monitor.isCanceled()) {
setErrMsg(msg);
dbInfo.setLogined(isOldLogined);
dbInfo.setAuthLoginedDbUserInfo(preDbUserInfo);
return false;
}
if (monitor.isCanceled()) {
return false;
}
if (task instanceof LoginDatabaseTask) {
dbUserInfo = ((LoginDatabaseTask) task).getLoginedDbUserInfo();
dbInfo.setLogined(true);
dbUserInfo.setNoEncryptPassword(dbPassword);
dbInfo.setAuthLoginedDbUserInfo(dbUserInfo);
}
}
return true;
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class LogEditorPart method connect.
/**
* Each page of log connect
*
* @param isCreateColumn boolean
*
*/
public void connect(final boolean isCreateColumn) {
GetLogListTask task = null;
if (charsetName == null) {
task = new GetLogListTask(this.cubridNode.getServer().getServerInfo());
} else {
task = new GetLogListTask(this.cubridNode.getServer().getServerInfo(), charsetName);
}
task.setPath(path);
task.setStart(Long.toString(lineStart));
task.setEnd(Long.toString(lineEnd));
TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {
public IStatus exec(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
for (final ITask task : taskList) {
task.execute();
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
} else {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (task instanceof GetLogListTask) {
GetLogListTask getLogListTask = (GetLogListTask) task;
LogContentInfo logContentInfo = (LogContentInfo) getLogListTask.getLogContent();
setTableInfo(logContentInfo, isCreateColumn);
}
}
});
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
};
taskJobExecutor.addTask(task);
String jobName = Messages.viewLogJobName + " - " + cubridNode.getName() + "@" + cubridNode.getServer().getName();
taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class LogViewAction method run.
/**
* Open the log editor and show log content
*/
public void run() {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
if (cubridNode == null) {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
setEnabled(false);
return;
}
cubridNode = (ICubridNode) obj[0];
}
LogInfo logInfo = (LogInfo) cubridNode.getAdapter(LogInfo.class);
final String filePath = logInfo.getPath();
TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {
public IStatus exec(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
cubridNode = null;
return Status.CANCEL_STATUS;
}
for (ITask task : taskList) {
task.execute();
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
cubridNode = null;
return Status.CANCEL_STATUS;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
cubridNode = null;
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
}
if (task instanceof CheckFileTask) {
CheckFileTask checkFileTask = (CheckFileTask) task;
final String[] files = checkFileTask.getExistFiles();
if (files == null || files.length == 0) {
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, Messages.bind(Messages.errLogFileNoExist, filePath));
}
} else if (task instanceof GetLogListTask) {
GetLogListTask getLogListTask = (GetLogListTask) task;
final LogContentInfo logContentInfo = (LogContentInfo) getLogListTask.getLogContent();
Display.getDefault().syncExec(new Runnable() {
public void run() {
IEditorPart editorPart = LayoutUtil.getEditorPart(cubridNode, LogEditorPart.ID);
if (editorPart != null) {
window.getActivePage().closeEditor(editorPart, false);
}
try {
IEditorPart editor = window.getActivePage().openEditor(cubridNode, LogEditorPart.ID);
((LogEditorPart) editor).setTableInfo(logContentInfo, true);
} catch (PartInitException e) {
LOGGER.error(e.getMessage(), e);
}
}
});
}
if (monitor.isCanceled()) {
cubridNode = null;
return Status.CANCEL_STATUS;
}
}
cubridNode = null;
return Status.OK_STATUS;
}
};
CheckFileTask checkFileTask = new CheckFileTask(cubridNode.getServer().getServerInfo());
checkFileTask.setFile(new String[] { filePath });
taskJobExecutor.addTask(checkFileTask);
GetLogListTask task = new GetLogListTask(cubridNode.getServer().getServerInfo());
task.setPath(filePath);
task.setStart("1");
task.setEnd("100");
taskJobExecutor.addTask(task);
String jobName = Messages.viewLogJobName + " - " + cubridNode.getName() + "@" + cubridNode.getServer().getName();
taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
}
use of com.cubrid.common.core.task.ITask 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);
}
use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.
the class EditTableAction method doRun.
private void doRun(ISchemaNode table, int type) {
final DatabaseInfo databaseInfo = NodeUtil.findDatabaseInfo(table);
if (databaseInfo == null) {
return;
}
final String tableName = table.getName();
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;
}
}
databaseInfo.removeSchema(tableName);
SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
if (schemaInfo == null) {
openErrorBox(shell, databaseInfo.getErrorMessage(), monitor);
return false;
}
return true;
}
};
boolean supportCharset = CompatibleUtil.isSupportCreateDBByCharset(databaseInfo);
JDBCGetAllDbUserTask allUserTask = new JDBCGetAllDbUserTask(databaseInfo);
taskExcutor.addTask(allUserTask);
GetCollations collationTask = null;
if (supportCharset) {
collationTask = new GetCollations(databaseInfo);
taskExcutor.addTask(collationTask);
}
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (!taskExcutor.isSuccess()) {
return;
}
List<String> dbUserList = allUserTask.getDbUserList();
SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
TableEditorInput input = new TableEditorInput(table.getDatabase(), false, schemaInfo, table, type);
input.setDbUserList(dbUserList);
if (supportCharset) {
List<Collation> collations = collationTask.getCollations();
input.setCollationList(collations);
}
try {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
//If true, active opened editor of it and return, else open new editor.
for (IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
IEditorPart oldEditor = editorRef.getEditor(true);
if (oldEditor.getEditorInput() instanceof TableEditorInput) {
TableEditorInput oldInput = (TableEditorInput) oldEditor.getEditorInput();
ISchemaNode oldTable = oldInput.getEditedTableNode();
if (oldTable != null && oldTable.equals(table)) {
workbenchWindow.getActivePage().activate(oldEditor);
return;
}
}
}
workbenchWindow.getActivePage().openEditor(input, TableEditorPart.ID);
} catch (Exception ignore) {
}
}
Aggregations