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

📄 profiledconnection.java

📁 jive 2.1.1 的源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }

    /**
     * An implementation of the PreparedStatement interface that wraps an
     * underlying PreparedStatement object and performs timings of the database
     * queries.
     */
    class TimedPreparedStatement implements PreparedStatement {

        private String sql;
        private PreparedStatement pstmt;
        private int type = SELECT;

        public TimedPreparedStatement(PreparedStatement _pstmt, String _sql) {
            this.pstmt  = _pstmt;
            this.sql    = _sql;

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

            if (sqlL.startsWith("insert")) {
                type = INSERT;
            }
            else if (sqlL.startsWith("update")) {
                type = UPDATE;
            }
            else if (sqlL.startsWith("delete")) {
                type = DELETE;
            }
            else {
                type = SELECT;
            }
        }

        public void addBatch() throws SQLException{
            pstmt.addBatch();
        }

        public void clearParameters() throws SQLException {
            pstmt.clearParameters();
        }

        public boolean execute() throws SQLException {
            //Perform timing of this method.
            long t1 = System.currentTimeMillis();
            boolean result = pstmt.execute();
            long t2 = System.currentTimeMillis();

            switch (type) {
                case SELECT:
                    addQuery(SELECT, sql, t2-t1);
                    break;
                case UPDATE:
                    addQuery(UPDATE, sql, t2-t1);
                    break;
                case INSERT:
                    addQuery(INSERT, sql, t2-t1);
                    break;
                case DELETE:
                    addQuery(DELETE, sql, t2-t1);
                    break;
            }
            return result;
        }

        /*
         * This is one of the methods that we wish to time
         */
        public ResultSet executeQuery() throws SQLException {

            long t1 = System.currentTimeMillis();
            ResultSet result = pstmt.executeQuery();
            long t2 = System.currentTimeMillis();

            switch (type) {
                case SELECT:
                    addQuery(SELECT, sql, t2-t1);
                    break;
                case UPDATE:
                    addQuery(UPDATE, sql, t2-t1);
                    break;
                case INSERT:
                    addQuery(INSERT, sql, t2-t1);
                    break;
                case DELETE:
                    addQuery(DELETE, sql, t2-t1);
                    break;
            }
            return result;
        }

        /*
         * This is one of the methods that we wish to time
         */
        public int executeUpdate() throws SQLException {

            long t1 = System.currentTimeMillis();
            int result = pstmt.executeUpdate();
            long t2 = System.currentTimeMillis();

            switch (type) {
                case SELECT:
                    addQuery(SELECT, sql, t2-t1);
                    break;
                case UPDATE:
                    addQuery(UPDATE, sql, t2-t1);
                    break;
                case INSERT:
                    addQuery(INSERT, sql, t2-t1);
                    break;
                case DELETE:
                    addQuery(DELETE, sql, t2-t1);
                    break;
            }
            return result;
        }

        public ResultSetMetaData getMetaData() throws SQLException {
            return pstmt.getMetaData();
        }

        public void setArray(int i, Array x) throws SQLException {
            pstmt.setArray(i, x);
        }

        public void setAsciiStream(int parameterIndex, InputStream x, int length)
                throws SQLException
        {
            pstmt.setAsciiStream(parameterIndex, x, length);
        }

        public void setBigDecimal(int parameterIndex, BigDecimal x)
                throws SQLException
        {
            pstmt.setBigDecimal(parameterIndex, x);
        }

        public void setBinaryStream(int parameterIndex, InputStream x, int length)
                throws SQLException
        {
            pstmt.setBinaryStream(parameterIndex, x, length);
        }

        public void setBlob(int i, Blob x) throws SQLException {
            pstmt.setBlob(i, x);
        }

        public void setBoolean(int parameterIndex, boolean x) throws SQLException {
            pstmt.setBoolean(parameterIndex, x);
        }

        public void setByte(int parameterIndex, byte x) throws SQLException {
            pstmt.setByte(parameterIndex, x);
        }

        public void setBytes(int parameterIndex, byte[] x) throws SQLException {
            pstmt.setBytes(parameterIndex, x);
        }

        public void setCharacterStream(int parameterIndex, Reader reader,
                int length) throws SQLException
        {
            pstmt.setCharacterStream(parameterIndex, reader, length);
        }

        public void setClob(int i, Clob x) throws SQLException {
            pstmt.setClob(i, x);
        }

        public void setDate(int parameterIndex, java.sql.Date x) throws SQLException {
            pstmt.setDate(parameterIndex, x);
        }

        public void setDate(int parameterIndex, java.sql.Date x, Calendar cal)
                throws SQLException
        {
            pstmt.setDate(parameterIndex, x, cal);
        }

        public void setDouble(int parameterIndex, double x) throws SQLException {
            pstmt.setDouble(parameterIndex, x);
        }

        public void setFloat(int parameterIndex, float x) throws SQLException {
            pstmt.setFloat(parameterIndex, x);
        }

        public void setInt(int parameterIndex, int x) throws SQLException {
            pstmt.setInt(parameterIndex, x);
        }

        public void setLong(int parameterIndex, long x) throws SQLException {
            pstmt.setLong(parameterIndex, x);
        }

        public void setNull(int parameterIndex, int sqlType) throws SQLException {
            pstmt.setNull(parameterIndex, sqlType);
        }

        public void setNull(int paramIndex, int sqlType, String typeName)
                throws SQLException
        {
            pstmt.setNull(paramIndex, sqlType, typeName);
        }

        public void setObject(int parameterIndex, Object x) throws SQLException {
            pstmt.setObject(parameterIndex, x);
        }

        public void setObject(int parameterIndex, Object x, int targetSqlType)
                throws SQLException
        {
            pstmt.setObject(parameterIndex, x, targetSqlType);
        }

        public void setObject(int parameterIndex, Object x, int targetSqlType,
                int scale) throws SQLException
        {
            pstmt.setObject(parameterIndex, x, targetSqlType, scale);
        }

        public void setRef(int i, Ref x) throws SQLException {
            pstmt.setRef(i, x);
        }

        public void setShort(int parameterIndex, short x) throws SQLException {
            pstmt.setShort(parameterIndex, x);
        }

        public void setString(int parameterIndex, String x) throws SQLException {
            pstmt.setString(parameterIndex, x);
        }

        public void setTime(int parameterIndex, Time x) throws SQLException {
            pstmt.setTime(parameterIndex, x);
        }

        public void setTime(int parameterIndex, Time x, Calendar cal)
                throws SQLException
        {
            pstmt.setTime(parameterIndex, x, cal);
        }

        public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
            pstmt.setTimestamp(parameterIndex, x);
        }

        public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
                throws SQLException
        {
            pstmt.setTimestamp(parameterIndex, x, cal);
        }

        public void setUnicodeStream(int parameterIndex, InputStream x, int length)
                throws SQLException
        {
            throw new UnsupportedOperationException();
        }

        // The following methods are from the Statement class - the
        // SuperInterface of PreparedStatement
        // without these this class won't compile

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

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

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

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

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

        public boolean execute(String _sql) throws SQLException {

            long t1 = System.currentTimeMillis();
            boolean result = pstmt.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 {

            long t1 = System.currentTimeMillis();
            int[] result = pstmt.executeBatch();
            long t2 = System.currentTimeMillis();

            switch (type) {
                case SELECT:
                    addQuery(SELECT, sql, t2-t1);
                    break;
                case UPDATE:
                    addQuery(UPDATE, sql, t2-t1);
                    break;
                case INSERT:
                    addQuery(INSERT, sql, t2-t1);
                    break;
                case DELETE:
                    addQuery(DELETE, sql, t2-t1);
                    break;
            }
            return result;
        }

        public ResultSet executeQuery(String _sql) throws SQLException {
            long t1 = System.currentTimeMillis();
            ResultSet result = pstmt.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 = pstmt.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 pstmt.getConnection();
        }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

⌨️ 快捷键说明

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