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

📄 profiledconnection.java

📁 jive 2.1.1 的源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    if (!hasQuotes && inValue) {
                        endValue = x;
                        inValue = false;
                        hasQuotes = false;
                        afterEquals = false;
                    }
                    break;
                }
                case '\'': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;
                        hasQuotes = true;
                    }
                    else if (afterEquals && inValue && hasQuotes) {
                        endValue = x+1;
                        inValue = false;
                        hasQuotes = false;
                        afterEquals = false;
                    }
                    break;
                }
                case '-': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;

                    }
                    break;
                }
                case '+': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;
                    }
                    break;
                }
                case '0': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;
                    }
                    break;
                }
                case '1': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;
                    }
                    break;
                }
                case '2': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;
                    }
                    break;
                }
                case '3': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;
                    }
                    break;
                }
                case '4': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;
                    }
                    break;
                }
                case '5': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;
                    }
                    break;
                }
                case '6': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;
                    }
                    break;
                }
                case '7': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;
                    }
                    break;
                }
                case '8': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;
                    }
                    break;
                }
                case '9': {
                    if (afterEquals && !inValue) {
                        startValue = x;
                        inValue = true;
                    }
                    break;
                }
                default: {
                    if (afterEquals && !inValue) {
                        afterEquals = false;
                    }
                }
            }

            if (x == length-1 && afterEquals) {
                endValue = x+1;
            }

            if (startValue != -1 && endValue != -1) {
                sql.replace(startValue-charRemoved, endValue-charRemoved, "?");

                charRemoved += endValue - startValue - 1;
                startValue = -1;
                endValue = -1;
            }
        }

        return sql.toString();
    }

    //--------------------- Connection Wrapping Code ---------------------//


    private Connection connection;

    /**
     * Creates a new ProfiledConnection that wraps the specified connection.
     *
     * @param connection the Connection to wrap and collect stats for.
     */
    public ProfiledConnection(Connection connection) throws SQLException {
        if (connection != null) {
            this.connection = connection;
        }
        else {
            throw new SQLException("ProfiledConnection constructor was given a " +
                    "null connection");
        }

    }

    public void close() throws SQLException {
        //Close underlying connection.
        if (connection != null) {
            connection.close();
        }
    }

    public String toString() {
        if (connection != null) {
            return connection.toString();
        }
        else {
            return "ProfiledConnection connection wrapper";
        }
    }

    public Statement createStatement() throws SQLException {
        //Returned a TimedStatement so that we can do db timings.
        return new TimedStatement(connection.createStatement());
    }

    public PreparedStatement prepareStatement(String sql) throws SQLException {
        //Returned a TimedPreparedStatement so that we can do db timings.
        return new TimedPreparedStatement(connection.prepareStatement(sql), sql);
    }

    public CallableStatement prepareCall(String sql) throws SQLException {
        return connection.prepareCall(sql);
    }

    public String nativeSQL(String sql) throws SQLException {
        return connection.nativeSQL(sql);
    }

    public void setAutoCommit(boolean autoCommit) throws SQLException {
        connection.setAutoCommit(autoCommit);
    }

    public boolean getAutoCommit() throws SQLException {
        return connection.getAutoCommit();
    }

    public void commit() throws SQLException {
        connection.commit();
    }

    public void rollback() throws SQLException {
        connection.rollback();
    }

    public boolean isClosed() throws SQLException {
        return connection.isClosed();
    }

    public DatabaseMetaData getMetaData() throws SQLException {
        return connection.getMetaData();
    }

    public void setReadOnly(boolean readOnly) throws SQLException {
        connection.setReadOnly(readOnly);
    }

    public boolean isReadOnly() throws SQLException {
        return connection.isReadOnly();
    }

    public void setCatalog(String catalog) throws SQLException {
        connection.setCatalog(catalog);
    }

    public String getCatalog() throws SQLException {
        return connection.getCatalog();
    }

    public void setTransactionIsolation(int level) throws SQLException {
        connection.setTransactionIsolation(level);
    }

    public int getTransactionIsolation() throws SQLException {
        return connection.getTransactionIsolation();
    }

    public SQLWarning getWarnings() throws SQLException {
        return connection.getWarnings();
    }

    public void clearWarnings() throws SQLException {
        connection.clearWarnings();
    }

    public Statement createStatement(int resultSetType, int resultSetConcurrency)
            throws SQLException
    {
        return new TimedStatement(connection.createStatement(resultSetType,
                resultSetConcurrency));
    }

    public PreparedStatement prepareStatement(String sql, int resultSetType,
            int resultSetConcurrency) throws SQLException
    {
        return new TimedPreparedStatement(connection.prepareStatement(
                sql,resultSetType, resultSetConcurrency), sql);
    }

    public CallableStatement prepareCall(String sql, int resultSetType,
            int resultSetConcurrency) throws SQLException
    {
        return connection.prepareCall(sql, resultSetType, resultSetConcurrency);
    }

    public Map getTypeMap() throws SQLException {
        return connection.getTypeMap();
    }

    public void setTypeMap(Map map) throws SQLException {
        connection.setTypeMap(map);
    }

    /**
     * An implementation of the Statement interface that wraps an underlying
     * Statement object and performs timings of the database queries. The class
     * does not handle batch queries but should generally work otherwise.
     */
    class TimedStatement implements Statement {

        private Statement stmt;
        private int type;

        /**
         * Creates a new TimedStatement that wraps <tt>stmt</tt>.
         */
        public TimedStatement(Statement stmt) {
            this.stmt = stmt;
        }

        public void addBatch(String sql) throws SQLException {
            stmt.addBatch(sql);
        }

        public void cancel() throws SQLException {
            stmt.cancel();
        }

        public void clearBatch() throws SQLException {
            stmt.clearBatch();
        }

        public void clearWarnings() throws SQLException {
            stmt.clearWarnings();
        }

        public void close() throws SQLException {
            stmt.close();
        }

        public boolean execute(String sql) throws SQLException {

            long t1 = System.currentTimeMillis();
            boolean result = stmt.execute(sql);
            long t2 = System.currentTimeMillis();

            // determine the type of query
            String sqlL = sql.toLowerCase().trim();

            if (sqlL.startsWith("insert")) {
                addQuery(INSERT, sql, t2-t1);
            }
            else if (sqlL.startsWith("update")) {
                addQuery(UPDATE, sql, t2-t1);
            }
            else if (sqlL.startsWith("delete")) {
                addQuery(DELETE, sql, t2-t1);
            }
            else {
                addQuery(SELECT, sql, t2-t1);
            }
            return result;
        }

        public int[] executeBatch() throws SQLException {
            return stmt.executeBatch();
        }

        public ResultSet executeQuery(String sql) throws SQLException {
            long t1 = System.currentTimeMillis();
            ResultSet result = stmt.executeQuery(sql);
            long t2 = System.currentTimeMillis();

            // determine the type of query
            String sqlL = sql.toLowerCase().trim();

            if (sqlL.startsWith("insert")) {
                addQuery(INSERT, sql, t2-t1);
            }
            else if (sqlL.startsWith("update")) {
                addQuery(UPDATE, sql, t2-t1);
            }
            else if (sqlL.startsWith("delete")) {
                addQuery(DELETE, sql, t2-t1);
            }
            else {
                addQuery(SELECT, sql, t2-t1);
            }
            return result;
        }

        public int executeUpdate(String sql) throws SQLException {
            long t1 = System.currentTimeMillis();
            int result = stmt.executeUpdate(sql);
            long t2 = System.currentTimeMillis();

            // determine the type of query
            String sqlL = sql.toLowerCase().trim();

            if (sqlL.startsWith("insert")) {
                addQuery(INSERT, sql, t2-t1);
            }
            else if (sqlL.startsWith("update")) {
                addQuery(UPDATE, sql, t2-t1);
            }
            else if (sqlL.startsWith("delete")) {
                addQuery(DELETE, sql, t2-t1);
            }
            else {
                addQuery(SELECT, sql, t2-t1);
            }
            return result;
        }

        public Connection getConnection() throws SQLException {
            return stmt.getConnection();
        }

        public int getFetchDirection() throws SQLException {
            return stmt.getFetchDirection();
        }

        public int getFetchSize()  throws SQLException {
            return stmt.getFetchSize();
        }

        public int getMaxFieldSize() throws SQLException {
            return stmt.getMaxFieldSize();
        }

        public int getMaxRows() throws SQLException {
            return stmt.getMaxRows();
        }

        public boolean getMoreResults() throws SQLException {
            return stmt.getMoreResults();
        }

        public int getQueryTimeout() throws SQLException {
            return stmt.getQueryTimeout();
        }

        public ResultSet getResultSet() throws SQLException {
            return stmt.getResultSet();
        }

        public int getResultSetConcurrency() throws SQLException {
            return stmt.getResultSetConcurrency();
        }

        public int getResultSetType() throws SQLException {
            return stmt.getResultSetType();
        }

        public int getUpdateCount() throws SQLException {
            return stmt.getUpdateCount();
        }

        public SQLWarning getWarnings() throws SQLException {
            return stmt.getWarnings();
        }

        public void setCursorName(String name) throws SQLException {
            stmt.setCursorName(name);
        }

        public void setEscapeProcessing(boolean enable) throws SQLException {
            stmt.setEscapeProcessing(enable);
        }

        public void setFetchDirection(int direction) throws SQLException {
            stmt.setFetchDirection(direction);
        }

        public void setFetchSize(int rows) throws SQLException {
            stmt.setFetchSize(rows);
        }

        public void setMaxFieldSize(int max) throws SQLException {
            stmt.setMaxFieldSize(max);
        }

        public void setMaxRows(int max) throws SQLException {
            stmt.setMaxRows(max);
        }

        public void setQueryTimeout(int seconds) throws SQLException {
            stmt.setQueryTimeout(seconds);
        }

⌨️ 快捷键说明

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