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
constructors, 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_TYPESModifier and TypeFieldDescriptionprotected static final Constructor<?>[]the constructors that are used to create statement proxies.protected static final Stringprotected static final intprotected static final Stringprotected static final Stringprotected static final Stringprotected static final StringStatement.executeLargeUpdate(String)and its overloads, andPreparedStatement.executeLargeUpdate()protected static final Stringprotected static final String[]Array of execute type method namesprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final intprotected static final Stringprotected static final intprotected static final intprotected static final intCount of statement types inAbstractCreateStatementInterceptor.STATEMENT_TYPESprotected static final String[]Array of statement type method namesFields inherited from class JdbcInterceptor
ABORT_VAL, CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VALModifier and TypeFieldDescriptionstatic final StringConnection.abort(java.util.concurrent.Executor)method namestatic final StringConnection.close()method namestatic final Stringstatic final StringPooledConnection.getConnection()method namestatic final Stringstatic final StringConnection.isClosed()method namestatic final StringConnection.isValid(int)method namestatic final StringWrapper.isWrapperFor(Class)method nameprotected Map<String, PoolProperties.InterceptorProperty> Properties for this interceptor.static final StringObject.toString()method namestatic final StringWrapper.unwrap(Class)method name -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newAbstractQueryReportwith the default threshold. -
Method Summary
Modifier and TypeMethodDescriptioncreateStatement(Object proxy, Method method, Object[] args, Object statement, long time) Creates a statement interceptor to monitor query response timeslongreturns 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 was exceeded the timing thresholdvoidsetThreshold(long threshold) Sets the query measurement threshold.Methods inherited from class AbstractCreateStatementInterceptor
closeInvoked, getConstructor, invoke, isExecute, isStatement, process, resetModifier and TypeMethodDescriptionabstract voidMethod invoked when the operationConnection.close()is invoked.protected Constructor<?> getConstructor(int idx, Class<?> clazz) Creates a constructor for a proxy class, if one doesn't already exist.Gets invoked each time an operation onConnectionis invoked.protected booleanReturns true if the method that is being invoked matches one of the execute types.protected booleanisStatement(Method method, boolean process) Returns true if the method that is being invoked matches one of the statement types.protected booleanReturns true if the method that is being invoked matches one of the method names passed invoidreset(ConnectionPool parent, PooledConnection con) no-op for this interceptor. no state is stored.Methods inherited from class JdbcInterceptor
compare, compare, disconnected, getNext, getProperties, isUseEquals, poolClosed, poolStarted, setNext, setProperties, setUseEqualsModifier and TypeMethodDescriptionbooleanCompares a method name (String) to a method (Method)JdbcInterceptor.compare(String,String)Uses reference comparison unless the useEquals property is set to truebooleanPerforms a string comparison, using references unless the useEquals property is set to true.voiddisconnected(ConnectionPool parent, PooledConnection con, boolean finalizing) Called whenConnection.close()is called on the underlying connection.getNext()Returns the next interceptor in the chainReturns the properties configured for this interceptorbooleanTrue if the compare method uses the Object.equals(Object) method, false if comparison is done on a reference level.voidpoolClosed(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.voidsetNext(JdbcInterceptor next) configures the next interceptor in the chainvoidsetProperties(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 propertiesvoidsetUseEquals(boolean useEquals) Set to true if string comparisons (for theJdbcInterceptor.compare(String, Method)andJdbcInterceptor.compare(String, String)methods) should use the Object.equals(Object) method The default is false
-
Field Details
-
threshold
protected long thresholdThe threshold in milliseconds. An 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 execution is reported as measured.
-
-
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 executeAbstractCreateStatementInterceptor.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 executed and failedargs- the arguments to the executionname- the name of the method used to executeAbstractCreateStatementInterceptor.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 was exceeded the timing threshold- 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 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. An execution that takes longer than this threshold is reported as a slow query; seesetThreshold(long)for the meaning of a negative value.- 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) Creates a statement interceptor to monitor query response times- 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- Returns:
- a
Statementobject
-