Class AbstractQueryReport
- java.lang.Object
-
- org.apache.tomcat.jdbc.pool.JdbcInterceptor
-
- org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor
-
- org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler
- Direct Known Subclasses:
ResetAbandonedTimer,SlowQueryReport
public abstract class AbstractQueryReport extends AbstractCreateStatementInterceptor
Abstract class that wraps statements and intercepts query executions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAbstractQueryReport.StatementProxyClass to measure query execute time
-
Field Summary
Fields Modifier and Type Field Description protected longthresholdThe threshold in milliseconds.-
Fields inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor
CREATE_STATEMENT, CREATE_STATEMENT_IDX, EXECUTE, EXECUTE_BATCH, EXECUTE_LARGE_BATCH, EXECUTE_LARGE_UPDATE, 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
ABORT_VAL, CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VAL
-
-
Constructor Summary
Constructors Constructor Description AbstractQueryReport()Constructs a newAbstractQueryReportwith the default threshold.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectcreateStatement(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args, java.lang.Object statement, long time)Wraps a newly created statement in a proxy that measures its executions, so they can be reported as measured, slow or failed queries.longgetThreshold()returns the query measure threshold.protected abstract voidprepareCall(java.lang.String query, long time)Invoked when prepareCall has been called and completed.protected abstract voidprepareStatement(java.lang.String sql, long time)Invoked when prepareStatement has been called and completed.protected java.lang.StringreportFailedQuery(java.lang.String query, java.lang.Object[] args, java.lang.String name, long start, long delta, java.lang.Throwable t)Invoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), failed.protected java.lang.StringreportQuery(java.lang.String query, java.lang.Object[] args, java.lang.String name, long start, long delta)Invoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), succeeded and was within the timing thresholdprotected java.lang.StringreportSlowQuery(java.lang.String query, java.lang.Object[] args, java.lang.String name, long start, long delta)Invoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), succeeded and exceeded the timing thresholdvoidsetThreshold(long threshold)Sets the query measurement threshold.-
Methods inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor
closeInvoked, elapsedMillis, getConstructor, invoke, isExecute, isStatement, process, reset
-
Methods inherited from class org.apache.tomcat.jdbc.pool.JdbcInterceptor
compare, compare, disconnected, getNext, getProperties, isUseEquals, poolClosed, poolStarted, setNext, setProperties, setUseEquals, unregisterMBean
-
-
-
-
Field Detail
-
threshold
protected long threshold
The threshold in milliseconds. A successful execution that takes longer than this is reported as a slow query; one that takes no longer is reported as a measured query. A negative threshold keeps every execution out of the slow path, so every successful execution is reported as measured. Failed executions are reported throughreportFailedQuery(java.lang.String, java.lang.Object[], java.lang.String, long, long, java.lang.Throwable)regardless of this threshold.
-
-
Method Detail
-
prepareStatement
protected abstract void prepareStatement(java.lang.String sql, long time)Invoked when prepareStatement has been called and completed.- Parameters:
sql- - the string used to prepare the statement withtime- - the time it took to invoke prepare
-
prepareCall
protected abstract void prepareCall(java.lang.String query, long time)Invoked when prepareCall has been called and completed.- Parameters:
query- - the string used to prepare the statement withtime- - the time it took to invoke prepare
-
reportFailedQuery
protected java.lang.String reportFailedQuery(java.lang.String query, java.lang.Object[] args, java.lang.String name, long start, long delta, java.lang.Throwable t)Invoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), failed.- Parameters:
query- the query that was executed and failedargs- the arguments to the executionname- the name of the method used to execute, as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean)start- the wall clock time the query execution starteddelta- the time the execution took before it failed, measured with the monotonic clockt- the exception that happened- Returns:
- - the SQL that was executed or the string "batch" if it was a batch execution, or
nullif the invocation carries no SQL string
-
reportQuery
protected java.lang.String reportQuery(java.lang.String query, java.lang.Object[] args, java.lang.String name, long start, long delta)Invoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), succeeded and was within the timing threshold- Parameters:
query- the query that was executedargs- the arguments to the executionname- the name of the method used to execute, as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean)start- the wall clock time the query execution starteddelta- the time the execution took, measured with the monotonic clock- Returns:
- - the SQL that was executed or the string "batch" if it was a batch execution, or
nullif the invocation carries no SQL string
-
reportSlowQuery
protected java.lang.String reportSlowQuery(java.lang.String query, java.lang.Object[] args, java.lang.String name, long start, long delta)Invoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), succeeded and exceeded the timing threshold- Parameters:
query- the query that was executedargs- the arguments to the executionname- the name of the method used to execute, as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean)start- the wall clock time the query execution starteddelta- the time the execution took, measured with the monotonic clock- Returns:
- - the SQL that was executed or the string "batch" if it was a batch execution, or
nullif the invocation carries no SQL string
-
getThreshold
public long getThreshold()
returns the query measure threshold. This value is in milliseconds. A successful execution that takes longer than this threshold is reported as a slow query; seesetThreshold(long)for the meaning of a negative value and for the handling of failed executions.- Returns:
- the threshold in milliseconds
-
setThreshold
public void setThreshold(long threshold)
Sets the query measurement threshold. The value is in milliseconds. A successful execution that takes longer than this threshold is reported throughreportSlowQuery(java.lang.String, java.lang.Object[], java.lang.String, long, long); one that takes no longer is reported throughreportQuery(java.lang.String, java.lang.Object[], java.lang.String, long, long). A negative threshold records every query: every execution is measured and reported as measured, and no execution is ever reported as slow.- Parameters:
threshold- the threshold in milliseconds; set to a negative value (conventionally -1) to record every query as measured without reporting any of them as slow
-
createStatement
public java.lang.Object createStatement(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args, java.lang.Object statement, long time)Wraps a newly created statement in a proxy that measures its executions, so they can be reported as measured, slow or failed queries.- Specified by:
createStatementin classAbstractCreateStatementInterceptor- Parameters:
proxy- the actual proxy objectmethod- the method that was called. It will be one of the methods defined inAbstractCreateStatementInterceptor.STATEMENT_TYPESargs- the arguments to the methodstatement- the statement that the underlying connection createdtime- elapsed time in milliseconds, measured with the monotonic clock- Returns:
- a
Statementobject
-
-