private void evaluate_unrestricted_nothread( final String sql, final int maxDisplayedRowCount, boolean isUpdatable) { closeLastExecution(); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { startButton.setVisible(false); stopButton.setVisible(true); stopButton.setToolTipText("Query started on " + Utils.formatDateTimeTZ(new Date())); } }); QueryExecutor queryExecutor; synchronized (STATEMENT_EXECUTOR_CREATOR_LOCK) { queryExecutor = queryExecutorCreator.createQueryExecutor(executionContextName); lastStatementExecutor = queryExecutor; } QueryExecution queryExecution; try { queryExecution = queryExecutor.execute( sql, isUsingMaxRowCount ? MAX_ROW_COUNT : Integer.MAX_VALUE, maxDisplayedRowCount, isUpdatable); } finally { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { startButton.setVisible(true); stopButton.setVisible(false); stopButton.setToolTipText(null); } }); } final QueryExecutionResult[] results = queryExecution.getResults(); final long executionDuration = queryExecution.getExecutionDuration(); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { for (QueryExecutionResult result : results) { if (result instanceof QueryExecutionMessageResult) { QueryExecutionMessageResult messageResult = (QueryExecutionMessageResult) result; setMessage(addResultPane(), messageResult.getMessage(), messageResult.isError()); } else if (result instanceof StatementExecutionResultSetResult) { addResultTable(sql, executionDuration, (StatementExecutionResultSetResult) result); } else { throw new IllegalStateException( "Unknown result class: " + result.getClass().getName()); } } } }); }
void closeLastExecution() { synchronized (STATEMENT_EXECUTOR_CREATOR_LOCK) { if (lastStatementExecutor != null) { lastStatementExecutor.stopExecution(); lastStatementExecutor = null; } } }
private CompletionCandidate[] getFilteredWords(int wordStart, String word) { List<CompletionCandidate> candidateList = new ArrayList<CompletionCandidate>(); // Here can add more candidates depending on magic word start. if (candidateList.isEmpty()) { QueryExecutor queryExecutor = queryExecutorCreator.createQueryExecutor(executionContextName); for (String s : queryExecutor.getTableNames()) { candidateList.add(new CompletionCandidate(KeyWordType.TABLE, s)); } for (String s : queryExecutor.getTableColumnNames()) { candidateList.add(new CompletionCandidate(KeyWordType.TABLE_COlUMN, s)); } queryExecutor.stopExecution(); for (String s : new String[] { "ALTER", "ASC", "BY", "DESC", "DROP", "FROM", "IN", "INNER", "INSERT", "INTO", "JOIN", "LEFT", "NOT", "ORDER", "SELECT", "UPDATE", "WHERE", "AND", "OR", "EXISTS", "HAVING", "TOP", "GROUP", "SET", }) { candidateList.add(new CompletionCandidate(KeyWordType.KEYWORD, s)); } } word = word.toUpperCase(Locale.ENGLISH); List<CompletionCandidate> filteredCompletionCandidateList = new ArrayList<CompletionCandidate>(); for (CompletionCandidate completionCandidate : candidateList) { if (completionCandidate .toString() .toLowerCase(Locale.ENGLISH) .startsWith(word.toLowerCase(Locale.ENGLISH))) { filteredCompletionCandidateList.add(completionCandidate); } } Collections.sort( filteredCompletionCandidateList, new Comparator<CompletionCandidate>() { @Override public int compare(CompletionCandidate o1, CompletionCandidate o2) { return String.CASE_INSENSITIVE_ORDER.compare(o1.toString(), o2.toString()); } }); return filteredCompletionCandidateList.toArray(new CompletionCandidate[0]); }