未验证 提交 63c83096 编写于 作者: G George 提交者: GitHub

dbeaver/dbeaver-ee#1523 restructure notifications (#15947)

* dbeaver/dbeaver-ee#1523 restructure notifications

* dbeaver/dbeaver-ee#1523 remove redundant parameter
上级 f0198a5e
......@@ -59,8 +59,7 @@ public class SQLScriptExecuteHandler implements DBTTaskHandler {
@NotNull Locale locale,
@NotNull Log log,
@NotNull PrintStream logStream,
@NotNull DBTTaskExecutionListener listener,
boolean showNotifications) throws DBException
@NotNull DBTTaskExecutionListener listener) throws DBException
{
SQLScriptExecuteSettings settings = new SQLScriptExecuteSettings();
settings.loadConfiguration(runnableContext, task.getProperties());
......@@ -90,7 +89,7 @@ public class SQLScriptExecuteHandler implements DBTTaskHandler {
if (error != null) {
log.error(error);
}
listener.taskFinished(settings, null, error);
listener.taskFinished(task, null, error, settings);
log.debug("SQL script execute completed");
}
......
......@@ -87,12 +87,11 @@ public class DataTransferJob implements DBRRunnableWithProgress {
hasErrors = true;
}
} catch (Exception e) {
listener.subTaskFinished(e);
throw new InvocationTargetException(e);
}
}
monitor.done();
listener.subTaskFinished(null);
// listener.subTaskFinished(task, null);
elapsedTime = System.currentTimeMillis() - startTime;
}
......
......@@ -55,8 +55,7 @@ public class DTTaskHandlerTransfer implements DBTTaskHandler {
@NotNull Locale locale,
@NotNull Log log,
@NotNull PrintStream logStream,
@NotNull DBTTaskExecutionListener listener,
boolean showNotifications) throws DBException
@NotNull DBTTaskExecutionListener listener) throws DBException
{
DataTransferSettings[] settings = new DataTransferSettings[1];
try {
......@@ -82,7 +81,7 @@ public class DTTaskHandlerTransfer implements DBTTaskHandler {
try {
indexOfLastPipeWithDisabledReferentialIntegrity = initializePipes(runnableContext, settings);
Throwable error = runDataTransferJobs(runnableContext, task, locale, log, listener, settings);
listener.taskFinished(settings, null, error);
listener.taskFinished(task, null, error, settings);
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError(
DTMessages.data_transfer_task_handler_unexpected_error_title,
......@@ -151,7 +150,6 @@ public class DTTaskHandlerTransfer implements DBTTaskHandler {
} catch (InterruptedException e) {
break;
}
listener.subTaskFinished(error);
}
return error;
}
......
......@@ -42,9 +42,9 @@ public abstract class MySQLNativeToolHandler<SETTINGS extends AbstractNativeTool
private File config;
@Override
protected boolean doExecute(DBRProgressMonitor monitor, DBTTask task, SETTINGS settings, Log log, boolean showNotifications) throws DBException, InterruptedException {
protected boolean doExecute(DBRProgressMonitor monitor, DBTTask task, SETTINGS settings, Log log) throws DBException, InterruptedException {
try {
return super.doExecute(monitor, task, settings, log, showNotifications);
return super.doExecute(monitor, task, settings, log);
} finally {
if (config != null && !config.delete()) {
log.debug("Failed to delete configuration file");
......
......@@ -59,8 +59,7 @@ public abstract class SQLToolExecuteHandler<OBJECT_TYPE extends DBSObject, SETTI
@NotNull Locale locale,
@NotNull Log log,
@NotNull PrintStream logStream,
@NotNull DBTTaskExecutionListener listener,
boolean showNotifications) throws DBException
@NotNull DBTTaskExecutionListener listener) throws DBException
{
SETTINGS settings = createToolSettings();
settings.loadConfiguration(runnableContext, task.getProperties());
......@@ -210,7 +209,7 @@ public abstract class SQLToolExecuteHandler<OBJECT_TYPE extends DBSObject, SETTI
} finally {
monitor.done();
}
listener.taskFinished(settings, null, lastError);
listener.taskFinished(task, null, lastError, settings);
outLog.println("Tool execution finished");
outLog.flush();
......
......@@ -26,8 +26,8 @@ public interface DBTTaskExecutionListener {
void taskStarted(@NotNull Object task);
void taskFinished(@NotNull Object task, @Nullable Object result, @Nullable Throwable error);
void taskFinished(@NotNull DBTTask task, @Nullable Object result, @Nullable Throwable error, @Nullable Object settings);
void subTaskFinished(@Nullable Throwable error);
void subTaskFinished(@NotNull DBTTask task, @Nullable Throwable error, @Nullable Object settings);
}
......@@ -36,8 +36,7 @@ public interface DBTTaskHandler {
@NotNull Locale locale,
@NotNull Log log,
@NotNull PrintStream logStream,
@NotNull DBTTaskExecutionListener listener,
boolean showNotifications)
@NotNull DBTTaskExecutionListener listener)
throws DBException;
......
......@@ -23,6 +23,7 @@ import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.runtime.*;
import org.jkiss.dbeaver.model.task.DBTTask;
import org.jkiss.dbeaver.model.task.DBTTaskExecutionListener;
import org.jkiss.dbeaver.model.task.DBTTaskHandler;
import org.jkiss.dbeaver.model.task.DBTTaskRunStatus;
......@@ -123,7 +124,7 @@ public class TaskRunJob extends AbstractJob implements DBRRunnableContext {
private DBTTaskRunStatus executeTask(DBRProgressMonitor monitor, PrintStream logWriter) throws DBException {
activeMonitor = monitor;
DBTTaskHandler taskHandler = task.getType().createHandler();
return taskHandler.executeTask(this, task, locale, taskLog, logWriter, executionListener, true);
return taskHandler.executeTask(this, task, locale, taskLog, logWriter, executionListener);
}
@Override
......@@ -164,15 +165,15 @@ public class TaskRunJob extends AbstractJob implements DBRRunnableContext {
}
@Override
public void taskFinished(@NotNull Object task, @Nullable Object result, @Nullable Throwable error) {
parent.taskFinished(task, result, error);
public void taskFinished(@NotNull DBTTask task, @Nullable Object result, @Nullable Throwable error, @Nullable Object settings) {
parent.taskFinished(task, result, error, settings);
elapsedTime = System.currentTimeMillis() - startTime;
taskError = error;
}
@Override
public void subTaskFinished(@Nullable Throwable error) {
parent.subTaskFinished(error);
public void subTaskFinished(@NotNull DBTTask task, @Nullable Throwable error, @Nullable Object settings) {
parent.subTaskFinished(task, error, settings);
}
}
......
......@@ -60,8 +60,7 @@ public abstract class AbstractNativeToolHandler<SETTINGS extends AbstractNativeT
@NotNull Locale locale,
@NotNull Log log,
@NotNull PrintStream logStream,
@NotNull DBTTaskExecutionListener listener,
boolean showNotifications) throws DBException {
@NotNull DBTTaskExecutionListener listener) throws DBException {
SETTINGS settings = createTaskSettings(runnableContext, task);
settings.setLogWriter(logStream);
if (!validateTaskParameters(task, settings, log)) {
......@@ -76,11 +75,11 @@ public abstract class AbstractNativeToolHandler<SETTINGS extends AbstractNativeT
listener.taskStarted(task);
Throwable error = null;
try {
doExecute(monitor, task, settings, log, showNotifications);
doExecute(monitor, task, settings, log);
} catch (Exception e) {
error = e;
} finally {
listener.taskFinished(settings, null, error);
listener.taskFinished(task, null, error, settings);
Log.setLogWriter(null);
monitor.worked(1);
......@@ -242,27 +241,7 @@ public abstract class AbstractNativeToolHandler<SETTINGS extends AbstractNativeT
}
}
protected void onSuccess(DBTTask task, SETTINGS settings, long workTime) {
StringBuilder message = new StringBuilder();
message.append("Task [").append(task.getName()).append("] is completed (").append(workTime).append("ms)");
List<String> objNames = new ArrayList<>();
for (BASE_OBJECT obj : settings.getDatabaseObjects()) {
objNames.add(obj.getName());
}
message.append("\nObject(s) processed: ").append(String.join(",", objNames));
DBWorkbench.getPlatformUI().showNotification(task.getName(), message.toString(), false);
}
protected void onError(DBTTask task, SETTINGS settings, long workTime) {
// DBWorkbench.getPlatformUI().showError(
// taskTitle,
// errorMessage == null ? "Internal error" : errorMessage,
// SWT.ICON_ERROR);
}
protected boolean doExecute(DBRProgressMonitor monitor, DBTTask task, SETTINGS settings, Log log, boolean showNotifications) throws DBException, InterruptedException {
protected boolean doExecute(DBRProgressMonitor monitor, DBTTask task, SETTINGS settings, Log log) throws DBException, InterruptedException {
validateClientHome(monitor, settings);
long startTime = System.currentTimeMillis();
......@@ -298,14 +277,6 @@ public abstract class AbstractNativeToolHandler<SETTINGS extends AbstractNativeT
long workTime = System.currentTimeMillis() - startTime;
notifyToolFinish(task.getType().getName() + " - " + task.getName() + " has finished", workTime);
if (isSuccess) {
if (showNotifications) {
onSuccess(task, settings, workTime);
}
} else {
onError(task, settings, workTime);
}
return isSuccess;
}
......
......@@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.jkiss.dbeaver.registry,
org.jkiss.dbeaver.ui,
org.jkiss.dbeaver.ui.navigator,
org.jkiss.dbeaver.ui.editors.base
org.jkiss.dbeaver.ui.editors.base,
org.jkiss.dbeaver.tasks.native
Export-Package: org.jkiss.dbeaver.tasks.ui,
org.jkiss.dbeaver.tasks.ui.registry,
org.jkiss.dbeaver.tasks.ui.wizard,
......
......@@ -25,16 +25,20 @@ import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPMessageType;
import org.jkiss.dbeaver.model.runtime.DBRRunnableContext;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.task.DBTTask;
import org.jkiss.dbeaver.model.task.DBTTaskExecutionListener;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.runtime.DBeaverNotifications;
import org.jkiss.dbeaver.runtime.ui.DBPPlatformUI;
import org.jkiss.dbeaver.tasks.nativetool.AbstractNativeToolSettings;
import org.jkiss.dbeaver.tasks.ui.internal.TaskUIMessages;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
public class TaskProcessorUI implements DBRRunnableContext, DBTTaskExecutionListener {
private static final Log log = Log.getLog(TaskProcessorUI.class);
......@@ -45,6 +49,7 @@ public class TaskProcessorUI implements DBRRunnableContext, DBTTaskExecutionList
private DBRRunnableContext staticContext;
private long startTime;
private boolean started;
private long timeSincePreviousTask;
public TaskProcessorUI(@NotNull DBRRunnableContext staticContext, @NotNull DBTTask task) {
this.staticContext = staticContext;
......@@ -72,42 +77,60 @@ public class TaskProcessorUI implements DBRRunnableContext, DBTTaskExecutionList
public void taskStarted(@NotNull Object task) {
this.started = true;
this.startTime = System.currentTimeMillis();
this.timeSincePreviousTask = startTime;
}
@Override
public void taskFinished(@NotNull Object task, @Nullable Object result, @Nullable Throwable error) {
public void taskFinished(@NotNull DBTTask task, @Nullable Object result, @Nullable Throwable error, @Nullable Object settings) {
this.started = false;
long elapsedTime = System.currentTimeMillis() - startTime;
sendNotification(task, error, elapsedTime, settings);
}
private void sendNotification(@NotNull DBTTask task, @Nullable Throwable error, long elapsedTime, @Nullable Object settings) {
UIUtils.asyncExec(() -> {
// Make a sound
Display.getCurrent().beep();
// Notify agent
boolean hasErrors = error != null;
DBPPlatformUI platformUI = DBWorkbench.getPlatformUI();
String completeMessage = this.task.getType().getName() + " " + TaskUIMessages.task_processor_ui_message_task_completed + " (" + RuntimeUtils.formatExecutionTime(elapsedTime) + ")";
StringBuilder completeMessage = new StringBuilder();
completeMessage.append(task.getType().getName()).append(" ").append(TaskUIMessages.task_processor_ui_message_task_completed).append(" (").append(RuntimeUtils.formatExecutionTime(elapsedTime)).append(")");
List<String> objects = new ArrayList<>();
if (settings instanceof AbstractNativeToolSettings) {
for (DBSObject databaseObject : ((AbstractNativeToolSettings<?>) settings).getDatabaseObjects()) {
objects.add(databaseObject.getName());
}
completeMessage.append("\nObject(s) processed: ").append(String.join(",", objects));
}
if (elapsedTime > platformUI.getLongOperationTimeout() * 1000) {
platformUI.notifyAgent(
completeMessage, !hasErrors ? IStatus.INFO : IStatus.ERROR);
completeMessage.toString(), !hasErrors ? IStatus.INFO : IStatus.ERROR);
}
if (isShowFinalMessage() && !hasErrors) {
// Show message box
DBeaverNotifications.showNotification(
"task",
this.task.getName(),
completeMessage,
task.getName(),
completeMessage.toString(),
DBPMessageType.INFORMATION,
null);
} else if (error != null) {
DBWorkbench.getPlatformUI().showError("Task error", "Task execution failed", error);
}
});
}
@Override
public void subTaskFinished(@Nullable Throwable error) {
public void subTaskFinished(@NotNull DBTTask task, @Nullable Throwable error, @Nullable Object settings) {
long elapsedTime = System.currentTimeMillis() - timeSincePreviousTask;
timeSincePreviousTask = System.currentTimeMillis();
sendNotification(task, error, elapsedTime, settings);
}
......
......@@ -46,7 +46,7 @@ public class TaskWizardExecutor extends TaskProcessorUI {
@Override
protected void runTask() throws DBException {
DBTTaskHandler handlerTransfer = getTask().getType().createHandler();
handlerTransfer.executeTask(this, getTask(), Locale.getDefault(), log, logWriter, this, true);
handlerTransfer.executeTask(this, getTask(), Locale.getDefault(), log, logWriter, this);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册