[#1177] Add SQL Console module to jOOQ - Minor bug fixes.
This commit is contained in:
parent
2f546950ce
commit
f4497dca18
@ -250,10 +250,13 @@ public class EditorPane extends JPanel {
|
||||
@Override
|
||||
public void run() {
|
||||
final int maxDisplayedRowCount = ((Number)displayedRowCountField.getValue()).intValue();
|
||||
// TODO: For now, if there is no max limit, consider we don't want the rows to be updatable.
|
||||
// TODO: eventually, we want a distinct choice on the user interface.
|
||||
final boolean isUpdatable = isUsingMaxRowCount;
|
||||
Thread evaluationThread = new Thread("SQLConsole - Evaluation") {
|
||||
@Override
|
||||
public void run() {
|
||||
evaluate_unrestricted_nothread(sql, maxDisplayedRowCount);
|
||||
evaluate_unrestricted_nothread(sql, maxDisplayedRowCount, isUpdatable);
|
||||
}
|
||||
};
|
||||
evaluationThread.start();
|
||||
@ -261,7 +264,7 @@ public class EditorPane extends JPanel {
|
||||
});
|
||||
}
|
||||
|
||||
private void evaluate_unrestricted_nothread(final String sql, final int maxDisplayedRowCount) {
|
||||
private void evaluate_unrestricted_nothread(final String sql, final int maxDisplayedRowCount, boolean isUpdatable) {
|
||||
closeLastExecution();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
@ -278,7 +281,7 @@ public class EditorPane extends JPanel {
|
||||
}
|
||||
QueryExecution queryExecution;
|
||||
try {
|
||||
queryExecution = queryExecutor.execute(sql, isUsingMaxRowCount? MAX_ROW_COUNT: Integer.MAX_VALUE, maxDisplayedRowCount);
|
||||
queryExecution = queryExecutor.execute(sql, isUsingMaxRowCount? MAX_ROW_COUNT: Integer.MAX_VALUE, maxDisplayedRowCount, isUpdatable);
|
||||
} finally {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
@ -660,7 +663,9 @@ public class EditorPane extends JPanel {
|
||||
case KeyEvent.VK_DOWN:
|
||||
case KeyEvent.VK_HOME:
|
||||
case KeyEvent.VK_END:
|
||||
return;
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
w.setVisible(false);
|
||||
return;
|
||||
case KeyEvent.VK_ENTER:
|
||||
editorTextArea.replaceRange(((CompletionCandidate)jList.getSelectedValue()).toString(), getWordStart(), editorTextArea.getCaretPosition());
|
||||
|
||||
@ -43,7 +43,7 @@ package org.jooq.tools.debug.old;
|
||||
*/
|
||||
public interface QueryExecutor {
|
||||
|
||||
public QueryExecution execute(String sql, int maxRSRowsParsing, int retainParsedRSDataRowCountThreshold);
|
||||
public QueryExecution execute(String sql, int maxRSRowsParsing, int retainParsedRSDataRowCountThreshold, boolean isUpdatable);
|
||||
|
||||
public void stopExecution();
|
||||
|
||||
|
||||
@ -66,8 +66,8 @@ class ClientStatementExecutor implements QueryExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryExecution execute(String sql, int maxRSRowsParsing, int retainParsedRSDataRowCountThreshold) {
|
||||
return debugger.getCommunicationInterface().syncSend(new CMS_doStatementExecutorExecution(id, sql, maxRSRowsParsing, retainParsedRSDataRowCountThreshold));
|
||||
public QueryExecution execute(String sql, int maxRSRowsParsing, int retainParsedRSDataRowCountThreshold, boolean isUpdatable) {
|
||||
return debugger.getCommunicationInterface().syncSend(new CMS_doStatementExecutorExecution(id, sql, maxRSRowsParsing, retainParsedRSDataRowCountThreshold, isUpdatable));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -83,9 +83,11 @@ class LocalStatementExecutor implements QueryExecutor {
|
||||
private volatile Thread evaluationThread;
|
||||
|
||||
@Override
|
||||
public QueryExecution execute(String sql, int maxRSRowsParsing, int retainParsedRSDataRowCountThreshold) {
|
||||
public QueryExecution execute(String sql, int maxRSRowsParsing, int retainParsedRSDataRowCountThreshold, boolean isUpdatable) {
|
||||
boolean isReadOnly = executorContext.isReadOnly();
|
||||
isUpdatable = !isReadOnly && isUpdatable;
|
||||
boolean isAllowed = true;
|
||||
if(executorContext.isReadOnly()) {
|
||||
if(isReadOnly) {
|
||||
String simplifiedSql = sql.replaceAll("'[^']*'", "");
|
||||
switch(QueryType.detectType(simplifiedSql)) {
|
||||
case SELECT:
|
||||
@ -123,7 +125,11 @@ class LocalStatementExecutor implements QueryExecutor {
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
conn = executorContext.getConnection();
|
||||
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
if(isUpdatable) {
|
||||
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
} else {
|
||||
stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
}
|
||||
// If no error, adjust start to beginning of actual execution.
|
||||
start = System.currentTimeMillis();
|
||||
if(evaluationThread != Thread.currentThread()) {
|
||||
@ -278,7 +284,7 @@ class LocalStatementExecutor implements QueryExecutor {
|
||||
}
|
||||
}
|
||||
final long resultSetParsingDuration = System.currentTimeMillis() - rsStart;
|
||||
queryExecutionResult = new LocalStatementExecutionResultSetResult(rs, columnNames, typeInfos, columnClasses, rowDataList.toArray(new Object[0][]), rowCount, resultSetParsingDuration, retainParsedRSDataRowCountThreshold, executorContext.isReadOnly());
|
||||
queryExecutionResult = new LocalStatementExecutionResultSetResult(rs, columnNames, typeInfos, columnClasses, rowDataList.toArray(new Object[0][]), rowCount, resultSetParsingDuration, retainParsedRSDataRowCountThreshold, isReadOnly);
|
||||
} else {
|
||||
final int updateCount = stmt.getUpdateCount();
|
||||
queryExecutionResult = new QueryExecutionMessageResult(Utils.formatDuration(executionDuration) + "> " + updateCount + " row(s) affected.", false);
|
||||
@ -299,7 +305,7 @@ class LocalStatementExecutor implements QueryExecutor {
|
||||
long executionDuration = System.currentTimeMillis() - start;
|
||||
return new QueryExecution(executionDuration, new QueryExecutionMessageResult(e));
|
||||
} finally {
|
||||
if(executorContext.isReadOnly()) {
|
||||
if(isReadOnly) {
|
||||
closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,22 +231,24 @@ class ServerDebugger extends LocalDebugger {
|
||||
}
|
||||
|
||||
static class CMS_doStatementExecutorExecution extends CommandMessage<QueryExecution> {
|
||||
private final int id;
|
||||
private final String sql;
|
||||
private final int maxRSRowsParsing;
|
||||
private final int retainParsedRSDataRowCountThreshold;
|
||||
private final int id;
|
||||
private final String sql;
|
||||
private final int maxRSRowsParsing;
|
||||
private final int retainParsedRSDataRowCountThreshold;
|
||||
private final boolean isUpdatable;
|
||||
|
||||
CMS_doStatementExecutorExecution(int id, String sql, int maxRSRowsParsing,
|
||||
int retainParsedRSDataRowCountThreshold) {
|
||||
int retainParsedRSDataRowCountThreshold, boolean isUpdatable) {
|
||||
this.id = id;
|
||||
this.sql = sql;
|
||||
this.maxRSRowsParsing = maxRSRowsParsing;
|
||||
this.retainParsedRSDataRowCountThreshold = retainParsedRSDataRowCountThreshold;
|
||||
this.isUpdatable = isUpdatable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryExecution run(MessageContext context) {
|
||||
QueryExecution queryExecution = getServerDebugger(context).getStatementExecutor(id).execute(sql, maxRSRowsParsing, retainParsedRSDataRowCountThreshold);
|
||||
QueryExecution queryExecution = getServerDebugger(context).getStatementExecutor(id).execute(sql, maxRSRowsParsing, retainParsedRSDataRowCountThreshold, isUpdatable);
|
||||
return new ClientStatementExecution(queryExecution);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user