use of com.cubrid.common.ui.spi.progress.TaskJobExecutor 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.ui.spi.progress.TaskJobExecutor 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.ui.spi.progress.TaskJobExecutor 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.ui.spi.progress.TaskJobExecutor in project cubrid-manager by CUBRID.
the class TableEditorPart method okPressed.
protected void okPressed() {
if (!verifyTableName()) {
return;
}
if (columnsTable.getItemCount() == 0) {
CommonUITool.openErrorBox(Messages.noAttributes);
return;
}
String message = (oldSchemaInfo == null) ? Messages.msgCreateTableConfirm : Messages.msgAlterTableConfirm;
if (!CommonUITool.openConfirmBox(message)) {
return;
}
tableName = tableNameText.getText();
owner = ownerCombo.getText();
String tableDesc = tableDescText.getText();
newSchemaInfo.setClassname(tableName);
newSchemaInfo.setOwner(owner);
newSchemaInfo.setDescription(tableDesc);
if (reuseOIDBtn != null) {
newSchemaInfo.setReuseOid(reuseOIDBtn.getSelection());
}
DatabaseInfo dbInfo = database.getDatabaseInfo();
CommonSQLExcuterTask commonSqlTask = new CommonSQLExcuterTask(dbInfo);
schemaDDL.setEndLineChar("$$$$");
String ddlStr = null;
if (isNewTableFlag) {
ddlStr = schemaDDL.getSchemaDDL(newSchemaInfo);
} else {
ddlStr = schemaDDL.getSchemaDDL(oldSchemaInfo, newSchemaInfo);
}
boolean isExecuteCommonSqlTask = false;
String[] sqlStr = ddlStr.split("\\$\\$\\$\\$");
for (String sql : sqlStr) {
String trimSql = sql.trim();
if (trimSql.length() > 0 && !trimSql.startsWith("--")) {
if (dbInfo.isShard()) {
sql = dbInfo.wrapShardQuery(sql);
}
commonSqlTask.addSqls(sql);
isExecuteCommonSqlTask = true;
}
}
// do with table user change
String changeOwnerDDL = getChangeOwnerDDL();
if (StringUtil.isNotEmpty(changeOwnerDDL)) {
changeOwnerDDL = dbInfo.wrapShardQuery(changeOwnerDDL);
commonSqlTask.addCallSqls(changeOwnerDDL);
isExecuteCommonSqlTask = true;
}
schemaDDL.setEndLineChar(";");
// do with column null attribute change
List<String[]> nullAttrChangedColumnList = getNotNullChangedColumn();
// if the column is null value, when set this column for not null,need
// change these null value for default value
List<String> nullToDefaultChangedColumnList = new ArrayList<String>();
List<String> defaultValList = new ArrayList<String>();
if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
for (Iterator<String[]> it = nullAttrChangedColumnList.iterator(); it.hasNext(); ) {
String[] column = it.next();
if (!Boolean.parseBoolean(column[1])) {
continue;
}
nullToDefaultChangedColumnList.add(column[0]);
}
// if the column is null value, when set this column for not null,do
// not need change these null value for default value
List<String> keepNullValueColList = new ArrayList<String>();
for (Iterator<String> it = nullToDefaultChangedColumnList.iterator(); it.hasNext(); ) {
String nullColumn = it.next();
DBAttribute dBAttribute = newSchemaInfo.getDBAttributeByName(nullColumn, false);
if (dBAttribute == null) {
continue;
}
String defaultVal = dBAttribute.getDefault();
boolean isUnique = dBAttribute.isUnique();
if (isUnique) {
keepNullValueColList.add(nullColumn);
it.remove();
} else {
if (defaultVal == null) {
keepNullValueColList.add(nullColumn);
it.remove();
continue;
} else {
FormatDataResult result = DBAttrTypeFormatter.formatForInput(dBAttribute.getType(), defaultVal, false);
if (result.isSuccess()) {
defaultValList.add(result.getFormatResult());
}
}
}
}
String msg = Messages.bind(Messages.confirmSetDef, nullToDefaultChangedColumnList);
if (!nullToDefaultChangedColumnList.isEmpty() && (!CommonUITool.openConfirmBox(msg))) {
return;
}
msg = Messages.bind(Messages.confirmKeepNull, keepNullValueColList);
if (!keepNullValueColList.isEmpty() && (!CommonUITool.openConfirmBox(msg))) {
return;
}
}
TaskJobExecutor taskJobExec = new CommonTaskJobExec(this);
boolean hasChanges = isExecuteCommonSqlTask || !nullAttrChangedColumnList.isEmpty() || !nullToDefaultChangedColumnList.isEmpty();
if (hasChanges) {
if (isExecuteCommonSqlTask) {
taskJobExec.addTask(commonSqlTask);
}
if (database == null || newSchemaInfo == null) {
return;
}
// change all table data from null value to default value
int nullColSize = nullToDefaultChangedColumnList.size();
for (int colIndex = 0; colIndex < nullColSize; colIndex++) {
UpdateNullToDefault updateNullToDefault = new UpdateNullToDefault(dbInfo);
updateNullToDefault.setTable(tableName);
updateNullToDefault.setColumn(nullToDefaultChangedColumnList.get(colIndex));
updateNullToDefault.setDefaultValue(defaultValList.get(colIndex));
taskJobExec.addTask(updateNullToDefault);
}
}
List<UpdateDescriptionTask> updateDescriptionTaskList = getUpdateDescriptionTaskList(dbInfo);
for (UpdateDescriptionTask task : updateDescriptionTaskList) {
taskJobExec.addTask(task);
}
if (taskJobExec.getTaskCount() > 0) {
String serverName = database.getServer().getName();
String dbName = database.getDatabaseInfo().getDbName();
String title = getSite().getShell().getText();
jobName = title + " - " + tableName + "@" + dbName;
JobFamily jobFamily = new JobFamily();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
taskJobExec.schedule(jobName, jobFamily, true, Job.SHORT);
} else {
getSite().getWorkbenchWindow().getActivePage().closeEditor(editor, false);
}
}
use of com.cubrid.common.ui.spi.progress.TaskJobExecutor in project cubrid-manager by CUBRID.
the class DatabaseDashboardEditor method showLogView.
/**
* show sql log view at broker table
*
* @param type sql type
*/
public void showLogView(String type) {
try {
int i = brokerInfoTable.getSelectionIndex();
if (i < 0) {
return;
}
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
String brokerName = brokerInfoTable.getItem(i).getText(0);
String serverId = brokerInfoTable.getItem(i).getText(1);
//get all log infor
BrokerLogInfos brokerLogInfos = new BrokerLogInfos();
final CommonQueryTask<BrokerLogInfos> task = new CommonQueryTask<BrokerLogInfos>(database.getDatabaseInfo().getServerInfo(), CommonSendMsg.getGetBrokerLogFileInfoMSGItems(), brokerLogInfos);
task.setBroker(brokerName);
task.execute();
brokerLogInfos = task.getResultModel();
String logFileName = brokerName + "_" + serverId + "." + type + ".log";
sqlLogViewPartName = logFileName + "@" + database.getServer().getLabel() + ":" + database.getServer().getMonPort();
List<LogInfo> logInfoList = brokerLogInfos == null ? null : brokerLogInfos.getBrokerLogInfoList().getLogFileInfoList();
task.finish();
//get the current log
LogInfo logInfo = null;
if (logInfoList != null && !logInfoList.isEmpty()) {
for (LogInfo logInfoInlist : logInfoList) {
if (logFileName.equals(logInfoInlist.getName())) {
logInfo = logInfoInlist;
break;
}
}
}
if (logInfo == null) {
String msg = Messages.bind(com.cubrid.cubridmanager.ui.logs.Messages.errLogFileNoExist, logFileName);
LOGGER.error(msg);
//CommonUITool.openErrorBox(msg);
return;
}
final String filePath = logInfo.getPath();
TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {
public IStatus exec(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
for (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);
}
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(com.cubrid.cubridmanager.ui.logs.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() {
try {
ICubridNode logInfoNode = new DefaultCubridNode("", "", "");
IEditorPart editor = window.getActivePage().openEditor(logInfoNode, LogEditorPart.ID);
((LogEditorPart) editor).setTableInfo(logContentInfo, true);
((LogEditorPart) editor).setShowLogPartName(sqlLogViewPartName);
} catch (PartInitException e) {
LOGGER.error(e.getMessage(), e);
}
}
});
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
task.finish();
}
return Status.OK_STATUS;
}
};
CheckFileTask checkFileTask = new CheckFileTask(cubridNode.getServer().getServerInfo());
checkFileTask.setFile(new String[] { filePath });
taskJobExecutor.addTask(checkFileTask);
GetLogListTask getLogListTask = new GetLogListTask(cubridNode.getServer().getServerInfo());
getLogListTask.setPath(filePath);
getLogListTask.setStart("1");
getLogListTask.setEnd("100");
taskJobExecutor.addTask(getLogListTask);
String jobName = com.cubrid.cubridmanager.ui.logs.Messages.viewLogJobName + " - " + cubridNode.getName() + "@" + cubridNode.getServer().getName();
taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
} catch (Exception e) {
LOGGER.error(Messages.exportDashboardOpenSQLLogErrMsg, e);
// CommonUITool.openErrorBox(Messages.exportDashboardOpenSQLLogErrMsg);
}
}
Aggregations