Class ProxyConnection
- All Implemented Interfaces:
InvocationHandler
PooledConnection. The
ProxyConnection intercepts, among the calls it forwards, the following methods:
Connection.close()- returns the connection to the pool. May be called multiple times.Connection.abort(java.util.concurrent.Executor)- delegates the abort to the physical connection and then ends the borrow: the session is taken out of service and the slot is freed. On a released handle it is the specification's no-op; on a handle whose session the pool discarded while borrowed it skips the driver and ends the borrow quietly.Object.toString()- returns a custom string for this objectPooledConnection.getConnection()- returns the underlying connectionObject.equals(Object)andObject.hashCode()- answered with the identity of the connection handle, so that theObjectcontract holds even when no facade sits in front of this interceptor
PoolConfiguration.setUseEquals(boolean) has been called with a true argument.
The connection handle the pool hands out implements PooledConnection (and
XAConnection when the pool is backed by an XADataSource). The pool keeps no
connection or statement event listeners of its own, so the four listener methods of
javax.sql.PooledConnection - addConnectionEventListener, removeConnectionEventListener,
addStatementEventListener and removeStatementEventListener - are answered by the XA-family
dispatch in invoke(Object, Method, Object[]): where the handle is itself an XAConnection they
reach the XA connection the driver created, whose implementation decides what registering them means; where it
is not, the call has no dispatch target and each of the four fails with an SQLException naming the
method. The refusal also stands on a pool backed by a ConnectionPoolDataSource: the pool does
hold the driver's own pooled connection there, but it holds it for its own session management and does not
route these calls to it. A handle whose session the pool discarded while it was still borrowed, or which its
borrower has already closed, answers instead with the closed-connection failure the handle gives in those
states. Either failure reaches a caller of the interface - the interface declares no checked exception - as an
UndeclaredThrowableException carrying it. That refusal is deliberate rather than
unfinished work. The specification has the connection pool manager register through these methods, to be told
to deactivate the logical handle and reuse or retire the physical session - decisions this pool makes and
carries out itself: close() on the handle recycles a session that stays open and owned by the pool, and
the next borrower is handed a new handle, so this handle is not the long-lived producer object whose listener
list the specification describes; and where the pool does not observe statements - as it does not by default -
a statementClosed event has no point from which it could be delivered. Accepting a registration it
could not notify faithfully would only hide from the caller that no notification will ever arrive.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PooledConnectionThe underlying pooled connection.protected ConnectionPoolThe parent connection pool.Fields inherited from class JdbcInterceptor
ABORT_VAL, CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VALModifier and TypeFieldDescriptionstatic final StringConnection.abort(java.util.concurrent.Executor)method namestatic final StringConnection.close()method namestatic final Stringstatic final StringPooledConnection.getConnection()method namestatic final Stringstatic final StringConnection.isClosed()method namestatic final StringConnection.isValid(int)method namestatic final StringWrapper.isWrapperFor(Class)method nameprotected Map<String, PoolProperties.InterceptorProperty> Properties for this interceptor.static final StringObject.toString()method namestatic final StringWrapper.unwrap(Class)method name -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProxyConnection(ConnectionPool parent, PooledConnection con, boolean useEquals) Creates a new ProxyConnection wrapping the given pooled connection. -
Method Summary
Modifier and TypeMethodDescriptionReturns the underlying pooled connection.Returns the delegate pooled connection.Returns the parent connection pool.getPool()Returns the parent connection pool.Gets invoked each time an operation onConnectionis invoked.booleanisClosed()Returns true if the underlying connection has been closed or discarded.booleanisWrapperFor(Class<?> iface) Checks whether this interceptor wraps the given interface.voidreset(ConnectionPool parent, PooledConnection con) Gets called each time the connection is borrowed from the pool This means that if an interceptor holds a reference to the connection the interceptor can be reused for another connection.voidsetConnection(PooledConnection connection) Sets the underlying pooled connection.voidsetPool(ConnectionPool pool) Sets the parent connection pool.toString()Unwraps the connection to the given interface.Methods inherited from class JdbcInterceptor
compare, compare, disconnected, getNext, getProperties, isUseEquals, poolClosed, poolStarted, setNext, setProperties, setUseEqualsModifier and TypeMethodDescriptionbooleanCompares a method name (String) to a method (Method)JdbcInterceptor.compare(String,String)Uses reference comparison unless the useEquals property is set to truebooleanPerforms a string comparison, using references unless the useEquals property is set to true.voiddisconnected(ConnectionPool parent, PooledConnection con, boolean finalizing) Called whenConnection.close()is called on the underlying connection.getNext()Returns the next interceptor in the chainReturns the properties configured for this interceptorbooleanTrue if the compare method uses the Object.equals(Object) method, false if comparison is done on a reference level.voidpoolClosed(ConnectionPool pool) This method is invoked by a connection pool when the pool is closed.voidpoolStarted(ConnectionPool pool) This method is invoked by a connection pool when the pool is first started up, usually when the first connection is requested.voidsetNext(JdbcInterceptor next) configures the next interceptor in the chainvoidsetProperties(Map<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 propertiesvoidsetUseEquals(boolean useEquals) Set to true if string comparisons (for theJdbcInterceptor.compare(String, Method)andJdbcInterceptor.compare(String, String)methods) should use the Object.equals(Object) method The default is false
-
Field Details
-
connection
The underlying pooled connection. -
pool
The parent connection pool.
-
-
Constructor Details
-
ProxyConnection
Creates a new ProxyConnection wrapping the given pooled connection.- Parameters:
parent- the parent connection poolcon- the pooled connectionuseEquals- whether to use equals for method comparison
-
-
Method Details
-
getConnection
Returns the underlying pooled connection.- Returns:
- the pooled connection
-
setConnection
Sets the underlying pooled connection.- Parameters:
connection- the pooled connection
-
getPool
-
setPool
Sets the parent connection pool.- Parameters:
pool- the connection pool
-
reset
Description copied from class:JdbcInterceptorGets called each time the connection is borrowed from the pool This means that if an interceptor holds a reference to the connection the interceptor can be reused for another connection.
This method may be called with null as both arguments when we are closing down the connection. When called for a shutdown reset, an interceptor that throws is isolated: the exception is logged and ignored, and the remaining interceptors in the chain are reset as well.- Specified by:
resetin classJdbcInterceptor- Parameters:
parent- - the connection pool owning the connectioncon- - the pooled connection
-
isWrapperFor
Checks whether this interceptor wraps the given interface. This is the view from the interceptor itself; the contract of the connection handle the pool hands out - which also implementsConnectionandPooledConnection(andXAConnectionon XA pools) - is answered by the dispatch ininvoke(Object, Method, Object[]).- Parameters:
iface- the interface to check- Returns:
- true if this interceptor wraps the given interface
-
unwrap
Unwraps the connection to the given interface.- Parameters:
iface- the interface to unwrap to- Returns:
- the unwrapped connection. For
PooledConnectionthis is the pool's own pooled connection - a pool-internal object meant for trusted callers such as interceptors, not for application code, as it can close and discard the connection behind the pool's own accounting. - Throws:
SQLException- if the connection does not wrap the given interface
-
invoke
Description copied from class:JdbcInterceptorGets invoked each time an operation onConnectionis invoked.- Specified by:
invokein interfaceInvocationHandler- Overrides:
invokein classJdbcInterceptor- Throws:
Throwable
-
isClosed
public boolean isClosed()Returns true if the underlying connection has been closed or discarded.- Returns:
- true if closed or discarded
-
getDelegateConnection
Returns the delegate pooled connection.- Returns:
- the delegate pooled connection
-
getParentPool
Returns the parent connection pool.- Returns:
- the parent connection pool
-
toString
-