Top Description Inners Fields Constructors Methods
org.apache.tomcat.jdbc.pool.interceptor

public abstract Class AbstractQueryReport

extends AbstractCreateStatementInterceptor
Class Inheritance
Known Direct Subclasses
org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer, org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport
Imports
java.lang.reflect.Constructor, .InvocationHandler, .InvocationTargetException, .Method, java.sql.CallableStatement, .PreparedStatement, .SQLException, .Statement, org.apache.juli.logging.Log, .LogFactory

Abstract class that wraps statements and intercepts query executions.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
AbstractQueryReport.StatementProxy

Class to measure query execute time

Field Summary

Modifier and TypeField and Description
private static final Log
protected long
threshold

The threshold in milliseconds.

Inherited from org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor:
constructorsCREATE_STATEMENTCREATE_STATEMENT_IDXEXECUTEEXECUTE_BATCHEXECUTE_QUERYEXECUTE_TYPESEXECUTE_UPDATEPREPARE_CALLPREPARE_CALL_IDXPREPARE_STATEMENTPREPARE_STATEMENT_IDXSTATEMENT_TYPE_COUNTSTATEMENT_TYPES

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
createStatement(Object
the actual proxy object
proxy
,
Method
the method that was called. It will be one of the methods defined in STATEMENT_TYPES
method
,
Object[]
the arguments to the method
args
,
Object
the statement that the underlying connection created
statement
,
long
Elapsed time
time
)

Implements abstract org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.createStatement.

Creates a statement interceptor to monitor query response times

public long

Returns:

the threshold in milliseconds
getThreshold
()

returns the query measure threshold.

protected abstract void
prepareCall(String
- the string used to prepare the statement with
query
,
long
- the time it took to invoke prepare
time
)

Invoked when prepareCall has been called and completed.

protected abstract void
prepareStatement(String
- the string used to prepare the statement with
sql
,
long
- the time it took to invoke prepare
time
)

Invoked when prepareStatement has been called and completed.

protected String

Returns:

- the SQL that was executed or the string "batch" if it was a batch execution
reportFailedQuery
(String
the query that was executed and failed
query
,
Object[]
the arguments to the execution
args
,
final String name, long
the time the query execution started
start
,
Throwable
the exception that happened
t
)

Invoked when a query execution, a call to execute/executeQuery or executeBatch failed.

protected String

Returns:

- the SQL that was executed or the string "batch" if it was a batch execution
reportQuery
(String
the query that was executed and failed
query
,
Object[]
the arguments to the execution
args
,
final String name, long
the time the query execution started
start
,
long
the time the execution took
delta
)

Invoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was within the timing threshold

protected String

Returns:

- the SQL that was executed or the string "batch" if it was a batch execution
reportSlowQuery
(String
the query that was executed and failed
query
,
Object[]
the arguments to the execution
args
,
final String name, long
the time the query execution started
start
,
long
the time the execution took
delta
)

Invoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was exceeded the timing threshold

public void
setThreshold(long
set to -1 to record every query. Value is in milliseconds.
threshold
)

Sets the query measurement threshold.

Inherited from org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor:
closeInvokedgetConstructorinvokeisExecuteisStatementprocessreset

Field Detail

logback to summary
private static final Log log
thresholdback to summary
protected long threshold

The threshold in milliseconds. If the query is faster than this, we don't measure it

Constructor Detail

AbstractQueryReportback to summary
public AbstractQueryReport()

Method Detail

createStatementback to summary
public Object createStatement(Object proxy, Method method, Object[] args, Object statement, long time)

Implements abstract org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.createStatement.

Creates a statement interceptor to monitor query response times

Parameters
proxy:Object

Doc from org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.createStatement.

the actual proxy object

method:Method

Doc from org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.createStatement.

the method that was called. It will be one of the methods defined in STATEMENT_TYPES

args:Object[]

Doc from org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.createStatement.

the arguments to the method

statement:Object

Doc from org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.createStatement.

the statement that the underlying connection created

time:long

Doc from org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.createStatement.

Elapsed time

Returns:Object

Doc from org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.createStatement.

a java.sql.Statement object

Annotations
@Override
getThresholdback to summary
public long getThreshold()

returns the query measure threshold. This value is in milliseconds. If the query is faster than this threshold than it won't be accounted for

Returns:long

the threshold in milliseconds

prepareCallback to summary
protected abstract void prepareCall(String query, long time)

Invoked when prepareCall has been called and completed.

Parameters
query:String

- the string used to prepare the statement with

time:long

- the time it took to invoke prepare

prepareStatementback to summary
protected abstract void prepareStatement(String sql, long time)

Invoked when prepareStatement has been called and completed.

Parameters
sql:String

- the string used to prepare the statement with

time:long

- the time it took to invoke prepare

reportFailedQueryback to summary
protected String reportFailedQuery(String query, Object[] args, final String name, long start, Throwable t)

Invoked when a query execution, a call to execute/executeQuery or executeBatch failed.

Parameters
query:String

the query that was executed and failed

args:Object[]

the arguments to the execution

name:String

the name of the method used to execute AbstractCreateStatementInterceptor#isExecute(Method, boolean)

start:long

the time the query execution started

t:Throwable

the exception that happened

Returns:String

- the SQL that was executed or the string "batch" if it was a batch execution

reportQueryback to summary
protected String reportQuery(String query, Object[] args, final String name, long start, long delta)

Invoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was within the timing threshold

Parameters
query:String

the query that was executed and failed

args:Object[]

the arguments to the execution

name:String

the name of the method used to execute AbstractCreateStatementInterceptor#isExecute(Method, boolean)

start:long

the time the query execution started

delta:long

the time the execution took

Returns:String

- the SQL that was executed or the string "batch" if it was a batch execution

reportSlowQueryback to summary
protected String reportSlowQuery(String query, Object[] args, final String name, long start, long delta)

Invoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was exceeded the timing threshold

Parameters
query:String

the query that was executed and failed

args:Object[]

the arguments to the execution

name:String

the name of the method used to execute AbstractCreateStatementInterceptor#isExecute(Method, boolean)

start:long

the time the query execution started

delta:long

the time the execution took

Returns:String

- the SQL that was executed or the string "batch" if it was a batch execution

setThresholdback to summary
public void setThreshold(long threshold)

Sets the query measurement threshold. The value is in milliseconds. If the query goes faster than this threshold it will not be recorded.

Parameters
threshold:long

set to -1 to record every query. Value is in milliseconds.

org.apache.tomcat.jdbc.pool.interceptor back to summary

protected Class AbstractQueryReport.StatementProxy

extends Object
implements InvocationHandler
Class Inheritance
  • java.lang.Object
  • org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.StatementProxy
All Implemented Interfaces
java.lang.reflect.InvocationHandler

Class to measure query execute time

Field Summary

Modifier and TypeField and Description
protected boolean
protected Object
protected final String

Constructor Summary

AccessConstructor and Description
public
StatementProxy(Object parent, String query)

Method Summary

Modifier and TypeMethod and Description
public Object
invoke(Object
the proxy instance that the method was invoked on
proxy
,
Method
the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
method
,
Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
args
)

Implements java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closedback to summary
protected boolean closed
delegateback to summary
protected Object delegate
queryback to summary
protected final String query

Constructor Detail

StatementProxyback to summary
public StatementProxy(Object parent, String query)

Method Detail

invokeback to summary
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable

Implements java.lang.reflect.InvocationHandler.invoke.

Doc from java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.

Parameters
proxy:Object

the proxy instance that the method was invoked on

method:Method

the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.

args:Object[]

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.

Returns:Object

the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.

Annotations
@Override
Exceptions
Throwable:
the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.