StatementCache (Apache Tomcat 7.0.96 API Documentation)

org.apache.tomcat.jdbc.pool.interceptor

## Class StatementCache

- java.lang.Object
- - org.apache.tomcat.jdbc.pool.JdbcInterceptor
  - - org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor
    - - org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor
      - - org.apache.tomcat.jdbc.pool.interceptor.StatementCache

- All Implemented Interfaces:
    java.lang.reflect.InvocationHandler

      public class StatementCache
      extends StatementDecoratorInterceptor

  Interceptor that caches `PreparedStatement` and/or `CallableStatement` instances on a connection.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `StatementCache.CachedStatement`

    - ### Nested classes/interfaces inherited from class org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor

      `StatementDecoratorInterceptor.ResultSetProxy, StatementDecoratorInterceptor.StatementProxy<T extends java.sql.Statement>`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static java.lang.String[]` | `ALL_TYPES`
    `protected static java.lang.String[]` | `CALLABLE_TYPE`
    `protected static java.lang.String[]` | `NO_TYPE`
    `protected static java.lang.String[]` | `PREPARED_TYPE`
    `protected static java.lang.String` | `STATEMENT_CACHE_ATTR`

    - ### Fields inherited from class org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor

      `EXECUTE_QUERY, GET_GENERATED_KEYS, GET_RESULTSET, RESULTSET_TYPES, resultSetConstructor`

    - ### Fields inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor

      `constructors, CREATE_STATEMENT, CREATE_STATEMENT_IDX, EXECUTE, EXECUTE_BATCH, EXECUTE_TYPES, EXECUTE_UPDATE, PREPARE_CALL, PREPARE_CALL_IDX, PREPARE_STATEMENT, PREPARE_STATEMENT_IDX, STATEMENT_TYPE_COUNT, STATEMENT_TYPES`

    - ### Fields inherited from class org.apache.tomcat.jdbc.pool.JdbcInterceptor

      `CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VAL`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StatementCache()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `cacheStatement(StatementCache.CachedStatement proxy)`
    `void` | `closeStatement(StatementCache.CachedStatement st)`
    `protected org.apache.tomcat.jdbc.pool.interceptor.StatementCache.CacheKey` | `createCacheKey(java.lang.reflect.Method method, java.lang.Object[] args)`
    `protected org.apache.tomcat.jdbc.pool.interceptor.StatementCache.CacheKey` | `createCacheKey(java.lang.String methodName, java.lang.Object[] args)`
    `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)` Creates a proxy for a Statement.
    `void` | `disconnected(ConnectionPool parent, PooledConnection con, boolean finalizing)` Called when `Connection.close()` is called on the underlying connection.
    `protected java.util.concurrent.ConcurrentHashMap<org.apache.tomcat.jdbc.pool.interceptor.StatementCache.CacheKey,StatementCache.CachedStatement>` | `getCache()`
    `java.util.concurrent.atomic.AtomicInteger` | `getCacheSize()`
    `int` | `getMaxCacheSize()`
    `java.lang.String[]` | `getTypes()`
    `java.lang.Object` | `invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)` Gets invoked each time an operation on `Connection` is invoked.
    `boolean` | `isCacheCallable()`
    `StatementCache.CachedStatement` | `isCached(java.lang.reflect.Method method, java.lang.Object[] args)`
    `StatementCache.CachedStatement` | `isCached(java.lang.String sql)` Deprecated. Unused. Will be removed in Tomcat 9
    `boolean` | `isCachePrepared()`
    `void` | `poolClosed(ConnectionPool pool)` This method is invoked by a connection pool when the pool is closed.
    `void` | `poolStarted(ConnectionPool pool)` This method is invoked by a connection pool when the pool is first started up, usually when the first connection is requested.
    `boolean` | `removeStatement(StatementCache.CachedStatement proxy)`
    `void` | `reset(ConnectionPool parent, PooledConnection con)` no-op for this interceptor. no state is stored.
    `void` | `setProperties(java.util.Map<java.lang.String,PoolProperties.InterceptorProperty> properties)` 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

    - ### Methods inherited from class org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor

      `closeInvoked, createStatement, getResultSetConstructor, isExecuteQuery, isExecuteQuery, isResultSet`

    - ### Methods inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor

      `getConstructor, isExecute, isStatement, process`

    - ### Methods inherited from class org.apache.tomcat.jdbc.pool.JdbcInterceptor

      `compare, compare, getNext, getProperties, isUseEquals, setNext, setUseEquals`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### ALL_TYPES

          protected static final java.lang.String[] ALL_TYPES

    - #### CALLABLE_TYPE

          protected static final java.lang.String[] CALLABLE_TYPE

    - #### PREPARED_TYPE

          protected static final java.lang.String[] PREPARED_TYPE

    - #### NO_TYPE

          protected static final java.lang.String[] NO_TYPE

    - #### STATEMENT_CACHE_ATTR

          protected static final java.lang.String STATEMENT_CACHE_ATTR

  - ### Constructor Detail

    - #### StatementCache

          public StatementCache()

  - ### Method Detail

    - #### isCachePrepared

          public boolean isCachePrepared()

    - #### isCacheCallable

          public boolean isCacheCallable()

    - #### getMaxCacheSize

          public int getMaxCacheSize()

    - #### getTypes

          public java.lang.String[] getTypes()

    - #### getCacheSize

          public java.util.concurrent.atomic.AtomicInteger getCacheSize()

    - #### setProperties

          public void setProperties(java.util.Map<java.lang.String,PoolProperties.InterceptorProperty> properties)

      Description copied from class: `JdbcInterceptor`
      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
      Overrides:
        `setProperties` in class `JdbcInterceptor`

    - #### poolStarted

          public void poolStarted(ConnectionPool pool)

      Description copied from class: `JdbcInterceptor`
      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.
      Overrides:
        `poolStarted` in class `JdbcInterceptor`
      Parameters:
        `pool` - - the pool that is being closed.

    - #### poolClosed

          public void poolClosed(ConnectionPool pool)

      Description copied from class: `JdbcInterceptor`
      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.
      Overrides:
        `poolClosed` in class `JdbcInterceptor`
      Parameters:
        `pool` - - the pool that is being closed.

    - #### reset

          public void reset(ConnectionPool parent,
                   PooledConnection con)

      Description copied from class: `AbstractCreateStatementInterceptor`
      no-op for this interceptor. no state is stored.
      Overrides:
        `reset` in class `AbstractCreateStatementInterceptor`
      Parameters:
        `parent` - - the connection pool owning the connection
        `con` - - the pooled connection

    - #### disconnected

          public void disconnected(ConnectionPool parent,
                          PooledConnection con,
                          boolean finalizing)

      Description copied from class: `JdbcInterceptor`
      Called when `Connection.close()` is called on the underlying connection. This is to notify the interceptors, that the physical connection has been released. Implementation of this method should be thought through with care, as no actions should trigger an exception.
      Overrides:
        `disconnected` in class `JdbcInterceptor`
      Parameters:
        `parent` - - the connection pool that this connection belongs to
        `con` - - the pooled connection that holds this connection
        `finalizing` - - if this connection is finalizing. True means that the pooled connection will not reconnect the underlying connection

    - #### closeStatement

          public void closeStatement(StatementCache.CachedStatement st)

    - #### 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

      Description copied from class: `StatementDecoratorInterceptor`
      Creates a proxy for a Statement.
      Overrides:
        `createDecorator` in class `StatementDecoratorInterceptor`
      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`
        `java.lang.IllegalAccessException`
        `java.lang.reflect.InvocationTargetException`

    - #### invoke

          public java.lang.Object invoke(java.lang.Object proxy,
                                java.lang.reflect.Method method,
                                java.lang.Object[] args)
                                  throws java.lang.Throwable

      Description copied from class: `AbstractCreateStatementInterceptor`
      Gets invoked each time an operation on `Connection` is invoked.
      Specified by:
        `invoke` in interface `java.lang.reflect.InvocationHandler`
      Overrides:
        `invoke` in class `AbstractCreateStatementInterceptor`
      Throws:
        `java.lang.Throwable`

    - #### isCached

          @Deprecated
          public StatementCache.CachedStatement isCached(java.lang.String sql)

      Deprecated. Unused. Will be removed in Tomcat 9
      Parameters:
        `sql` - Ignored
      Returns:
        `null`

    - #### isCached

          public StatementCache.CachedStatement isCached(java.lang.reflect.Method method,
                                                java.lang.Object[] args)

    - #### cacheStatement

          public boolean cacheStatement(StatementCache.CachedStatement proxy)

    - #### removeStatement

          public boolean removeStatement(StatementCache.CachedStatement proxy)

    - #### getCache

          protected java.util.concurrent.ConcurrentHashMap<org.apache.tomcat.jdbc.pool.interceptor.StatementCache.CacheKey,StatementCache.CachedStatement> getCache()

    - #### createCacheKey

          protected org.apache.tomcat.jdbc.pool.interceptor.StatementCache.CacheKey createCacheKey(java.lang.reflect.Method method,
                                                                                       java.lang.Object[] args)

    - #### createCacheKey

          protected org.apache.tomcat.jdbc.pool.interceptor.StatementCache.CacheKey createCacheKey(java.lang.String methodName,
                                                                                       java.lang.Object[] args)

Copyright © 2000-2019 Apache Software Foundation. All Rights Reserved.