[#1177] Add SQL Console module to jOOQ - multi execution context
prepared in the code.
This commit is contained in:
parent
f4497dca18
commit
8fdcddf78e
@ -183,7 +183,7 @@ public class BreakpointHitEditor extends JPanel {
|
||||
tabbedPane.addTab("Execution", breakpointHitExecutionPane);
|
||||
tabbedPane.addTab("Editor", new EditorsPane(new QueryExecutorCreator() {
|
||||
@Override
|
||||
public QueryExecutor createQueryExecutor() {
|
||||
public QueryExecutor createQueryExecutor(String executionContextName) {
|
||||
return debugger.createBreakpointHitStatementExecutor(hit.getThreadID());
|
||||
}
|
||||
}, false));
|
||||
|
||||
@ -245,7 +245,10 @@ public class Console extends JFrame {
|
||||
// }
|
||||
// }
|
||||
setTitle(title);
|
||||
if(debugger.isExecutionSupported()) {
|
||||
// TODO: use context names to have on screen selector.
|
||||
String[] executionContextNames = debugger.getExecutionContextNames();
|
||||
boolean isExecutionSupported = executionContextNames.length > 0;
|
||||
if(isExecutionSupported) {
|
||||
addEditorTab();
|
||||
}
|
||||
if(isShowingLoggingTab) {
|
||||
@ -258,7 +261,7 @@ public class Console extends JFrame {
|
||||
setLocationByPlatform(true);
|
||||
setSize(800, 600);
|
||||
addNotify();
|
||||
if(debugger.isExecutionSupported()) {
|
||||
if(isExecutionSupported) {
|
||||
editorsPane.adjustDefaultFocus();
|
||||
}
|
||||
addWindowListener(new WindowAdapter() {
|
||||
|
||||
@ -123,6 +123,8 @@ public class EditorPane extends JPanel {
|
||||
private static final int MAX_ROW_COUNT = 10000;
|
||||
private boolean isUsingMaxRowCount = true;
|
||||
private JFormattedTextField displayedRowCountField;
|
||||
// TODO: once multi contexts is implemented, make this configurable.
|
||||
private String executionContextName = "default";
|
||||
|
||||
private SqlTextArea editorTextArea;
|
||||
private JPanel southPanel;
|
||||
@ -276,7 +278,7 @@ public class EditorPane extends JPanel {
|
||||
});
|
||||
QueryExecutor queryExecutor;
|
||||
synchronized (STATEMENT_EXECUTOR_CREATOR_LOCK) {
|
||||
queryExecutor = queryExecutorCreator.createQueryExecutor();
|
||||
queryExecutor = queryExecutorCreator.createQueryExecutor(executionContextName);
|
||||
lastStatementExecutor = queryExecutor;
|
||||
}
|
||||
QueryExecution queryExecution;
|
||||
@ -851,7 +853,7 @@ public class EditorPane extends JPanel {
|
||||
List<CompletionCandidate> candidateList = new ArrayList<CompletionCandidate>();
|
||||
// Here can add more candidates depending on magic word start.
|
||||
if(candidateList.isEmpty()) {
|
||||
QueryExecutor queryExecutor = queryExecutorCreator.createQueryExecutor();
|
||||
QueryExecutor queryExecutor = queryExecutorCreator.createQueryExecutor(executionContextName);
|
||||
for(String s: queryExecutor.getTableNames()) {
|
||||
candidateList.add(new CompletionCandidate(KeyWordType.TABLE, s));
|
||||
}
|
||||
|
||||
@ -107,7 +107,8 @@ public class EditorsPane extends JPanel {
|
||||
}
|
||||
|
||||
private JPanel createTablePane() {
|
||||
final String[] tableNames = queryExecutorCreator.createQueryExecutor().getTableNames();
|
||||
// TODO: have one table pane per execution context name (lazily created).
|
||||
final String[] tableNames = queryExecutorCreator.createQueryExecutor("default").getTableNames();
|
||||
final JList tableNamesJList = new JList(tableNames);
|
||||
tableNamesJList.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
|
||||
@ -84,7 +84,7 @@ public interface Debugger extends QueryExecutorCreator {
|
||||
|
||||
BreakpointHitHandler getBreakpointHitHandler();
|
||||
|
||||
boolean isExecutionSupported();
|
||||
String[] getExecutionContextNames();
|
||||
|
||||
void processBreakpointBeforeExecutionHit(ExecuteContext ctx, BreakpointHit hit);
|
||||
|
||||
|
||||
@ -42,6 +42,6 @@ package org.jooq.tools.debug.old;
|
||||
*/
|
||||
public interface QueryExecutorCreator {
|
||||
|
||||
public QueryExecutor createQueryExecutor();
|
||||
public QueryExecutor createQueryExecutor(String executionContextName);
|
||||
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ import org.jooq.tools.debug.old.QueryLog;
|
||||
import org.jooq.tools.debug.old.ResultLog;
|
||||
import org.jooq.tools.debug.old.impl.Message.NoResult;
|
||||
import org.jooq.tools.debug.old.impl.ServerDebugger.CMS_addBreakpoint;
|
||||
import org.jooq.tools.debug.old.impl.ServerDebugger.CMS_isExecutionSupported;
|
||||
import org.jooq.tools.debug.old.impl.ServerDebugger.CMS_getExecutionContextNames;
|
||||
import org.jooq.tools.debug.old.impl.ServerDebugger.CMS_removeBreakpoint;
|
||||
import org.jooq.tools.debug.old.impl.ServerDebugger.CMS_setBreakpointHitHandlerActive;
|
||||
import org.jooq.tools.debug.old.impl.ServerDebugger.CMS_setLoggingActive;
|
||||
@ -180,22 +180,25 @@ class ClientDebugger implements Debugger {
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean isExecutionSupported;
|
||||
private final Object IS_EXECUTION_SUPPORTED_LOCK = new Object();
|
||||
private String[] executionContextNames;
|
||||
private final Object EXECUTION_CONTEXT_NAMES_LOCK = new Object();
|
||||
|
||||
@Override
|
||||
public boolean isExecutionSupported() {
|
||||
synchronized (IS_EXECUTION_SUPPORTED_LOCK) {
|
||||
if(isExecutionSupported == null) {
|
||||
isExecutionSupported = comm.syncSend(new CMS_isExecutionSupported());
|
||||
public String[] getExecutionContextNames() {
|
||||
synchronized (EXECUTION_CONTEXT_NAMES_LOCK) {
|
||||
if(executionContextNames == null) {
|
||||
executionContextNames = comm.syncSend(new CMS_getExecutionContextNames());
|
||||
if(executionContextNames == null) {
|
||||
executionContextNames = new String[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return Boolean.TRUE.equals(isExecutionSupported);
|
||||
return executionContextNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryExecutor createQueryExecutor() {
|
||||
return new ClientStatementExecutor(this, null);
|
||||
public QueryExecutor createQueryExecutor(String executionContextName) {
|
||||
return new ClientStatementExecutor(this, executionContextName, null);
|
||||
}
|
||||
|
||||
|
||||
@ -326,7 +329,7 @@ class ClientDebugger implements Debugger {
|
||||
|
||||
@Override
|
||||
public QueryExecutor createBreakpointHitStatementExecutor(long threadID) {
|
||||
ClientStatementExecutor statementExecutor = new ClientStatementExecutor(this, threadID);
|
||||
ClientStatementExecutor statementExecutor = new ClientStatementExecutor(this, null, threadID);
|
||||
synchronized (threadIDToStatementExecutorList) {
|
||||
List<QueryExecutor> list = threadIDToStatementExecutorList.get(threadID);
|
||||
if(list == null) {
|
||||
|
||||
@ -57,12 +57,13 @@ class ClientStatementExecutor implements QueryExecutor {
|
||||
private int id;
|
||||
|
||||
/**
|
||||
* @param executionContextName ignored if in a breakpoint hit.
|
||||
* @param breakpointHitThreadID null if not in a breakpoint hit.
|
||||
*/
|
||||
public ClientStatementExecutor(ClientDebugger debugger, Long breakpointHitThreadID) {
|
||||
public ClientStatementExecutor(ClientDebugger debugger, String executionContextName, Long breakpointHitThreadID) {
|
||||
id = nextID.incrementAndGet();
|
||||
this.debugger = debugger;
|
||||
debugger.getCommunicationInterface().asyncSend((CommandMessage<?>) new CMS_createServerStatementExecutor(id, breakpointHitThreadID));
|
||||
debugger.getCommunicationInterface().asyncSend((CommandMessage<?>) new CMS_createServerStatementExecutor(id, executionContextName, breakpointHitThreadID));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -167,12 +167,14 @@ class LocalDebugger implements Debugger {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExecutionSupported() {
|
||||
return databaseDescriptor != null;
|
||||
public String[] getExecutionContextNames() {
|
||||
// TODO: implement execution context mapping.
|
||||
return databaseDescriptor != null? new String[] {"default"}: new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalStatementExecutor createQueryExecutor() {
|
||||
public LocalStatementExecutor createQueryExecutor(String executionContextName) {
|
||||
// TODO: implement execution context mapping: use context name.
|
||||
return new LocalStatementExecutor(new QueryExecutorContext() {
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
|
||||
@ -80,7 +80,7 @@ public class Server {
|
||||
}
|
||||
}
|
||||
|
||||
public static ServerSocket openServerCommunicationChannel(final int port, final DatabaseDescriptor descriptor) throws Exception {
|
||||
private static ServerSocket openServerCommunicationChannel(final int port, final DatabaseDescriptor descriptor) throws Exception {
|
||||
final ServerSocket serverSocket;
|
||||
try {
|
||||
serverSocket = new ServerSocket();
|
||||
|
||||
@ -181,19 +181,19 @@ class ServerDebugger extends LocalDebugger {
|
||||
}
|
||||
}
|
||||
|
||||
static class CMS_isExecutionSupported extends CommandMessage<Boolean> {
|
||||
static class CMS_getExecutionContextNames extends CommandMessage<String[]> {
|
||||
@Override
|
||||
public Boolean run(MessageContext context) {
|
||||
return context.getDebugger().isExecutionSupported();
|
||||
public String[] run(MessageContext context) {
|
||||
return context.getDebugger().getExecutionContextNames();
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Integer, QueryExecutor> idToStatementExecutorMap = new HashMap<Integer, QueryExecutor>();
|
||||
|
||||
private void createStatementExecutor(int id, Long breakpointHitThreadID) {
|
||||
private void createStatementExecutor(int id, String executionContextName, Long breakpointHitThreadID) {
|
||||
LocalStatementExecutor statementExecutor;
|
||||
if(breakpointHitThreadID == null) {
|
||||
statementExecutor = createQueryExecutor();
|
||||
statementExecutor = createQueryExecutor(executionContextName);
|
||||
} else {
|
||||
statementExecutor = createBreakpointHitStatementExecutor(breakpointHitThreadID);
|
||||
}
|
||||
@ -216,16 +216,18 @@ class ServerDebugger extends LocalDebugger {
|
||||
|
||||
static class CMS_createServerStatementExecutor extends CommandMessage<NoResult> {
|
||||
private final int id;
|
||||
private final String executionContextName;
|
||||
private final Long breakpointHitThreadID;
|
||||
|
||||
CMS_createServerStatementExecutor(int id, Long breakpointHitThreadID) {
|
||||
CMS_createServerStatementExecutor(int id, String executionContextName, Long breakpointHitThreadID) {
|
||||
this.id = id;
|
||||
this.executionContextName = executionContextName;
|
||||
this.breakpointHitThreadID = breakpointHitThreadID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoResult run(MessageContext context) {
|
||||
getServerDebugger(context).createStatementExecutor(id, breakpointHitThreadID);
|
||||
getServerDebugger(context).createStatementExecutor(id, executionContextName, breakpointHitThreadID);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user