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 SummaryNested ClassesModifier and TypeClassDescriptionstatic classstatic classCompare QueryStats by their lastInvocation value.Nested classes/interfaces inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReportAbstractQueryReport.StatementProxy
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected booleanFlag to enable disable logging of failed queriesprotected booleanFlag to enable disable logging of slow queriesprotected intMaximum 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.AbstractQueryReportthresholdFields inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptorconstructors, 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_TYPESFields inherited from class org.apache.tomcat.jdbc.pool.JdbcInterceptorCLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VAL
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidinvoked when the connection receives the close request Not used for now.getPoolStats(String poolname) Returns the query stats for a given poolprotected SlowQueryReport.QueryStatsgetQueryStats(String sql) booleanbooleanvoidpoolClosed(ConnectionPool pool) This method is invoked by a connection pool when the pool is closed.voidpoolStarted(ConnectionPool pool) This method is invoked by a connection pool when the pool is first started up, usually when the first connection is requested.voidprepareCall(String sql, long time) Invoked when prepareCall has been called and completed.voidprepareStatement(String sql, long time) Invoked when prepareStatement has been called and completed.protected voidSort QueryStats by last invocation timeprotected StringreportFailedQuery(String query, Object[] args, String name, long start, Throwable t) Invoked when a query execution, a call to execute/executeQuery or executeBatch failed.protected StringreportQuery(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 StringreportSlowQuery(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 thresholdvoidreset(ConnectionPool parent, PooledConnection con) no-op for this interceptor. no state is stored.voidsetLogFailed(boolean logFailed) voidsetLogSlow(boolean logSlow) voidsetMaxQueries(int maxQueries) voidsetProperties(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.AbstractQueryReportcreateStatement, getThreshold, setThresholdMethods inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptorgetConstructor, invoke, isExecute, isStatement, processMethods inherited from class org.apache.tomcat.jdbc.pool.JdbcInterceptorcompare, compare, disconnected, getNext, getProperties, isUseEquals, setNext, setUseEquals
- 
Field Details- 
perPoolStatsprotected static final ConcurrentHashMap<String,ConcurrentHashMap<String, perPoolStatsSlowQueryReport.QueryStats>> we will be keeping track of query stats on a per pool basis
- 
queriesthe queries that are used for this interceptor.
- 
maxQueriesprotected int maxQueriesMaximum number of queries we will be storing
- 
logSlowprotected boolean logSlowFlag to enable disable logging of slow queries
- 
logFailedprotected boolean logFailedFlag to enable disable logging of failed queries
- 
queryStatsComparatorSort QueryStats by last invocation time
 
- 
- 
Constructor Details- 
SlowQueryReportpublic SlowQueryReport()Creates a slow query report interceptor
 
- 
- 
Method Details- 
getPoolStatsReturns 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
 
- 
setMaxQueriespublic void setMaxQueries(int maxQueries) 
- 
reportFailedQueryprotected String reportFailedQuery(String query, Object[] args, String name, long start, Throwable t) Description copied from class:AbstractQueryReportInvoked when a query execution, a call to execute/executeQuery or executeBatch failed.- Overrides:
- reportFailedQueryin 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
 
- 
reportQueryDescription copied from class:AbstractQueryReportInvoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was within the timing threshold- Overrides:
- reportQueryin 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
 
- 
reportSlowQueryDescription copied from class:AbstractQueryReportInvoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was exceeded the timing threshold- Overrides:
- reportSlowQueryin 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
 
- 
closeInvokedpublic void closeInvoked()invoked when the connection receives the close request Not used for now.- Specified by:
- closeInvokedin class- AbstractCreateStatementInterceptor
 
- 
prepareStatementDescription copied from class:AbstractQueryReportInvoked when prepareStatement has been called and completed.- Specified by:
- prepareStatementin class- AbstractQueryReport
- Parameters:
- sql- - the string used to prepare the statement with
- time- - the time it took to invoke prepare
 
- 
prepareCallDescription copied from class:AbstractQueryReportInvoked when prepareCall has been called and completed.- Specified by:
- prepareCallin class- AbstractQueryReport
- Parameters:
- sql- - the string used to prepare the statement with
- time- - the time it took to invoke prepare
 
- 
poolStartedDescription copied from class:JdbcInterceptorThis 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:
- poolStartedin class- JdbcInterceptor
- Parameters:
- pool- - the pool that is being closed.
 
- 
poolClosedDescription copied from class:JdbcInterceptorThis 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:
- poolClosedin class- JdbcInterceptor
- Parameters:
- pool- - the pool that is being closed.
 
- 
getQueryStats
- 
removeOldestSort QueryStats by last invocation time- Parameters:
- queries- The queries map
 
- 
resetDescription copied from class:AbstractCreateStatementInterceptorno-op for this interceptor. no state is stored.- Overrides:
- resetin class- AbstractCreateStatementInterceptor
- Parameters:
- parent- - the connection pool owning the connection
- con- - the pooled connection
 
- 
isLogSlowpublic boolean isLogSlow()
- 
setLogSlowpublic void setLogSlow(boolean logSlow) 
- 
isLogFailedpublic boolean isLogFailed()
- 
setLogFailedpublic void setLogFailed(boolean logFailed) 
- 
setPropertiesDescription copied from class:JdbcInterceptorCalled 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:
- setPropertiesin class- JdbcInterceptor
- Parameters:
- properties- The properties
 
 
-