提交 ae6adfe4 编写于 作者: A Alexander Fedorov

#2556 move SQL outside of PostgreDebugBreakpointDescriptor

上级 caf9f108
......@@ -26,7 +26,7 @@ public interface DBGSession {
List<? extends DBGBreakpointDescriptor> getBreakpoints();
DBGBreakpointDescriptor setBreakpoint(DBGObjectDescriptor obj, DBGBreakpointProperties properties) throws DBGException;
void addBreakpoint(DBGObjectDescriptor object, DBGBreakpointProperties properties) throws DBGException;
void removeBreakpoint(DBGBreakpointDescriptor bp) throws DBGException;
......
......@@ -543,12 +543,12 @@ public class Debugger {
break;
}
DBGBreakpointProperties bpp = lineNo > 0 ? new PostgreDebugBreakpointProperties(lineNo, true)
DBGBreakpointProperties bp = lineNo > 0 ? new PostgreDebugBreakpointProperties(lineNo, true)
: new PostgreDebugBreakpointProperties(true);
DBGBreakpointDescriptor bp = debugSession.setBreakpoint(debugObject, bpp);
debugSession.addBreakpoint(debugObject, bp);
System.out.println("Breakpoint set");
System.out.println("Breakpoint added");
System.out.println(bp.toString());
......
......@@ -18,9 +18,6 @@
package org.jkiss.dbeaver.ext.postgresql.debug.internal.impl;
import java.sql.SQLException;
import java.sql.Statement;
import org.jkiss.dbeaver.debug.DBGBreakpointDescriptor;
import org.jkiss.dbeaver.debug.DBGException;
......@@ -33,28 +30,11 @@ public class PostgreDebugBreakpointDescriptor implements DBGBreakpointDescriptor
private final PostgreDebugBreakpointProperties properties;
private static final String SQL_SET_GLOBAL = "select pldbg_set_global_breakpoint(?sessionid, ?obj, ?line, ?target)";
private static final String SQL_SET = "select pldbg_set_breakpoint(?sessionid, ?obj, ?line)";
public PostgreDebugBreakpointDescriptor(PostgreDebugSession session, PostgreDebugObjectDescriptor obj,
PostgreDebugBreakpointProperties properties) throws DBGException {
this.session = session;
this.obj = obj;
this.properties = properties;
try (Statement stmt = session.getConnection().createStatement()) {
String sqlCommand = properties.isGlobal() ? SQL_SET_GLOBAL : SQL_SET;
stmt.executeQuery(sqlCommand.replaceAll("\\?sessionid", String.valueOf(session.getSessionId()))
.replaceAll("\\?obj", String.valueOf(obj.getID()))
.replaceAll("\\?line", properties.isOnStart() ? "-1" : String.valueOf(properties.getLineNo()))
.replaceAll("\\?target", properties.isAll() ? "null"
: String.valueOf(properties.getTargetId())));
} catch (SQLException e) {
throw new DBGException("SQL error", e);
}
}
......
......@@ -70,7 +70,6 @@ public class PostgreDebugSession implements DBGSession {
private static final String SQL_ATTACH = "select pldbg_wait_for_target(?sessionid)";
private static final String SQL_ATTACH_BREAKPOINT = "select pldbg_wait_for_breakpoint(?sessionid)";
private static final String SQL_LISTEN = "select pldbg_create_listener() as sessionid";
......@@ -88,14 +87,15 @@ public class PostgreDebugSession implements DBGSession {
private static final String SQL_ABORT = "select pldbg_abort_target(?sessionid)";
private static final String SQL_SET_GLOBAL_BREAKPOINT = "select pldbg_set_global_breakpoint(?sessionid, ?obj, ?line, ?target)";
private static final String SQL_SET_BREAKPOINT = "select pldbg_set_breakpoint(?sessionid, ?obj, ?line)";
private static final String SQL_DROP_BREAKPOINT = "select pldbg_drop_breakpoint(?sessionid, ?obj, ?line)";
private static final String SQL_ATTACH_BREAKPOINT = "select pldbg_wait_for_breakpoint(?sessionid)";
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
private List<PostgreDebugBreakpointDescriptor> breakpoints = new ArrayList<PostgreDebugBreakpointDescriptor>(1);
private PostgreDebugBreakpointDescriptor entry = null;
private FutureTask<Void> task;
private Thread workerThread = null;
......@@ -146,8 +146,7 @@ public class PostgreDebugSession implements DBGSession {
PostgreDebugBreakpointProperties properties = new PostgreDebugBreakpointProperties(true);
PostgreDebugObjectDescriptor obj = new PostgreDebugObjectDescriptor(OID,"ENTRY","SESSION","THIS","PG");
this.entry = new PostgreDebugBreakpointDescriptor(this,obj,properties);
addBreakpoint(obj, properties);
runAsync(SQL_ATTACH.replaceAll("\\?sessionid", String.valueOf(sessionId)),
String.valueOf(sessionId) + " global attached to " + String.valueOf(targetId));
......@@ -189,21 +188,34 @@ public class PostgreDebugSession implements DBGSession {
}
@Override
public DBGBreakpointDescriptor setBreakpoint(DBGObjectDescriptor obj, DBGBreakpointProperties properties) throws DBGException {
public void addBreakpoint(DBGObjectDescriptor object, DBGBreakpointProperties properties) throws DBGException {
acquireReadLock();
PostgreDebugBreakpointDescriptor bp = null;
try {
bp = new PostgreDebugBreakpointDescriptor(this, (PostgreDebugObjectDescriptor)obj, (PostgreDebugBreakpointProperties) properties);
PostgreDebugBreakpointProperties bpd = (PostgreDebugBreakpointProperties) properties;
bp = new PostgreDebugBreakpointDescriptor(this, (PostgreDebugObjectDescriptor)object, bpd);
try (Statement stmt = getConnection().createStatement()) {
String sqlCommand = bpd.isGlobal() ? SQL_SET_GLOBAL_BREAKPOINT : SQL_SET_BREAKPOINT;
stmt.executeQuery(sqlCommand.replaceAll("\\?sessionid", String.valueOf(getSessionId()))
.replaceAll("\\?obj", String.valueOf(object.getID()))
.replaceAll("\\?line", bpd.isOnStart() ? "-1" : String.valueOf(bpd.getLineNo()))
.replaceAll("\\?target", bpd.isAll() ? "null"
: String.valueOf(bpd.getTargetId())));
} catch (SQLException e) {
throw new DBGException("SQL error", e);
}
breakpoints.add(bp);
} finally {
lock.readLock().unlock();
}
return bp;
}
@Override
......@@ -415,7 +427,7 @@ public class PostgreDebugSession implements DBGSession {
* @return java.sql.Connection
* @throws DBGException
*/
public Connection getConnection() throws DBGException {
private Connection getConnection() throws DBGException {
try {
return getConnection(connection);
} catch (SQLException e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册