SlowQueryReport (Apache Tomcat 7.0.104 API Documentation)

org.apache.tomcat.jdbc.pool.interceptor

## Class SlowQueryReport

- java.lang.Object
- - org.apache.tomcat.jdbc.pool.JdbcInterceptor
  - - org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor
    - - org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport
      - - org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport

- All Implemented Interfaces:
    InvocationHandler
  Direct Known Subclasses:
    SlowQueryReportJmx

      public class SlowQueryReport
      extends AbstractQueryReport

  Slow query report interceptor. Tracks timing of query executions.
  Version:
    1.0
  Author:
    Filip Hanik

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `SlowQueryReport.QueryStats`

    - ### Nested classes/interfaces inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport

      `AbstractQueryReport.StatementProxy`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `maxQueries` Maximum number of queries we will be storing
    `protected static ConcurrentHashMap<String,ConcurrentHashMap<String,SlowQueryReport.QueryStats>>` | `perPoolStats` we will be keeping track of query stats on a per pool basis
    `protected ConcurrentHashMap<String,SlowQueryReport.QueryStats>` | `queries` the queries that are used for this interceptor.
    `protected Comparator<SlowQueryReport.QueryStats>` | `queryStatsComparator` Sort QueryStats by last invocation time

    - ### Fields inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport

      `threshold`

    - ### Fields inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor

      `constructors, CREATE_STATEMENT, CREATE_STATEMENT_IDX, EXECUTE, EXECUTE_BATCH, EXECUTE_QUERY, EXECUTE_TYPES, EXECUTE_UPDATE, PREPARE_CALL, PREPARE_CALL_IDX, PREPARE_STATEMENT, PREPARE_STATEMENT_IDX, STATEMENT_TYPE_COUNT, STATEMENT_TYPES`

    - ### Fields inherited from class org.apache.tomcat.jdbc.pool.JdbcInterceptor

      `CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VAL`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SlowQueryReport()` Creates a slow query report interceptor

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `closeInvoked()` invoked when the connection receives the close request Not used for now.
    `static ConcurrentHashMap<String,SlowQueryReport.QueryStats>` | `getPoolStats(String poolname)` Returns the query stats for a given pool
    `protected SlowQueryReport.QueryStats` | `getQueryStats(String sql)`
    `void` | `poolClosed(ConnectionPool pool)` This method is invoked by a connection pool when the pool is closed.
    `void` | `poolStarted(ConnectionPool pool)` This method is invoked by a connection pool when the pool is first started up, usually when the first connection is requested.
    `void` | `prepareCall(String sql, long time)` Invoked when prepareCall has been called and completed.
    `void` | `prepareStatement(String sql, long time)` Invoked when prepareStatement has been called and completed.
    `protected void` | `removeOldest(ConcurrentHashMap<String,SlowQueryReport.QueryStats> queries)` Sort QueryStats by last invocation time
    `protected String` | `reportFailedQuery(String query, Object[] args, String name, long start, Throwable t)` Invoked when a query execution, a call to execute/executeQuery or executeBatch failed.
    `protected String` | `reportQuery(String query, Object[] args, String name, long start, long delta)` Invoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was within the timing threshold
    `protected String` | `reportSlowQuery(String query, Object[] args, String name, long start, long delta)` Invoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was exceeded the timing threshold
    `void` | `reset(ConnectionPool parent, PooledConnection con)` no-op for this interceptor. no state is stored.
    `void` | `setMaxQueries(int maxQueries)`
    `void` | `setProperties(Map<String,PoolProperties.InterceptorProperty> properties)` Called during the creation of an interceptor The properties can be set during the configuration of an interceptor Override this method to perform type casts between string values and object properties

    - ### Methods inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport

      `createStatement, getThreshold, setThreshold`

    - ### Methods inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor

      `getConstructor, invoke, isExecute, isStatement, process`

    - ### Methods inherited from class org.apache.tomcat.jdbc.pool.JdbcInterceptor

      `compare, compare, disconnected, getNext, getProperties, isUseEquals, setNext, setUseEquals`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### perPoolStats

          protected static ConcurrentHashMap<String,ConcurrentHashMap<String,SlowQueryReport.QueryStats>> perPoolStats

      we will be keeping track of query stats on a per pool basis

    - #### queries

          protected volatile ConcurrentHashMap<String,SlowQueryReport.QueryStats> queries

      the queries that are used for this interceptor.

    - #### maxQueries

          protected int maxQueries

      Maximum number of queries we will be storing

    - #### queryStatsComparator

          protected final Comparator<SlowQueryReport.QueryStats> queryStatsComparator

      Sort QueryStats by last invocation time

  - ### Constructor Detail

    - #### SlowQueryReport

          public SlowQueryReport()

      Creates a slow query report interceptor

  - ### Method Detail

    - #### getPoolStats

          public static ConcurrentHashMap<String,SlowQueryReport.QueryStats> getPoolStats(String poolname)

      Returns the query stats for a given pool
      Parameters:
        `poolname` - - the name of the pool we want to retrieve stats for
      Returns:
        a hash map containing statistics for 0 to maxQueries

    - #### setMaxQueries

          public void setMaxQueries(int maxQueries)

    - #### reportFailedQuery

          protected String reportFailedQuery(String query,
                                 Object[] args,
                                 String name,
                                 long start,
                                 Throwable t)

      Description copied from class: `AbstractQueryReport`
      Invoked when a query execution, a call to execute/executeQuery or executeBatch failed.
      Overrides:
        `reportFailedQuery` in class `AbstractQueryReport`
      Parameters:
        `query` - the query that was executed and failed
        `args` - the arguments to the execution
        `name` - the name of the method used to execute `AbstractCreateStatementInterceptor.isExecute(Method, boolean)`
        `start` - the time the query execution started
        `t` - the exception that happened
      Returns:
        - the SQL that was executed or the string "batch" if it was a batch execution

    - #### reportQuery

          protected String reportQuery(String query,
                           Object[] args,
                           String name,
                           long start,
                           long delta)

      Description copied from class: `AbstractQueryReport`
      Invoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was within the timing threshold
      Overrides:
        `reportQuery` in class `AbstractQueryReport`
      Parameters:
        `query` - the query that was executed and failed
        `args` - the arguments to the execution
        `name` - the name of the method used to execute `AbstractCreateStatementInterceptor.isExecute(Method, boolean)`
        `start` - the time the query execution started
        `delta` - the time the execution took
      Returns:
        - the SQL that was executed or the string "batch" if it was a batch execution

    - #### reportSlowQuery

          protected String reportSlowQuery(String query,
                               Object[] args,
                               String name,
                               long start,
                               long delta)

      Description copied from class: `AbstractQueryReport`
      Invoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was exceeded the timing threshold
      Overrides:
        `reportSlowQuery` in class `AbstractQueryReport`
      Parameters:
        `query` - the query that was executed and failed
        `args` - the arguments to the execution
        `name` - the name of the method used to execute `AbstractCreateStatementInterceptor.isExecute(Method, boolean)`
        `start` - the time the query execution started
        `delta` - the time the execution took
      Returns:
        - the SQL that was executed or the string "batch" if it was a batch execution

    - #### closeInvoked

          public void closeInvoked()

      invoked when the connection receives the close request Not used for now.
      Specified by:
        `closeInvoked` in class `AbstractCreateStatementInterceptor`

    - #### prepareStatement

          public void prepareStatement(String sql,
                              long time)

      Description copied from class: `AbstractQueryReport`
      Invoked when prepareStatement has been called and completed.
      Specified by:
        `prepareStatement` in class `AbstractQueryReport`
      Parameters:
        `sql` - - the string used to prepare the statement with
        `time` - - the time it took to invoke prepare

    - #### prepareCall

          public void prepareCall(String sql,
                         long time)

      Description copied from class: `AbstractQueryReport`
      Invoked when prepareCall has been called and completed.
      Specified by:
        `prepareCall` in class `AbstractQueryReport`
      Parameters:
        `sql` - - the string used to prepare the statement with
        `time` - - the time it took to invoke prepare

    - #### poolStarted

          public void poolStarted(ConnectionPool pool)

      This method is invoked by a connection pool when the pool is first started up, usually when the first connection is requested. Interceptor classes can override this method if they keep static variables or other tracking means around. This method is only invoked on a single instance of the interceptor, and not on every instance created.
      Overrides:
        `poolStarted` in class `JdbcInterceptor`
      Parameters:
        `pool` - - the pool that is being closed.

    - #### poolClosed

          public void poolClosed(ConnectionPool pool)

      This method is invoked by a connection pool when the pool is closed. Interceptor classes can override this method if they keep static variables or other tracking means around. This method is only invoked on a single instance of the interceptor, and not on every instance created.
      Overrides:
        `poolClosed` in class `JdbcInterceptor`
      Parameters:
        `pool` - - the pool that is being closed.

    - #### getQueryStats

          protected SlowQueryReport.QueryStats getQueryStats(String sql)

    - #### removeOldest

          protected void removeOldest(ConcurrentHashMap<String,SlowQueryReport.QueryStats> queries)

      Sort QueryStats by last invocation time
      Parameters:
        `queries` -

    - #### reset

          public void reset(ConnectionPool parent,
                   PooledConnection con)

      Description copied from class: `AbstractCreateStatementInterceptor`
      no-op for this interceptor. no state is stored.
      Overrides:
        `reset` in class `AbstractCreateStatementInterceptor`
      Parameters:
        `parent` - - the connection pool owning the connection
        `con` - - the pooled connection

    - #### setProperties

          public void setProperties(Map<String,PoolProperties.InterceptorProperty> properties)

      Description copied from class: `JdbcInterceptor`
      Called during the creation of an interceptor The properties can be set during the configuration of an interceptor Override this method to perform type casts between string values and object properties
      Overrides:
        `setProperties` in class `JdbcInterceptor`

Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.