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

public Class SlowQueryReport

extends AbstractQueryReport
Class Inheritance
Known Direct Subclasses
org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx
Imports
java.text.SimpleDateFormat, java.util.ArrayList, .Collections, .Comparator, .Locale, .Map, .TimeZone, java.util.concurrent.ConcurrentHashMap, javax.management.openmbean.CompositeDataSupport, .CompositeType, .OpenDataException, .OpenType, .SimpleType, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.jdbc.pool.ConnectionPool, .PoolProperties.InterceptorProperty, .PooledConnection

Slow query report interceptor. Tracks timing of query executions.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
SlowQueryReport.QueryStatsComparator

Compare QueryStats by their lastInvocation value.

Field Summary

Modifier and TypeField and Description
private static final Log
protected boolean
logFailed

Flag to enable disable logging of failed queries

protected boolean
logSlow

Flag to enable disable logging of slow queries

protected int
maxQueries

Maximum number of queries we will be storing

protected static final ConcurrentHashMap<String, ConcurrentHashMap<String, SlowQueryReport.QueryStats>>
perPoolStats

we will be keeping track of query stats on a per pool basis

protected volatile ConcurrentHashMap<String, SlowQueryReport.QueryStats>
queries

the queries that are used for this interceptor.

protected final Comparator<SlowQueryReport.QueryStats>
queryStatsComparator

Sort QueryStats by last invocation time

Inherited from org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport:
threshold

Constructor Summary

AccessConstructor and Description
public
SlowQueryReport()

Creates a slow query report interceptor

Method Summary

Modifier and TypeMethod and Description
public void
closeInvoked()

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

invoked when the connection receives the close request Not used for now.

public static ConcurrentHashMap<String, SlowQueryReport.QueryStats>

Returns:

a hash map containing statistics for 0 to maxQueries
getPoolStats
(String
- the name of the pool we want to retrieve stats for
poolname
)

Returns the query stats for a given pool

protected SlowQueryReport.QueryStats
public boolean
public boolean
public void
poolClosed(ConnectionPool
- the pool that is being closed.
pool
)

Overrides org.apache.tomcat.jdbc.pool.JdbcInterceptor.poolClosed.

This method is invoked by a connection pool when the pool is closed.

public void
poolStarted(ConnectionPool
- the pool that is being closed.
pool
)

Overrides org.apache.tomcat.jdbc.pool.JdbcInterceptor.poolStarted.

This method is invoked by a connection pool when the pool is first started up, usually when the first connection is requested.

public void
prepareCall(String
- the string used to prepare the statement with
sql
,
long
- the time it took to invoke prepare
time
)

Implements abstract org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.prepareCall.

Invoked when prepareCall has been called and completed.

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

Implements abstract org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.prepareStatement.

Invoked when prepareStatement has been called and completed.

protected void
removeOldest(ConcurrentHashMap<String, SlowQueryReport.QueryStats>
The queries map
queries
)

Sort QueryStats by last invocation time

protected String
reportFailedQuery(String
the query that was executed and failed
query
,
Object[]
the arguments to the execution
args
,
String name, long
the time the query execution started
start
,
Throwable
the exception that happened
t
)

Overrides org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.reportFailedQuery.

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

protected String
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
)

Overrides org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.reportQuery.

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

protected String
reportSlowQuery(String
the query that was executed and failed
query
,
Object[]
the arguments to the execution
args
,
String name, long
the time the query execution started
start
,
long
the time the execution took
delta
)

Overrides org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.reportSlowQuery.

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

public void
reset(ConnectionPool
- the connection pool owning the connection
parent
,
PooledConnection
- the pooled connection
con
)

Overrides org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.reset.

no-op for this interceptor.

public void
setLogFailed(boolean logFailed)

public void
setLogSlow(boolean logSlow)

public void
setMaxQueries(int maxQueries)

public void
setProperties(Map<String, PoolProperties.InterceptorProperty>
The properties
properties
)

Overrides org.apache.tomcat.jdbc.pool.JdbcInterceptor.setProperties.

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 properties

Inherited from org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport:
createStatementgetThresholdsetThreshold

Field Detail

logback to summary
private static final Log log

Hides org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.log.

logFailedback to summary
protected boolean logFailed

Flag to enable disable logging of failed queries

logSlowback to summary
protected boolean logSlow

Flag to enable disable logging of slow queries

maxQueriesback to summary
protected int maxQueries

Maximum number of queries we will be storing

perPoolStatsback to summary
protected static final ConcurrentHashMap<String, ConcurrentHashMap<String, SlowQueryReport.QueryStats>> perPoolStats

we will be keeping track of query stats on a per pool basis

queriesback to summary
protected volatile ConcurrentHashMap<String, SlowQueryReport.QueryStats> queries

the queries that are used for this interceptor.

queryStatsComparatorback to summary
protected final Comparator<SlowQueryReport.QueryStats> queryStatsComparator

Sort QueryStats by last invocation time

Constructor Detail

SlowQueryReportback to summary
public SlowQueryReport()

Creates a slow query report interceptor

Method Detail

closeInvokedback to summary
public void closeInvoked()

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

invoked when the connection receives the close request Not used for now.

Annotations
@Override
getPoolStatsback to summary
public static ConcurrentHashMap<String, SlowQueryReport.QueryStats> getPoolStats(String poolname)

Returns the query stats for a given pool

Parameters
poolname:String

- the name of the pool we want to retrieve stats for

Returns:ConcurrentHashMap<String, SlowQueryReport.QueryStats>

a hash map containing statistics for 0 to maxQueries

getQueryStatsback to summary
protected SlowQueryReport.QueryStats getQueryStats(String sql)
isLogFailedback to summary
public boolean isLogFailed()
isLogSlowback to summary
public boolean isLogSlow()
poolClosedback to summary
public void poolClosed(ConnectionPool pool)

Overrides org.apache.tomcat.jdbc.pool.JdbcInterceptor.poolClosed.

Doc from org.apache.tomcat.jdbc.pool.JdbcInterceptor.poolClosed.

This 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.

Parameters
pool:ConnectionPool

- the pool that is being closed.

Annotations
@Override
poolStartedback to summary
public void poolStarted(ConnectionPool pool)

Overrides org.apache.tomcat.jdbc.pool.JdbcInterceptor.poolStarted.

Doc from org.apache.tomcat.jdbc.pool.JdbcInterceptor.poolStarted.

This 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.

Parameters
pool:ConnectionPool

- the pool that is being closed.

Annotations
@Override
prepareCallback to summary
public void prepareCall(String sql, long time)

Implements abstract org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.prepareCall.

Doc from org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.prepareCall.

Invoked when prepareCall 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

Annotations
@Override
prepareStatementback to summary
public void prepareStatement(String sql, long time)

Implements abstract org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.prepareStatement.

Doc from org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.prepareStatement.

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

Annotations
@Override
removeOldestback to summary
protected void removeOldest(ConcurrentHashMap<String, SlowQueryReport.QueryStats> queries)

Sort QueryStats by last invocation time

Parameters
queries:ConcurrentHashMap<String, SlowQueryReport.QueryStats>

The queries map

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

Overrides org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.reportFailedQuery.

Doc from org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.reportFailedQuery.

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

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

Overrides org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.reportQuery.

Doc from org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.reportQuery.

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

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

Overrides org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.reportSlowQuery.

Doc from org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport.reportSlowQuery.

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

Annotations
@Override
resetback to summary
public void reset(ConnectionPool parent, PooledConnection con)

Overrides org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.reset.

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

no-op for this interceptor. no state is stored.

Parameters
parent:ConnectionPool

Doc from org.apache.tomcat.jdbc.pool.JdbcInterceptor.reset.

- the connection pool owning the connection

con:PooledConnection

Doc from org.apache.tomcat.jdbc.pool.JdbcInterceptor.reset.

- the pooled connection

Annotations
@Override
setLogFailedback to summary
public void setLogFailed(boolean logFailed)
setLogSlowback to summary
public void setLogSlow(boolean logSlow)
setMaxQueriesback to summary
public void setMaxQueries(int maxQueries)
setPropertiesback to summary
public void setProperties(Map<String, PoolProperties.InterceptorProperty> properties)

Overrides org.apache.tomcat.jdbc.pool.JdbcInterceptor.setProperties.

Doc from org.apache.tomcat.jdbc.pool.JdbcInterceptor.setProperties.

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 properties

Parameters
properties:Map<String, PoolProperties.InterceptorProperty>

The properties

Annotations
@Override
org.apache.tomcat.jdbc.pool.interceptor back to summary

public Class SlowQueryReport.QueryStats

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport.QueryStats

Field Summary

Modifier and TypeField and Description
private volatile long
pack-priv static final String[]
pack-priv static final String[]
pack-priv static final OpenType<?>[]
private volatile long
private volatile long
private volatile long
private volatile long
private volatile long
private volatile int
private volatile int
private volatile long
private final String
private volatile long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
add(long invocationTime, long now)

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public synchronized void
failure(long invocationTime, long now)

public CompositeDataSupport
public static String[]
public static String[]
public static OpenType<?>[]
public long
public long
public long
public long
public int
public String
public long
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
public synchronized void
prepare(long invocationTime)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

failuresback to summary
private volatile long failures
FIELD_DESCRIPTIONSback to summary
pack-priv static final String[] FIELD_DESCRIPTIONS
FIELD_NAMESback to summary
pack-priv static final String[] FIELD_NAMES
FIELD_TYPESback to summary
pack-priv static final OpenType<?>[] FIELD_TYPES
lastInvocationback to summary
private volatile long lastInvocation
maxInvocationDateback to summary
private volatile long maxInvocationDate
maxInvocationTimeback to summary
private volatile long maxInvocationTime
minInvocationDateback to summary
private volatile long minInvocationDate
minInvocationTimeback to summary
private volatile long minInvocationTime
nrOfInvocationsback to summary
private volatile int nrOfInvocations
prepareCountback to summary
private volatile int prepareCount
prepareTimeback to summary
private volatile long prepareTime
queryback to summary
private final String query
totalInvocationTimeback to summary
private volatile long totalInvocationTime

Constructor Detail

QueryStatsback to summary
public QueryStats(String query)

Method Detail

addback to summary
public synchronized void add(long invocationTime, long now)
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
failureback to summary
public synchronized void failure(long invocationTime, long now)
getCompositeDataback to summary
public CompositeDataSupport getCompositeData(final CompositeType type) throws OpenDataException
getFieldDescriptionsback to summary
public static String[] getFieldDescriptions()
getFieldNamesback to summary
public static String[] getFieldNames()
getFieldTypesback to summary
public static OpenType<?>[] getFieldTypes()
getMaxInvocationDateback to summary
public long getMaxInvocationDate()
getMaxInvocationTimeback to summary
public long getMaxInvocationTime()
getMinInvocationDateback to summary
public long getMinInvocationDate()
getMinInvocationTimeback to summary
public long getMinInvocationTime()
getNrOfInvocationsback to summary
public int getNrOfInvocations()
getQueryback to summary
public String getQuery()
getTotalInvocationTimeback to summary
public long getTotalInvocationTime()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isOlderThanback to summary
public boolean isOlderThan(SlowQueryReport.QueryStats other)
prepareback to summary
public synchronized void prepare(long invocationTime)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.apache.tomcat.jdbc.pool.interceptor back to summary

public Class SlowQueryReport.QueryStatsComparator

extends Object
implements Comparator<SlowQueryReport.QueryStats>
Class Inheritance
  • java.lang.Object
  • org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport.QueryStatsComparator
All Implemented Interfaces
java.util.Comparator

Compare QueryStats by their lastInvocation value. QueryStats that have never been updated, have a lastInvocation value of 0 which should be handled as the newest possible invocation.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
compare(SlowQueryReport.QueryStats
the first object to be compared.
stats1
,
SlowQueryReport.QueryStats
the second object to be compared.
stats2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

private static long
handleZero(long value)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

QueryStatsComparatorback to summary
public QueryStatsComparator()

Method Detail

compareback to summary
public int compare(SlowQueryReport.QueryStats stats1, SlowQueryReport.QueryStats stats2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
stats1:SlowQueryReport.QueryStats

the first object to be compared.

stats2:SlowQueryReport.QueryStats

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Annotations
@Override
handleZeroback to summary
private static long handleZero(long value)