Class StatementDecoratorInterceptor

  • All Implemented Interfaces:
    java.lang.reflect.InvocationHandler
    Direct Known Subclasses:
    StatementCache

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

      • EXECUTE_QUERY

        protected static final java.lang.String EXECUTE_QUERY
        Method name for executeQuery.
        See Also:
        Constant Field Values
      • GET_GENERATED_KEYS

        protected static final java.lang.String GET_GENERATED_KEYS
        Method name for getGeneratedKeys.
        See Also:
        Constant Field Values
      • GET_RESULTSET

        protected static final java.lang.String GET_RESULTSET
        Method name for getResultSet.
        See Also:
        Constant Field Values
      • RESULTSET_TYPES

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

        protected static volatile java.lang.reflect.Constructor<?> resultSetConstructor
        the constructor to create the resultSet proxies
    • Constructor Detail

      • StatementDecoratorInterceptor

        public StatementDecoratorInterceptor()
        Default constructor.
    • Method Detail

      • getResultSetConstructor

        protected java.lang.reflect.Constructor<?> getResultSetConstructor()
                                                                    throws java.lang.NoSuchMethodException
        Gets the constructor for creating ResultSet proxies.
        Returns:
        the ResultSet proxy constructor
        Throws:
        java.lang.NoSuchMethodException - if the constructor is not found
      • createStatement

        public java.lang.Object createStatement​(java.lang.Object proxy,
                                                java.lang.reflect.Method method,
                                                java.lang.Object[] args,
                                                java.lang.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 java.lang.Object createDecorator​(java.lang.Object proxy,
                                                   java.lang.reflect.Method method,
                                                   java.lang.Object[] args,
                                                   java.lang.Object statement,
                                                   java.lang.reflect.Constructor<?> constructor,
                                                   java.lang.String sql)
                                            throws java.lang.InstantiationException,
                                                   java.lang.IllegalAccessException,
                                                   java.lang.reflect.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:
        java.lang.InstantiationException - Couldn't instantiate object
        java.lang.IllegalAccessException - Inaccessible constructor
        java.lang.reflect.InvocationTargetException - Exception thrown from constructor
      • isExecuteQuery

        protected boolean isExecuteQuery​(java.lang.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​(java.lang.reflect.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​(java.lang.reflect.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