Class SlowQueryReport.QueryStats
- java.lang.Object
-
- org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport.QueryStats
-
- Enclosing class:
- SlowQueryReport
public static class SlowQueryReport.QueryStats extends java.lang.ObjectHolds timing and invocation statistics for a single SQL query.
-
-
Constructor Summary
Constructors Constructor Description QueryStats(java.lang.String query)Creates a new QueryStats instance for the given SQL query.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(long invocationTime, long now)Records a successful query invocation, updating min/max/total timing statistics.booleanequals(java.lang.Object other)voidfailure(long invocationTime, long now)Records a failed query invocation, updating timing statistics and failure count.javax.management.openmbean.CompositeDataSupportgetCompositeData(javax.management.openmbean.CompositeType type)Returns the query statistics as JMX CompositeData.static java.lang.String[]getFieldDescriptions()Returns the descriptions of the fields in the composite data representation.static java.lang.String[]getFieldNames()Returns the names of the fields in the composite data representation.static javax.management.openmbean.OpenType<?>[]getFieldTypes()Returns the JMX OpenType of each field in the composite data representation.longgetMaxInvocationDate()Returns the timestamp when the longest query execution occurred.longgetMaxInvocationTime()Returns the longest time this query took to execute.longgetMinInvocationDate()Returns the timestamp when the shortest query execution occurred.longgetMinInvocationTime()Returns the shortest time this query took to execute.intgetNrOfInvocations()Returns the total number of times this query has been invoked.java.lang.StringgetQuery()Returns the SQL query string for these statistics.longgetTotalInvocationTime()Returns the total time spent executing this query across all invocations.inthashCode()booleanisOlderThan(SlowQueryReport.QueryStats other)Returns whether this query is the one eviction would take before the given one, that is, whether it was last invoked or prepared earlier.voidprepare(long invocationTime)Records the time taken to prepare this query.java.lang.StringtoString()
-
-
-
Method Detail
-
getFieldNames
public static java.lang.String[] getFieldNames()
Returns the names of the fields in the composite data representation.- Returns:
- the field names
-
getFieldDescriptions
public static java.lang.String[] getFieldDescriptions()
Returns the descriptions of the fields in the composite data representation.- Returns:
- the field descriptions
-
getFieldTypes
public static javax.management.openmbean.OpenType<?>[] getFieldTypes()
Returns the JMX OpenType of each field in the composite data representation.- Returns:
- the field types
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getCompositeData
public javax.management.openmbean.CompositeDataSupport getCompositeData(javax.management.openmbean.CompositeType type) throws javax.management.openmbean.OpenDataExceptionReturns the query statistics as JMX CompositeData.- Parameters:
type- the composite type definition- Returns:
- the composite data representation of this query's statistics
- Throws:
javax.management.openmbean.OpenDataException- if the data cannot be converted
-
prepare
public void prepare(long invocationTime)
Records the time taken to prepare this query. Preparation counts as activity on the entry, so the last invocation time that orders the statistics for eviction is updated as well: a statement that is prepared but never executed must age like any other query instead of occupying a statistics slot for ever.- Parameters:
invocationTime- the time in milliseconds to prepare the query
-
add
public void add(long invocationTime, long now)Records a successful query invocation, updating min/max/total timing statistics.- Parameters:
invocationTime- the time in milliseconds the query tooknow- the current timestamp in milliseconds
-
failure
public void failure(long invocationTime, long now)Records a failed query invocation, updating timing statistics and failure count.- Parameters:
invocationTime- the time in milliseconds the query took before failingnow- the current timestamp in milliseconds
-
getQuery
public java.lang.String getQuery()
Returns the SQL query string for these statistics.- Returns:
- the SQL query string
-
getNrOfInvocations
public int getNrOfInvocations()
Returns the total number of times this query has been invoked.- Returns:
- the number of invocations
-
getMaxInvocationTime
public long getMaxInvocationTime()
Returns the longest time this query took to execute. Until an execution has been booked the value isLong.MIN_VALUE; the published views report0in that state.- Returns:
- the maximum invocation time in milliseconds, or
Long.MIN_VALUEwhile no execution has been booked
-
getMaxInvocationDate
public long getMaxInvocationDate()
Returns the timestamp when the longest query execution occurred. Until an execution has been booked the value is0, because no date has been recorded.- Returns:
- the timestamp in milliseconds of the maximum invocation, or
0while no execution has been booked
-
getMinInvocationTime
public long getMinInvocationTime()
Returns the shortest time this query took to execute. Until an execution has been booked the value isLong.MAX_VALUE; the published views report0in that state.- Returns:
- the minimum invocation time in milliseconds, or
Long.MAX_VALUEwhile no execution has been booked
-
getMinInvocationDate
public long getMinInvocationDate()
Returns the timestamp when the shortest query execution occurred. Until an execution has been booked the value is0, because no date has been recorded.- Returns:
- the timestamp in milliseconds of the minimum invocation, or
0while no execution has been booked
-
getTotalInvocationTime
public long getTotalInvocationTime()
Returns the total time spent executing this query across all invocations.- Returns:
- the total invocation time in milliseconds
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
isOlderThan
public boolean isOlderThan(SlowQueryReport.QueryStats other)
Returns whether this query is the one eviction would take before the given one, that is, whether it was last invoked or prepared earlier. An entry that has never been invoked or prepared is the newest of all by that order rather than the oldest, and answersfalsehere, because the comparison is the very one the eviction of the statistics map makes.- Parameters:
other- the other query statistics to compare against- Returns:
trueif this query's last invocation is older
-
-