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:
InvocationHandler
- Direct Known Subclasses:
ResetAbandonedTimer, SlowQueryReport
Abstract class that wraps statements and intercepts query executions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classClass to measure query execute time -
Field Summary
FieldsFields inherited from class 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_TYPESFields inherited from class JdbcInterceptor
ABORT_VAL, CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VAL -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newAbstractQueryReportwith the default threshold. -
Method Summary
Modifier and TypeMethodDescriptioncreateStatement(Object proxy, Method method, Object[] args, 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.longreturns the query measure threshold.protected abstract voidprepareCall(String query, long time) Invoked when prepareCall has been called and completed.protected abstract voidprepareStatement(String sql, long time) Invoked when prepareStatement has been called and completed.protected StringreportFailedQuery(String query, Object[] args, String name, long start, long delta, Throwable t) Invoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), failed.protected StringreportQuery(String query, Object[] args, 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 StringreportSlowQuery(String query, Object[] args, 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 AbstractCreateStatementInterceptor
closeInvoked, elapsedMillis, getConstructor, invoke, isExecute, isStatement, process, resetMethods inherited from class JdbcInterceptor
compare, compare, disconnected, getNext, getProperties, isUseEquals, poolClosed, poolStarted, setNext, setProperties, setUseEquals, unregisterMBean
-
Field Details
-
threshold
protected long thresholdThe 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(String, Object[], String, long, long, Throwable)regardless of this threshold.
-
-
Constructor Details
-
AbstractQueryReport
public AbstractQueryReport()Constructs a newAbstractQueryReportwith the default threshold.
-
-
Method Details
-
prepareStatement
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
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 String reportFailedQuery(String query, Object[] args, String name, long start, long delta, 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
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
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(String, Object[], String, long, long); one that takes no longer is reported throughreportQuery(String, Object[], 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 Object createStatement(Object proxy, Method method, Object[] args, 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
-