📄 queryanalyser.java
字号:
if (!executing) { return; }/* if (!isSelect) { if (worker != null) { worker.interrupt(); } } else { */ if (qs != null) { //Log.debug("interrupting qs"); qs.cancelCurrentStatement(); }/* if (worker != null) { worker.interrupt(); } */ // } executing = false; statementCancelled = true; } /** * Returns whether a a query is currently being executed. * * @param true if in an execution is in progress, false otherwise */ public boolean isExecuting() { return executing; } /** * Executes the query(ies) as specified. This method performs the * actual execution following query 'massaging'.The executeAsBlock * flag indicates that the query should be executed in its entirety - * not split up into mulitple queries (where applicable). * * @param the query string * @param true to execute in entirety, false otherwise */ private Object executeSQL(String q, boolean executeAsBlock) { // init the start and end times long start = 0; long end = 0; try { // check we are executing the whole block of sql text if (executeAsBlock) { start = System.currentTimeMillis(); // print the query logExecution(q.trim()); executing = true; SqlStatementResult result = qs.execute(q, true); if (Thread.interrupted()) { throw new InterruptedException(); } if (result.isResultSet()) { ResultSet rset = result.getResultSet(); if (rset == null) { setOutputMessage(QueryEditorConstants.ERROR_MESSAGE, result.getErrorMessage()); setLeftStatusText(ERROR_EXECUTING); } else { setResultSet(rset, q); } } else { int updateCount = result.getUpdateCount(); if (updateCount == -1) { setOutputMessage(QueryEditorConstants.ERROR_MESSAGE, result.getErrorMessage()); setLeftStatusText(ERROR_EXECUTING); } else { panel.setResultText(updateCount, QuerySender.UNKNOWN); } } end = System.currentTimeMillis(); panel.addToHistory(q); return DONE; } int type = -1; isSelect = false; executing = true; String query = null; String tempQuery = q; String procQuery = tempQuery.toUpperCase(); start = System.currentTimeMillis(); // check if its a procedure creation or execution if (isCreateProcedureOrFunction(procQuery)) { logExecution(tempQuery.trim()); SqlStatementResult result = qs.createProcedure(procQuery); if (result.getUpdateCount() == -1) { setOutputMessage(QueryEditorConstants.ERROR_MESSAGE, result.getErrorMessage()); setLeftStatusText(ERROR_EXECUTING); } else { if (isCreateProcedure(procQuery)) { setResultText(result.getUpdateCount(), QuerySender.CREATE_PROCEDURE); } else if (isCreateFunction(procQuery)) { setResultText(result.getUpdateCount(), QuerySender.CREATE_FUNCTION); } } outputWarnings(result.getSqlWarning()); panel.addToHistory(tempQuery); return DONE; }// StringTokenizer st = tokenizeQuery(tempQuery);// int tokens = st.countTokens(); List<String> queries = tokenizeQuery(tempQuery); String _query = null; String returnQuery = null; start = System.currentTimeMillis(); int count = 0; //while(st.hasMoreTokens()) { for (int i = 0, n = queries.size(); i < n; i++) { returnQuery = originalQueries.get(count); count++; //query = st.nextToken().trim(); query = queries.get(i); _query = query.toUpperCase(); type = qs.getQueryType(query); if (type != QuerySender.COMMIT && type != QuerySender.ROLLBACK) { logExecution(query); } else { if (type == QuerySender.COMMIT) { setOutputMessage( QueryEditorConstants.ACTION_MESSAGE, COMMITTING_LAST); } else if (type == QuerySender.ROLLBACK) { setOutputMessage( QueryEditorConstants.ACTION_MESSAGE, ROLLINGBACK_LAST); } } SqlStatementResult result = qs.executeQuery(type, query); if (statementCancelled || Thread.interrupted()) { throw new InterruptedException(); } if (result.isResultSet()) { ResultSet rset = result.getResultSet(); if (rset == null) { String message = result.getErrorMessage(); if (message == null) { message = result.getMessage(); // if still null dump simple message if (message == null) { message = "A NULL result set was returned."; } } setOutputMessage(QueryEditorConstants.ERROR_MESSAGE, message); setLeftStatusText(ERROR_EXECUTING); } else { setResultSet(rset, returnQuery); } } else { // check that we executed a 'normal' statement (not a proc) if (result.getType() != QuerySender.EXECUTE) { int updateCount = result.getUpdateCount(); if (updateCount == -1) { setOutputMessage(QueryEditorConstants.ERROR_MESSAGE, result.getErrorMessage()); setLeftStatusText(ERROR_EXECUTING); } else { type = result.getType(); setResultText(updateCount, type); if (type == QuerySender.COMMIT || type == QuerySender.ROLLBACK) { setLeftStatusText(" " + result.getMessage()); } } } else { Hashtable results = (Hashtable)result.getOtherResult(); if (results == null) { setOutputMessage(QueryEditorConstants.ERROR_MESSAGE, result.getErrorMessage()); setLeftStatusText(ERROR_EXECUTING); } else { setOutputMessage(QueryEditorConstants.PLAIN_MESSAGE, "Call executed successfully."); int updateCount = result.getUpdateCount(); if (updateCount > 0) { setOutputMessage(QueryEditorConstants.PLAIN_MESSAGE, updateCount + ((updateCount > 1) ? " rows affected." : " row affected.")); } String SPACE = " = "; Enumeration keys = results.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement().toString(); setOutputMessage(QueryEditorConstants.PLAIN_MESSAGE, key + SPACE + results.get(key)); } } } } /* if (count == tokens) { panel.addToHistory(q); } */ } panel.addToHistory(q); end = System.currentTimeMillis(); } catch (SQLException e) { processException(e); return "SQLException"; } catch (InterruptedException e) { //Log.debug("InterruptedException"); statementCancelled = true; // make sure its set return "Interrupted"; } catch (OutOfMemoryError e) { setOutputMessage(QueryEditorConstants.ERROR_MESSAGE, "Resources exhausted while executing query.\n"+ "The query result set was too large to return."); panel.setLeftStatusText(ERROR_EXECUTING); } catch (Exception e) { if (!statementCancelled) { e.printStackTrace(); processException(e); } } finally { qs.releaseStatements(); if (end == 0) { end = System.currentTimeMillis(); } duration = MiscUtils.formatDuration(end - start); } return DONE; } /** * Logs the specified query being executed. * * @param query - the executed query */ private void logExecution(String query) { Log.info(EXECUTING_1 + query); if (verboseLogging) { setOutputMessage( QueryEditorConstants.ACTION_MESSAGE, EXECUTING_1); setOutputMessage( QueryEditorConstants.ACTION_MESSAGE_PREFORMAT, query); } else { int queryLength = query.length(); int subIndex = queryLength < 50 ? (queryLength + 1) : 50; setOutputMessage( QueryEditorConstants.ACTION_MESSAGE, EXECUTING_1); setOutputMessage( QueryEditorConstants.ACTION_MESSAGE_PREFORMAT, query.substring(0, subIndex-1).trim() + SUBSTRING); } } private void processException(Throwable e) { setOutputMessage(QueryEditorConstants.ERROR_MESSAGE, e.getMessage()); if (e instanceof SQLException) { SQLException sqlExc = (SQLException)e; sqlExc = sqlExc.getNextException(); if (sqlExc != null) { setOutputMessage(QueryEditorConstants.ERROR_MESSAGE, sqlExc.getMessage()); } } else { setLeftStatusText(ERROR_EXECUTING); } } private void setResultText(final int result, final int type) { GUIUtils.invokeAndWait(new Runnable() { public void run() { panel.setResultText(result, type); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -