Class StatementCache.CachedStatement

All Implemented Interfaces:
InvocationHandler
Enclosing class:
StatementCache

protected class StatementCache.CachedStatement extends StatementDecoratorInterceptor.StatementProxy<PreparedStatement>
Proxy for a cached prepared statement.
  • Constructor Details

    • CachedStatement

      public CachedStatement(PreparedStatement parent, String sql)
      Constructs a CachedStatement, recording the physical connection the statement was prepared on as the answer of the statement itself (or, when that answer is not a physical connection the cache can read, of the pool's own record of the session the prepare ran on).
      Parameters:
      parent - the parent prepared statement
      sql - the SQL text
  • Method Details

    • getAssociatedConnection

      public Connection getAssociatedConnection()
      Returns the physical connection this statement was prepared on.
      Returns:
      the connection associated with the statement
    • closeInvoked

      public void closeInvoked() throws SQLException
      Description copied from class: StatementDecoratorInterceptor.StatementProxy
      Called when the close method is invoked on the statement.

      The driver's answer is passed on to the caller: Statement.close() declares SQLException for a database error while closing, and this proxy reports every other call as the delegate answered it, so a failed close must not come back as a success. The swallowed failure this replaces told the application that the statement was closed while the driver had left its resources on the session the pooled connection was about to hand to the next borrower, and nothing along the path recorded or retried it.

      The handle is retired whichever way the driver answered: the application has been told, and a handle whose close failed must not go on answering calls on a statement the driver may have half released. Where no application waits on the close - the cache dropping a statement, see StatementCache.closeStatement(StatementCache.CachedStatement) - the failure is answered with a log line instead, so that one statement that will not close cannot stop the rest of that purge.

      Overrides:
      closeInvoked in class StatementDecoratorInterceptor.StatementProxy<PreparedStatement>
      Throws:
      SQLException - if the underlying statement could not be closed
    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      Specified by:
      invoke in interface InvocationHandler
      Overrides:
      invoke in class StatementDecoratorInterceptor.StatementProxy<PreparedStatement>
      Throws:
      Throwable
    • forceClose

      public void forceClose()
      Forces immediate closure of this cached statement. No application waits on this close - the pool is dropping the statement, from the purge that runs when a session is disconnected or from a cache hit on an entry of a replaced session - so a driver that refuses it is logged rather than thrown: the caller walks the cache, and one statement that will not close must not keep the entries after it from being dropped as well.
    • getCacheKey

      public org.apache.tomcat.jdbc.pool.interceptor.StatementCache.CacheKey getCacheKey()
      Returns the cache key for this statement.
      Returns:
      the cache key
    • setCacheKey

      public void setCacheKey(org.apache.tomcat.jdbc.pool.interceptor.StatementCache.CacheKey cacheKey)
      Sets the cache key for this statement.
      Parameters:
      cacheKey - the cache key