⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queryanalyser.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * QueryAnalyser.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * */package org.executequery.gui.editor;import java.io.IOException;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.SQLWarning;import java.util.ArrayList;import java.util.Enumeration;import java.util.Hashtable;import java.util.List;import java.util.regex.Matcher;import java.util.regex.Pattern;import org.executequery.Constants;import org.executequery.GUIUtilities;import org.underworldlabs.util.SystemProperties;import org.executequery.SystemUtilities;import org.executequery.databasemediators.DatabaseConnection;import org.executequery.databasemediators.QuerySender;import org.executequery.databasemediators.SqlStatementResult;import org.underworldlabs.swing.util.SwingWorker;import org.executequery.gui.SQLExecutor;import org.executequery.gui.text.syntax.Token;import org.executequery.gui.text.syntax.TokenTypes;import org.executequery.util.Log;import org.underworldlabs.util.MiscUtils;import org.executequery.util.OutputLogger;import org.underworldlabs.swing.GUIUtils;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the  *           release of version 3.0.0beta1 has meant a  *           resetting of CVS revision numbers. * ---------------------------------------------------------- *//** <p>Determines the type of exeuted query and returns *  appropriate results. * *  @author   Takis Diakoumis * @version  $Revision: 1.11 $ * @date     $Date: 2006/09/21 13:17:00 $ */public class QueryAnalyser {        /** the parent controller */    private SQLExecutor panel;       /** thread worker object */    private SwingWorker worker;        /** the query sender database mediator */    private QuerySender qs;        /** indicates verbose logging output */    private boolean verboseLogging;        /** logging on/off flag */    private boolean logging;        /** Indicates that an execute is in progress */    private boolean executing;        /** indicates that executed query was a SQL SELECT statement */    private boolean isSelect;        /** connection commit mode */    private boolean autoCommitMode;        /** Regex matcher for quote marks */    private Matcher quoteMatcher;        /** Regex matcher for single-line comments */    private Matcher singleLineCommentMatcher;    /** Regex matcher for multi-line comments */    private Matcher multiLineCommentMatcher;    /** Regex matcher for final query trim */    private Matcher trimNewLineMatcher;            /** The query execute duration time */    private String duration;        /** indicates that the current execution has been cancelled */    private boolean statementCancelled;    // ------------------------------------------------    // static string constants    // ------------------------------------------------        private static final String BEGIN = "BEGIN";    private static final String DECLARE = "DECLARE";        private static final String delim = ";";    private static final String SUBSTRING = "...";    private static final String EXECUTING_1 = "Executing: ";    private static final String EXECUTING_2 = " Executing... ";    private static final String ERROR_EXECUTING = " Error executing statement";    private static final String SUCCESS = " Statement executed successfully";    private static final String DONE = " Done";    private static final String LOGGER_NAME = "query-editor";    private static final String COMMITTING_LAST = "Committing last transaction block...";    private static final String ROLLINGBACK_LAST = "Rolling back last transaction block...";    // ------------------------------------------------        public QueryAnalyser(SQLExecutor panel) {        this.panel = panel;        qs = new QuerySender(null, true);        setCommitMode(SystemProperties.getBooleanProperty("user", "editor.connection.commit"));        //quoteMatcher = Pattern.compile("'([^'\r\n])+'|'.*").matcher(Constants.EMPTY);                initialiseLogging();    }    /**     * Intialises the regex matchers.     */    protected void initMatchers() {        if (quoteMatcher == null) {            quoteMatcher = Pattern.compile(                    "'((?>[^']*+)(?>'''[^']*+)*+)'|'.*").matcher(Constants.EMPTY);                    }                if (singleLineCommentMatcher == null) {            singleLineCommentMatcher = Pattern.compile(                    TokenTypes.SINGLE_LINE_COMMENT_REGEX, Pattern.MULTILINE).                    matcher(Constants.EMPTY);        }                if (multiLineCommentMatcher == null) {            multiLineCommentMatcher = Pattern.compile(                    "/\\*((?>[^\\*/]*+)*+)\\*/|/\\*.*", Pattern.DOTALL).                    matcher(Constants.EMPTY);        }                if (trimNewLineMatcher == null) {            trimNewLineMatcher = Pattern.compile(                    //"\\A\\s+|\n{2,}|\\s+\\z", Pattern.DOTALL).                    "\n{2,}", Pattern.DOTALL).                    matcher(Constants.EMPTY);                    }    }        /**     * Notification of user preference changes.     */    public void preferencesChanged() {        initialiseLogging();    }        /**     * Logging initialisation.     */    protected void initialiseLogging() {        verboseLogging = SystemProperties.getBooleanProperty("user", "editor.logging.verbose");        logging = SystemProperties.getBooleanProperty("user", "editor.logging.enabled");        if (logging) {            String layout = "[%d{dd-MM-yy HH:mm:ss}] %m%n";            String path = SystemProperties.getStringProperty("user", "editor.logging.path");            int maxBackups = SystemProperties.getIntProperty("user", "editor.logging.backups");            if (!MiscUtils.isNull(path)) {                try {                    OutputLogger.initialiseLogger(LOGGER_NAME, layout, path, maxBackups);                } catch (IOException e) {                    StringBuffer sb = new StringBuffer();                    sb.append("An error occurred initialising the logger.").                       append("\n\nThe system returned:\n").                       append(e.getMessage());                    GUIUtilities.displayExceptionErrorDialog(sb.toString(), e);                }            }            if (newLineMatcher == null) {                newLineMatcher = Pattern.compile("\n").matcher("");            }        }    }        /**     * Sets the commit mode to that specified.     *     * @param the commit mode     */    public void setCommitMode(boolean commitMode) {        autoCommitMode = commitMode;        qs.setCommitMode(autoCommitMode);        panel.setRightStatusText(" Auto-Commit: " + autoCommitMode);    }        /**     * Propagates the call to close the connection to      * the QuerySender object.     */    public void closeConnection() {        try {            if (qs != null) {                qs.closeConnection();            }        }        catch (SQLException sqlExc) {}    }        /**     * Indicates a connection has been closed.     * Propagates the call to the query sender object.     *      * @param the connection thats been closed     */    public void disconnected(DatabaseConnection dc) {        qs.disconnected(dc);    }    /**     * Returns the current commit mode.     *     * @return the commit mode     */    public boolean getCommitMode() {        return autoCommitMode;    }        /**     * Executes the query(ies) as specified. 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     */    public void executeSQLQuery(String query, boolean executeAsBlock) {        executeSQLQuery(null, query, executeAsBlock);    }    /**     * Executes the query(ies) as specified on the provided database     * connection properties object. The executeAsBlock flag     * indicates that the query should be executed in its entirety -      * not split up into mulitple queries (where applicable).     *     * @param the connection object     * @param the query string     * @param true to execute in entirety, false otherwise     */    public void executeSQLQuery(DatabaseConnection dc,                                 final String query,                                 final boolean executeAsBlock) {        if (!SystemUtilities.isConnected()) {            setOutputMessage(QueryEditorConstants.PLAIN_MESSAGE, "Not Connected");            panel.setLeftStatusText(ERROR_EXECUTING);            return;        }        if (qs == null) {            qs = new QuerySender(null, true);        }        if (dc != null) {            qs.setDatabaseConnection(dc);        }                panel.setStopButtonEnabled(true);        statementCancelled = false;        worker = new SwingWorker() {            public Object construct() {                return executeSQL(query, executeAsBlock);            }            public void finished() {                panel.setStopButtonEnabled(false);                panel.setActivityStatusText(duration);                panel.setExecuting(false);                if (statementCancelled) {                    setOutputMessage(QueryEditorConstants.PLAIN_MESSAGE,                                     "Statement cancelled");                    panel.setLeftStatusText(" Statement cancelled");                }                qs.releaseResources();                executing = false;            }        };                setOutputMessage(QueryEditorConstants.PLAIN_MESSAGE,                 "---\nUsing connection: " + dc);        panel.setActivityStatusText(EXECUTING_2);        panel.setExecuting(true);        panel.setLeftStatusText(Constants.EMPTY);        worker.start();    }        /**     * Interrupts the statement currently being executed.     */    public void interruptStatement() {        //Log.debug("interruptStatement");        //Log.debug("executing " + executing);        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -