提交 28ba60c7 编写于 作者: A Alexander Fedorov

#2556 normalize debug events

上级 200209e2
......@@ -39,7 +39,7 @@ public abstract class DBGBaseSession implements DBGSession {
private final DBGBaseController controller;
private FutureTask<DBGEvent> task;
private FutureTask<Void> task;
private Thread workerThread = null;
......@@ -71,7 +71,7 @@ public abstract class DBGBaseSession implements DBGSession {
this.connection = connection;
}
public DBGBaseController getController() {
protected DBGBaseController getController() {
return controller;
}
......@@ -105,8 +105,7 @@ public abstract class DBGBaseSession implements DBGSession {
}
if (task.isDone()) {
try {
DBGEvent dbgEvent = task.get();
getController().fireEvent(dbgEvent);
task.get();
} catch (InterruptedException e) {
log.error("DEBUG INTERRUPT ERROR ", e);
return false;
......@@ -126,18 +125,18 @@ public abstract class DBGBaseSession implements DBGSession {
* @param name
* @throws DBGException
*/
protected void runAsync(String commandSQL, String name, DBGEvent event) throws DBGException {
protected void runAsync(String commandSQL, String name, DBGEvent begin, DBGEvent end) throws DBGException {
Connection connection = getConnection();
try (Statement stmt = connection.createStatement()) {
connection.setAutoCommit(false);
DBGWorker worker = new DBGWorker(connection, commandSQL, event);
task = new FutureTask<DBGEvent>(worker);
workerThread = new Thread(task);
workerThread.setName(name);
workerThread.start();
} catch (SQLException e) {
throw new DBGException("SQL error", e);
}
DBGWorker worker = new DBGWorker(this, commandSQL, begin, end);
task = new FutureTask<Void>(worker);
workerThread = new Thread(task);
workerThread.setName(name);
workerThread.start();
}
public void close() {
......
......@@ -24,16 +24,25 @@ public class DBGEvent extends EventObject {
private static final long serialVersionUID = 1L;
public static final int ATTACH = 0x0001;
public static final int SUSPEND = 0x0002;
public static final int RESUME = 0x0004;
public static final int DETACH = 0x0008;
/*
* The event kind constants
*/
public static final int RESUME= 0x0001;
public static final int SUSPEND= 0x0002;
public static final int CREATE= 0x0004;
public static final int TERMINATE= 0x0008;
public static final int CHANGE= 0x0010;
public static final int MODEL_SPECIFIC= 0x0020;
/*
* The event detail constants
*/
public static final int UNSPECIFIED = 0;
public static final int STEP_INTO = 0x0001;
public static final int STEP_OVER = 0x0002;
public static final int STEP_RETURN = 0x0004;
public static final int STEP_END = 0x0008;
public static final int BREAKPOINT= 0x0010;
private int kind;
......
......@@ -19,31 +19,34 @@
package org.jkiss.dbeaver.debug;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.concurrent.Callable;
public class DBGWorker implements Callable<DBGEvent> {
public class DBGWorker implements Callable<Void> {
private final Connection conn;
private final DBGBaseSession session;
private final String sql;
private final DBGEvent event;
private final DBGEvent before;
private final DBGEvent after;
public DBGWorker(Connection conn, String sqlCommand, DBGEvent event)
public DBGWorker(DBGBaseSession session, String sqlCommand, DBGEvent begin, DBGEvent end)
{
this.conn = conn;
this.session = session;
this.sql = sqlCommand;
this.event = event;
this.before = begin;
this.after = end;
}
@Override
public DBGEvent call() throws Exception
public Void call() throws Exception
{
try (Statement stmt = conn.createStatement()) {
try (Statement stmt = session.getConnection().createStatement()) {
session.getController().fireEvent(before);
stmt.executeQuery(sql);
return event;
session.getController().fireEvent(after);
return null;
} catch (SQLException e) {
String message = String.format("Failed to execute %s", sql);
throw new Exception(message, e);
......
......@@ -133,7 +133,10 @@ public class PostgreDebugSession extends DBGBaseSession {
String sessionParam = String.valueOf(getSessionId());
String taskName = sessionParam + " global attached to " + String.valueOf(targetId);
runAsync(SQL_ATTACH.replaceAll("\\?sessionid", sessionParam), taskName, new DBGEvent(this, DBGEvent.ATTACH));
String sql = SQL_ATTACH.replaceAll("\\?sessionid", sessionParam);
DBGEvent begin = new DBGEvent(this, DBGEvent.RESUME, DBGEvent.MODEL_SPECIFIC);
DBGEvent end = new DBGEvent(this, DBGEvent.SUSPEND, DBGEvent.BREAKPOINT);
runAsync(sql, taskName, begin, end);
/*if (breakpoint) {
runAsync(SQL_ATTACH_BREAKPOINT.replaceAll("\\?sessionid", String.valueOf(sessionId)),
......@@ -198,20 +201,20 @@ public class PostgreDebugSession extends DBGBaseSession {
* Execute step SQL command asynchronously, set debug session name to
* [sessionID] name [managerPID]
*
* @param commandSQL - SQL command for execute step
* @param name - session 'name' part
* @param commandPattern - SQL command for execute step
* @param nameParameter - session 'name' part
* @throws DBGException
*/
public void execStep(String commandSQL, String name, int eventDetail) throws DBGException {
public void execStep(String commandPattern, String nameParameter, int eventDetail) throws DBGException {
acquireWriteLock();
try {
DBGEvent event = new DBGEvent(this, DBGEvent.RESUME, eventDetail);
runAsync(commandSQL.replaceAll("\\?sessionid", String.valueOf(sessionId)),
String.valueOf(sessionId) + name + String.valueOf(targetId), event);
String sql = commandPattern.replaceAll("\\?sessionid", String.valueOf(sessionId));
String taskName = String.valueOf(sessionId) + nameParameter + String.valueOf(targetId);
DBGEvent begin = new DBGEvent(this, DBGEvent.RESUME, eventDetail);
DBGEvent end = new DBGEvent(this, DBGEvent.SUSPEND, eventDetail);
runAsync(sql, taskName, begin, end);
} finally {
lock.writeLock().unlock();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册