Class StatementCache.CachedStatement
- java.lang.Object
-
- org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor.StatementProxy<java.sql.PreparedStatement>
-
- org.apache.tomcat.jdbc.pool.interceptor.StatementCache.CachedStatement
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler
- Enclosing class:
- StatementCache
protected class StatementCache.CachedStatement extends StatementDecoratorInterceptor.StatementProxy<java.sql.PreparedStatement>
Proxy for a cached prepared statement.
-
-
Field Summary
-
Fields inherited from class org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor.StatementProxy
closed, delegate
-
-
Constructor Summary
Constructors Constructor Description CachedStatement(java.sql.PreparedStatement parent, java.lang.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).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseInvoked()Called when the close method is invoked on the statement.voidforceClose()Forces immediate closure of this cached statement.java.sql.ConnectiongetAssociatedConnection()Returns the physical connection this statement was prepared on.org.apache.tomcat.jdbc.pool.interceptor.StatementCache.CacheKeygetCacheKey()Returns the cache key for this statement.java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)voidsetCacheKey(org.apache.tomcat.jdbc.pool.interceptor.StatementCache.CacheKey cacheKey)Sets the cache key for this statement.-
Methods inherited from class org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor.StatementProxy
equals, getActualProxy, getConnection, getConstructor, getDelegate, getSql, hashCode, setActualProxy, setConnection, setConstructor, toString
-
-
-
-
Constructor Detail
-
CachedStatement
public CachedStatement(java.sql.PreparedStatement parent, java.lang.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 statementsql- the SQL text
-
-
Method Detail
-
getAssociatedConnection
public java.sql.Connection getAssociatedConnection()
Returns the physical connection this statement was prepared on.- Returns:
- the connection associated with the statement
-
closeInvoked
public void closeInvoked() throws java.sql.SQLExceptionDescription copied from class:StatementDecoratorInterceptor.StatementProxyCalled when the close method is invoked on the statement.The driver's answer is passed on to the caller:
Statement.close()declaresSQLExceptionfor 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(org.apache.tomcat.jdbc.pool.interceptor.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:
closeInvokedin classStatementDecoratorInterceptor.StatementProxy<java.sql.PreparedStatement>- Throws:
java.sql.SQLException- if the underlying statement could not be closed
-
invoke
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable- Specified by:
invokein interfacejava.lang.reflect.InvocationHandler- Overrides:
invokein classStatementDecoratorInterceptor.StatementProxy<java.sql.PreparedStatement>- Throws:
java.lang.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
-
-