This commit is contained in:
Lukas Eder 2012-10-07 12:37:59 +02:00
commit af336751f4
6 changed files with 63 additions and 20 deletions

View File

@ -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());

View File

@ -96,6 +96,7 @@ import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;
import org.jooq.debug.console.misc.InvisibleSplitPane;
import org.jooq.debug.console.misc.JTableX;
@ -913,9 +914,38 @@ public class LoggerPane extends JPanel {
} else {
text = displayedCount + "/" + size + " queries";
}
int count = table.getSelectedRowCount();
if(count > 0) {
text = text + " - " + count + " selected rows";
int selectedRowCount = table.getSelectedRowCount();
if(selectedRowCount > 0) {
text = text + " - " + selectedRowCount + " selected rows";
if(selectedRowCount > 1) {
int[] selectedColumns = table.getSelectedColumns();
if(selectedColumns.length == 1) {
int column = table.convertColumnIndexToModel(selectedColumns[0]);
switch(column) {
case COLUMN_EXEC_TIME:
case COLUMN_RS_LIFETIME:
case COLUMN_RS_READ:
case COLUMN_RS_READ_ROWS:
int[] selectedRows = table.getSelectedRows();
TableModel model = table.getModel();
long sum = 0;
boolean isValid = true;
for(int row: selectedRows) {
row = table.convertRowIndexToModel(row);
Number number = (Number)model.getValueAt(row, column);
if(number == null) {
isValid = false;
break;
}
sum += number.longValue();
}
if(isValid) {
text += " - sum: " + sum;
}
break;
}
}
}
}
loggerStatusLabel.setText(text);
}

View File

@ -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();

View File

@ -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

View File

@ -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();
}
}

View File

@ -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);
}
}