Class StatementDecoratorInterceptor

All Implemented Interfaces:
InvocationHandler
Direct Known Subclasses:
StatementCache

public class StatementDecoratorInterceptor extends AbstractCreateStatementInterceptor
Implementation of JdbcInterceptor that proxies resultSets and statements.
  • Field Details

    • EXECUTE_QUERY

      protected static final String EXECUTE_QUERY
      Method name for executeQuery.
      See Also:
    • GET_GENERATED_KEYS

      protected static final String GET_GENERATED_KEYS
      Method name for getGeneratedKeys.
      See Also:
    • GET_RESULTSET

      protected static final String GET_RESULTSET
      Method name for getResultSet.
      See Also:
    • RESULTSET_TYPES

      protected static final String[] RESULTSET_TYPES
      Method names that return a ResultSet.
    • resultSetConstructor

      protected static volatile Constructor<?> resultSetConstructor
      the constructor to create the resultSet proxies
  • Constructor Details

    • StatementDecoratorInterceptor

      public StatementDecoratorInterceptor()
      Default constructor.
  • Method Details

    • closeInvoked

      public void closeInvoked()
      Description copied from class: AbstractCreateStatementInterceptor
      Method invoked when the operation Connection.close() is invoked.
      Specified by:
      closeInvoked in class AbstractCreateStatementInterceptor
    • getResultSetConstructor

      protected Constructor<?> getResultSetConstructor() throws NoSuchMethodException
      Gets the constructor for creating ResultSet proxies.
      Returns:
      the ResultSet proxy constructor
      Throws:
      NoSuchMethodException - if the constructor is not found
    • 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:
      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
      Returns:
      a Statement object
    • createDecorator

      protected Object createDecorator(Object proxy, Method method, Object[] args, Object statement, Constructor<?> constructor, String sql) throws InstantiationException, IllegalAccessException, InvocationTargetException
      Creates a proxy for a Statement.
      Parameters:
      proxy - The proxy object on which the method that triggered the creation of the statement was called.
      method - The method that was called on the proxy
      args - The arguments passed as part of the method call to the proxy
      statement - The statement object that is to be proxied
      constructor - The constructor for the desired proxy
      sql - The sql of of the statement
      Returns:
      A new proxy for the Statement
      Throws:
      InstantiationException - Couldn't instantiate object
      IllegalAccessException - Inaccessible constructor
      InvocationTargetException - Exception thrown from constructor
    • isExecuteQuery

      protected boolean isExecuteQuery(String methodName)
      Checks if the given method name is executeQuery.
      Parameters:
      methodName - the method name to check
      Returns:
      true if the method is executeQuery
    • isExecuteQuery

      protected boolean isExecuteQuery(Method method)
      Checks if the given method is executeQuery.
      Parameters:
      method - the method to check
      Returns:
      true if the method is executeQuery
    • isResultSet

      protected boolean isResultSet(Method method, boolean process)
      Checks if the given method returns a ResultSet.
      Parameters:
      method - the method to check
      process - whether processing is already enabled
      Returns:
      true if the method returns a ResultSet