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
Slow query report interceptor. Tracks timing of query executions.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
Compare QueryStats by their lastInvocation value.Nested classes/interfaces inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport
AbstractQueryReport.StatementProxy
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
Flag to enable disable logging of failed queriesprotected boolean
Flag to enable disable logging of slow queriesprotected int
Maximum number of queries we will be storingprotected static final ConcurrentHashMap<String,
ConcurrentHashMap<String, SlowQueryReport.QueryStats>> we will be keeping track of query stats on a per pool basisprotected ConcurrentHashMap<String,
SlowQueryReport.QueryStats> the queries that are used for this interceptor.protected final Comparator<SlowQueryReport.QueryStats>
Sort QueryStats by last invocation timeFields 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, GET_GENERATED_KEYS, GET_RESULTSET, GET_STATEMENT, PREPARE_CALL, PREPARE_CALL_IDX, PREPARE_STATEMENT, PREPARE_STATEMENT_IDX, RESULTSET_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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
invoked when the connection receives the close request Not used for now.getPoolStats
(String poolname) Returns the query stats for a given poolprotected SlowQueryReport.QueryStats
getQueryStats
(String sql) boolean
boolean
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
Sort QueryStats by last invocation timeprotected 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 thresholdprotected 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 thresholdvoid
reset
(ConnectionPool parent, PooledConnection con) no-op for this interceptor. no state is stored.void
setLogFailed
(boolean logFailed) void
setLogSlow
(boolean logSlow) 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 propertiesMethods 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
-
Field Details
-
perPoolStats
protected static final ConcurrentHashMap<String,ConcurrentHashMap<String, perPoolStatsSlowQueryReport.QueryStats>> we will be keeping track of query stats on a per pool basis -
queries
the queries that are used for this interceptor. -
maxQueries
protected int maxQueriesMaximum number of queries we will be storing -
logSlow
protected boolean logSlowFlag to enable disable logging of slow queries -
logFailed
protected boolean logFailedFlag to enable disable logging of failed queries -
queryStatsComparator
Sort QueryStats by last invocation time
-
-
Constructor Details
-
SlowQueryReport
public SlowQueryReport()Creates a slow query report interceptor
-
-
Method Details
-
getPoolStats
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 classAbstractQueryReport
- Parameters:
query
- the query that was executed and failedargs
- the arguments to the executionname
- the name of the method used to executeAbstractCreateStatementInterceptor.isExecute(Method, boolean)
start
- the time the query execution startedt
- the exception that happened- Returns:
- - the SQL that was executed or the string "batch" if it was a batch execution
-
reportQuery
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 classAbstractQueryReport
- Parameters:
query
- the query that was executed and failedargs
- the arguments to the executionname
- the name of the method used to executeAbstractCreateStatementInterceptor.isExecute(Method, boolean)
start
- the time the query execution starteddelta
- the time the execution took- Returns:
- - the SQL that was executed or the string "batch" if it was a batch execution
-
reportSlowQuery
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 classAbstractQueryReport
- Parameters:
query
- the query that was executed and failedargs
- the arguments to the executionname
- the name of the method used to executeAbstractCreateStatementInterceptor.isExecute(Method, boolean)
start
- the time the query execution starteddelta
- 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 classAbstractCreateStatementInterceptor
-
prepareStatement
Description copied from class:AbstractQueryReport
Invoked when prepareStatement has been called and completed.- Specified by:
prepareStatement
in classAbstractQueryReport
- Parameters:
sql
- - the string used to prepare the statement withtime
- - the time it took to invoke prepare
-
prepareCall
Description copied from class:AbstractQueryReport
Invoked when prepareCall has been called and completed.- Specified by:
prepareCall
in classAbstractQueryReport
- Parameters:
sql
- - the string used to prepare the statement withtime
- - the time it took to invoke prepare
-
poolStarted
Description copied from class:JdbcInterceptor
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 classJdbcInterceptor
- Parameters:
pool
- - the pool that is being closed.
-
poolClosed
Description copied from class:JdbcInterceptor
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 classJdbcInterceptor
- Parameters:
pool
- - the pool that is being closed.
-
getQueryStats
-
removeOldest
Sort QueryStats by last invocation time- Parameters:
queries
- The queries map
-
reset
Description copied from class:AbstractCreateStatementInterceptor
no-op for this interceptor. no state is stored.- Overrides:
reset
in classAbstractCreateStatementInterceptor
- Parameters:
parent
- - the connection pool owning the connectioncon
- - the pooled connection
-
isLogSlow
public boolean isLogSlow() -
setLogSlow
public void setLogSlow(boolean logSlow) -
isLogFailed
public boolean isLogFailed() -
setLogFailed
public void setLogFailed(boolean logFailed) -
setProperties
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 classJdbcInterceptor
- Parameters:
properties
- The properties
-