提交 5b6d7b42 编写于 作者: J jurgen

Use job instead of progress service.

上级 2e3552c7
......@@ -37,6 +37,7 @@ import org.jkiss.dbeaver.model.net.DBWTunnel;
import org.jkiss.dbeaver.model.runtime.*;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.model.virtual.DBVModel;
import org.jkiss.dbeaver.runtime.TaskstJob;
import org.jkiss.dbeaver.runtime.properties.PropertyCollector;
import org.jkiss.dbeaver.ui.actions.datasource.DataSourceHandler;
import org.jkiss.utils.CommonUtils;
......@@ -288,25 +289,20 @@ public class DataSourceDescriptor
if (updateContext != null) {
final DBCTransactionManager txnManager = DBUtils.getTransactionManager(updateContext);
if (updateConnection && txnManager != null) {
try {
DBeaverUI.runInProgressDialog(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
monitor.beginTask("Set auto-commit mode", 1);
try {
// Change auto-commit mode
txnManager.setAutoCommit(monitor, autoCommit);
} catch (DBCException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
new TaskstJob("Set auto-commit mode", new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
try {
// Change auto-commit mode
txnManager.setAutoCommit(monitor, autoCommit);
} catch (DBCException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
});
} catch (InvocationTargetException e) {
throw new DBException("Can't set auto-commit", e.getTargetException());
}
}
}).schedule();
}
}
// Save in preferences
......
......@@ -21,11 +21,13 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dialogs.exec.ExecutionQueueErrorJob;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
......@@ -41,6 +43,10 @@ public class TaskstJob extends AbstractJob
this.tasks = new ArrayList<DBRRunnableWithProgress>(tasks);
}
public TaskstJob(String name, DBRRunnableWithProgress task) {
this(name, Collections.singletonList(task));
}
@Override
protected IStatus run(DBRProgressMonitor monitor) {
monitor.beginTask(getName(), tasks.size());
......@@ -53,17 +59,11 @@ public class TaskstJob extends AbstractJob
try {
task.run(monitor);
} catch (InvocationTargetException e) {
if (!ignoreErrors) {
ExecutionQueueErrorJob errorJob = new ExecutionQueueErrorJob(getName(), e.getTargetException(), tasks.size() > 1);
errorJob.schedule();
try {
errorJob.join();
} catch (InterruptedException e1) {
log.error(e1);
}
if (tasks.size() == 1) {
UIUtils.showErrorDialog(null, getName(), null, e.getTargetException());
} else if (!ignoreErrors) {
boolean keepRunning = true;
switch (errorJob.getResponse()) {
switch (ExecutionQueueErrorJob.showError(getName(), e.getTargetException(), true)) {
case STOP:
keepRunning = false;
break;
......@@ -85,6 +85,7 @@ public class TaskstJob extends AbstractJob
} catch (InterruptedException e) {
// Ignore
}
monitor.worked(1);
i++;
}
monitor.done();
......
......@@ -23,9 +23,12 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.IWorkbenchPartSite;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPPreferenceStore;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.data.DBDDataFilter;
import org.jkiss.dbeaver.model.data.DBDDataReceiver;
import org.jkiss.dbeaver.model.exec.*;
......@@ -37,11 +40,12 @@ import org.jkiss.dbeaver.model.sql.SQLQuery;
import org.jkiss.dbeaver.model.sql.SQLQueryParameter;
import org.jkiss.dbeaver.model.sql.SQLQueryResult;
import org.jkiss.dbeaver.runtime.RunnableWithResult;
import org.jkiss.dbeaver.ui.dialogs.exec.ExecutionQueueErrorJob;
import org.jkiss.dbeaver.runtime.jobs.DataSourceJob;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dialogs.exec.ExecutionQueueErrorJob;
import org.jkiss.dbeaver.ui.dialogs.exec.ExecutionQueueErrorResponse;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
......@@ -162,20 +166,13 @@ public class SQLQueryJob extends DataSourceJob
log.error(lastError);
}
boolean isQueue = queryNum < queries.size() - 1;
ExecutionQueueErrorJob errorJob = new ExecutionQueueErrorJob(
ExecutionQueueErrorResponse response = ExecutionQueueErrorJob.showError(
isQueue ? "SQL script execution" : "SQL query execution",
lastError,
isQueue);
errorJob.schedule();
try {
errorJob.join();
}
catch (InterruptedException e) {
log.error(e);
}
boolean stopScript = false;
switch (errorJob.getResponse()) {
switch (response) {
case STOP:
// just stop execution
stopScript = true;
......
......@@ -18,8 +18,8 @@
package org.jkiss.dbeaver.tools.transfer.database;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
......@@ -30,11 +30,12 @@ import org.jkiss.dbeaver.model.sql.SQLDataSource;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.model.struct.rdb.DBSCatalog;
import org.jkiss.dbeaver.model.struct.rdb.DBSSchema;
import org.jkiss.dbeaver.ui.dialogs.exec.ExecutionQueueErrorJob;
import org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer;
import org.jkiss.dbeaver.tools.transfer.IDataTransferProcessor;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.actions.navigator.NavigatorHandlerObjectOpen;
import org.jkiss.dbeaver.ui.dialogs.exec.ExecutionQueueErrorJob;
import org.jkiss.dbeaver.ui.dialogs.exec.ExecutionQueueErrorResponse;
import org.jkiss.utils.CommonUtils;
import java.util.*;
......@@ -143,19 +144,11 @@ public class DatabaseTransferConsumer implements IDataTransferConsumer<DatabaseC
} catch (Throwable e) {
log.error("Error inserting row", e);
if (!ignoreErrors) {
ExecutionQueueErrorJob errorJob = new ExecutionQueueErrorJob(
ExecutionQueueErrorResponse response = ExecutionQueueErrorJob.showError(
DBUtils.getObjectFullName(containerMapping.getTarget()) + " data load",
e,
true);
errorJob.schedule();
try {
errorJob.join();
}
catch (InterruptedException e1) {
// ignore
throw new DBCException("Transfer interrupted", e);
}
switch (errorJob.getResponse()) {
switch (response) {
case STOP:
// just stop execution
throw new DBCException("Can't insert row", e);
......
......@@ -68,4 +68,16 @@ public class ExecutionQueueErrorJob extends AbstractUIJob {
{
return response;
}
public static ExecutionQueueErrorResponse showError(String task, Throwable error, boolean queue) {
ExecutionQueueErrorJob errorJob = new ExecutionQueueErrorJob(task, error, queue);
errorJob.schedule();
try {
errorJob.join();
} catch (InterruptedException e1) {
log.error(e1);
}
return errorJob.getResponse();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册