提交 34d6ca0f 编写于 作者: A Alexander Fedorov

#2556 remove DBRResult

Former-commit-id: 194d034d
上级 76c7068e
......@@ -12,8 +12,6 @@ Require-Bundle: org.eclipse.core.runtime,
Export-Package: org.jkiss.dbeaver.debug,
org.jkiss.dbeaver.debug.core,
org.jkiss.dbeaver.debug.core.breakpoints,
org.jkiss.dbeaver.debug.core.model,
org.jkiss.dbeaver.runtime,
org.jkiss.dbeaver.runtime.core
org.jkiss.dbeaver.debug.core.model
Bundle-Activator: org.jkiss.dbeaver.debug.internal.core.DebugCoreActivator
Bundle-ActivationPolicy: lazy
......@@ -29,8 +29,6 @@ import org.jkiss.dbeaver.model.exec.DBCExecutionPurpose;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import org.jkiss.dbeaver.runtime.DBRResult;
import org.jkiss.dbeaver.runtime.DefaultResult;
public class DBGBaseController implements DBGController {
......@@ -50,7 +48,7 @@ public class DBGBaseController implements DBGController {
}
@Override
public DBRResult connect(DBRProgressMonitor monitor) {
public void connect(DBRProgressMonitor monitor) throws DBGException {
DBPDataSource dataSource = dataSourceDescriptor.getDataSource();
if (!dataSourceDescriptor.isConnected()) {
......@@ -60,7 +58,7 @@ public class DBGBaseController implements DBGController {
} catch (DBException e) {
String message = NLS.bind(DebugMessages.DatabaseDebugController_e_connecting_datasource, dataSourceDescriptor);
log.error(message, e);
return DefaultResult.error(message, e);
throw new DBGException(message, e);
}
}
try {
......@@ -70,9 +68,8 @@ public class DBGBaseController implements DBGController {
} catch (DBException e) {
String message = NLS.bind(DebugMessages.DatabaseDebugController_e_opening_debug_context, dataSourceDescriptor);
log.error(message, e);
return DefaultResult.error(message, e);
throw new DBGException(message, e);
}
return DefaultResult.ok();
}
protected void afterSessionOpen(DBCSession session) {
......@@ -84,19 +81,19 @@ public class DBGBaseController implements DBGController {
}
@Override
public void resume() {
public void resume() throws DBGException {
// TODO Auto-generated method stub
}
@Override
public void suspend() {
public void suspend() throws DBGException {
// TODO Auto-generated method stub
}
@Override
public void terminate() {
public void terminate() throws DBGException {
beforeSessionClose(this.debugSession);
if (this.debugSession != null) {
this.debugSession.close();
......
......@@ -21,26 +21,22 @@ import java.util.Map;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import org.jkiss.dbeaver.runtime.DBRResult;
//FIXME:AF: we need "operation result" interface like IStatus to express the result of operation
//FIXME:AF: so let's return void for now and let's throw an exception for any issue (poor practice)
/**
* This interface is expected to be used in synch manner
*/
public interface DBGController {
void init(DataSourceDescriptor dataSourceDescriptor, String databaseName, Map<String, Object> attributes);
public DBRResult connect(DBRProgressMonitor monitor);
void connect(DBRProgressMonitor monitor) throws DBGException;
void resume() throws DBGException;
void resume();
void suspend() throws DBGException;
void suspend();
void terminate() throws DBGException;
void terminate();
void dispose();
void dispose() throws DBGException;
}
......@@ -22,19 +22,17 @@ import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
import org.eclipse.osgi.util.NLS;
import org.jkiss.dbeaver.debug.DBGController;
import org.jkiss.dbeaver.debug.DBGException;
import org.jkiss.dbeaver.debug.core.model.DatabaseDebugTarget;
import org.jkiss.dbeaver.debug.core.model.DatabaseProcess;
import org.jkiss.dbeaver.model.runtime.DefaultProgressMonitor;
import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import org.jkiss.dbeaver.registry.DataSourceRegistry;
import org.jkiss.dbeaver.runtime.DBRResult;
import org.jkiss.dbeaver.runtime.core.RuntimeCore;
public abstract class DatabaseLaunchDelegate<C extends DBGController> extends LaunchConfigurationDelegate {
......@@ -54,10 +52,11 @@ public abstract class DatabaseLaunchDelegate<C extends DBGController> extends La
DatabaseDebugTarget<C> target = createDebugTarget(launch, controller, process);
launch.addDebugTarget(target);
DefaultProgressMonitor progress = new DefaultProgressMonitor(monitor);
DBRResult connectResult = controller.connect(progress);
IStatus status = RuntimeCore.toStatus(connectResult);
if (!status.isOK()) {
throw new CoreException(status);
try {
controller.connect(progress);
} catch (DBGException e) {
String message = NLS.bind("Unable to connect to {0}", datasourceDescriptor.getName());
throw new CoreException(DebugCore.newErrorStatus(message));
}
}
......
......@@ -63,6 +63,10 @@ public class DebugCore {
private static Log log = Log.getLog(DebugCore.class);
public static void log(IStatus status) {
Log.log(log, status);
}
public static CoreException abort(String message, Throwable th) {
return new CoreException(newErrorStatus(message, th));
}
......
......@@ -19,6 +19,7 @@ package org.jkiss.dbeaver.debug.core.model;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
......@@ -28,7 +29,10 @@ import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IThread;
import org.eclipse.osgi.util.NLS;
import org.jkiss.dbeaver.debug.DBGController;
import org.jkiss.dbeaver.debug.DBGException;
import org.jkiss.dbeaver.debug.core.DebugCore;
public abstract class DatabaseDebugTarget<C extends DBGController> extends DatabaseDebugElement implements IDatabaseDebugTarget {
......@@ -113,7 +117,11 @@ public abstract class DatabaseDebugTarget<C extends DBGController> extends Datab
for (int i = 0; i < events.length; i++) {
DebugEvent event = events[i];
if (event.getKind() == DebugEvent.TERMINATE && event.getSource().equals(process)) {
terminated();
try {
terminated();
} catch (DebugException e) {
DebugCore.log(e.getStatus());
}
}
}
}
......@@ -133,11 +141,17 @@ public abstract class DatabaseDebugTarget<C extends DBGController> extends Datab
terminated();
}
public synchronized void terminated() {
public synchronized void terminated() throws DebugException {
if (!terminated) {
terminated = true;
suspended = false;
controller.terminate();
try {
controller.terminate();
} catch (DBGException e) {
String message = NLS.bind("Error terminating {0}", getName());
IStatus status = DebugCore.newErrorStatus(message, e);
throw new DebugException(status);
}
}
}
......@@ -159,7 +173,13 @@ public abstract class DatabaseDebugTarget<C extends DBGController> extends Datab
@Override
public void resume() throws DebugException {
suspended = false;
controller.resume();
try {
controller.resume();
} catch (DBGException e) {
String message = NLS.bind("Error resuming {0}", getName());
IStatus status = DebugCore.newErrorStatus(message, e);
throw new DebugException(status);
}
if (thread.isSuspended()) {
thread.resumedByTarget();
}
......@@ -168,7 +188,13 @@ public abstract class DatabaseDebugTarget<C extends DBGController> extends Datab
@Override
public void suspend() throws DebugException {
controller.suspend();
try {
controller.suspend();
} catch (DBGException e) {
String message = NLS.bind("Error suspending {0}", getName());
IStatus status = DebugCore.newErrorStatus(message, e);
throw new DebugException(status);
}
}
public void suspended(int detail) {
......
package org.jkiss.dbeaver.runtime;
/**
*
* Represents an operation result
*
*/
public interface DBRResult {
int OK = 0;
int INFO = 1;
int WARNING = 2;
int ERROR = 3;
int CANCEL = 3;
int getSeverity();
String getMessage();
Throwable getException();
boolean isOK();
}
package org.jkiss.dbeaver.runtime;
public class DefaultResult implements DBRResult {
public static final DefaultResult OK_RESULT = ok();
private final static String EMPTY_MESSAGE = ""; //$NON-NLS-1$
private final int severity;
private final String message;
private final Throwable exception;
public static DefaultResult ok() {
return new DefaultResult(OK, EMPTY_MESSAGE, null);
}
public static DefaultResult info(String message) {
return new DefaultResult(INFO, message, null);
}
public static DefaultResult warning(String message) {
return new DefaultResult(WARNING, message, null);
}
public static DefaultResult error(String message) {
return new DefaultResult(ERROR, message, null);
}
public static DefaultResult error(String message, Throwable exception) {
return new DefaultResult(ERROR, message, exception);
}
public static DefaultResult cancel() {
return new DefaultResult(CANCEL, EMPTY_MESSAGE, null);
}
public DefaultResult(int severity, String message, Throwable exception) {
this.severity = severity;
this.message = message;
this.exception = exception;
}
@Override
public int getSeverity() {
return severity;
}
@Override
public String getMessage() {
return message;
}
@Override
public Throwable getException() {
return exception;
}
@Override
public boolean isOK() {
return severity == OK;
}
}
package org.jkiss.dbeaver.runtime.core;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.jkiss.dbeaver.runtime.DBRResult;
public class RuntimeCore {
public static final String BUNDLE_SYMBOLIC_NAME = "org.jkiss.dbeaver.runtime.core"; //$NON-NLS-1$
public static IStatus toStatus(DBRResult result)
{
if (result == null) {
return Status.CANCEL_STATUS;
}
int severity = toStatusSeverity(result.getSeverity());
String message = result.getMessage();
Throwable exception = result.getException();
String pluginId = toPluginId();
return new Status(severity, pluginId, message , exception );
}
private static String toPluginId()
{
return BUNDLE_SYMBOLIC_NAME;
}
public static int toStatusSeverity(int resultSeverity) {
return resultSeverity;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册