Class AbstractQueryReport

All Implemented Interfaces:
InvocationHandler
Direct Known Subclasses:
ResetAbandonedTimer, SlowQueryReport

public abstract class AbstractQueryReport extends AbstractCreateStatementInterceptor
Abstract class that wraps statements and intercepts query executions.
  • Field Details

    • threshold

      protected long threshold
      The 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 through reportFailedQuery(String, Object[], String, long, long, Throwable) regardless of this threshold.
  • Constructor Details

    • AbstractQueryReport

      public AbstractQueryReport()
      Constructs a new AbstractQueryReport with the default threshold.
  • Method Details

    • prepareStatement

      protected abstract void prepareStatement(String sql, long time)
      Invoked when prepareStatement has been called and completed.
      Parameters:
      sql - - the string used to prepare the statement with
      time - - the time it took to invoke prepare
    • prepareCall

      protected abstract void prepareCall(String query, long time)
      Invoked when prepareCall has been called and completed.
      Parameters:
      query - - the string used to prepare the statement with
      time - - 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 by AbstractCreateStatementInterceptor.isExecute(Method, boolean), failed.
      Parameters:
      query - the query that was executed and failed
      args - the arguments to the execution
      name - the name of the method used to execute, as recognised by AbstractCreateStatementInterceptor.isExecute(Method, boolean)
      start - the wall clock time the query execution started
      delta - the time the execution took before it failed, measured with the monotonic clock
      t - the exception that happened
      Returns:
      - the SQL that was executed or the string "batch" if it was a batch execution, or null if the invocation carries no SQL string
    • reportQuery

      protected String reportQuery(String query, Object[] args, String name, long start, long delta)
      Invoked when a query execution, a call to an execute method as recognised by AbstractCreateStatementInterceptor.isExecute(Method, boolean), succeeded and was within the timing threshold
      Parameters:
      query - the query that was executed
      args - the arguments to the execution
      name - the name of the method used to execute, as recognised by AbstractCreateStatementInterceptor.isExecute(Method, boolean)
      start - the wall clock time the query execution started
      delta - 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 null if the invocation carries no SQL string
    • reportSlowQuery

      protected String reportSlowQuery(String query, Object[] args, String name, long start, long delta)
      Invoked when a query execution, a call to an execute method as recognised by AbstractCreateStatementInterceptor.isExecute(Method, boolean), succeeded and exceeded the timing threshold
      Parameters:
      query - the query that was executed
      args - the arguments to the execution
      name - the name of the method used to execute, as recognised by AbstractCreateStatementInterceptor.isExecute(Method, boolean)
      start - the wall clock time the query execution started
      delta - 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 null if 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; see setThreshold(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 through reportSlowQuery(String, Object[], String, long, long); one that takes no longer is reported through reportQuery(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:
      createStatement in class AbstractCreateStatementInterceptor
      Parameters:
      proxy - the actual proxy object
      method - the method that was called. It will be one of the methods defined in AbstractCreateStatementInterceptor.STATEMENT_TYPES
      args - the arguments to the method
      statement - the statement that the underlying connection created
      time - elapsed time in milliseconds, measured with the monotonic clock
      Returns:
      a Statement object