public abstract class JdbcInterceptor extends Object implements InvocationHandler
Connection
object the
invoke(Object, Method, Object[])
method on the interceptor will be called.
Interceptors are useful to change or improve behavior of the connection pool.setProperties(Map)
method.
Properties arrive in a key-value pair of Strings as they were received through the configuration.
This method is called once per cached connection object when the object is first configured.Modifier and Type | Field and Description |
---|---|
static String |
CLOSE_VAL
Connection.close() method name |
static String |
EQUALS_VAL
|
static String |
GETCONNECTION_VAL
PooledConnection.getConnection() method name |
static String |
HASHCODE_VAL
|
static String |
ISCLOSED_VAL
Connection.isClosed() method name |
static String |
ISVALID_VAL
Connection.isValid(int) method name |
static String |
ISWRAPPERFOR_VAL
Wrapper.isWrapperFor(Class) method name |
protected Map<String,PoolProperties.InterceptorProperty> |
properties
Properties for this interceptor.
|
static String |
TOSTRING_VAL
Object.toString() method name |
static String |
UNWRAP_VAL
Wrapper.unwrap(Class) method name |
Constructor and Description |
---|
JdbcInterceptor()
Public constructor for instantiation through reflection
|
Modifier and Type | Method and Description |
---|---|
boolean |
compare(String methodName,
Method method)
Compares a method name (String) to a method (Method)
compare(String,String)
Uses reference comparison unless the useEquals property is set to true |
boolean |
compare(String name1,
String name2)
Performs a string comparison, using references unless the useEquals property is set to true.
|
void |
disconnected(ConnectionPool parent,
PooledConnection con,
boolean finalizing)
Called when
Connection.close() is called on the underlying connection. |
JdbcInterceptor |
getNext()
Returns the next interceptor in the chain
|
Map<String,PoolProperties.InterceptorProperty> |
getProperties()
Returns the properties configured for this interceptor
|
Object |
invoke(Object proxy,
Method method,
Object[] args)
Gets invoked each time an operation on
Connection is invoked. |
boolean |
isUseEquals() |
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.
|
abstract void |
reset(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.
|
void |
setNext(JdbcInterceptor next)
configures the next interceptor in the chain
|
void |
setProperties(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 properties
|
void |
setUseEquals(boolean useEquals)
Set to true if string comparisons (for the
compare(String, Method) and compare(String, String) methods) should use the Object.equals(Object) method
The default is false |
public static final String CLOSE_VAL
Connection.close()
method namepublic static final String TOSTRING_VAL
Object.toString()
method namepublic static final String ISCLOSED_VAL
Connection.isClosed()
method namepublic static final String GETCONNECTION_VAL
PooledConnection.getConnection()
method namepublic static final String UNWRAP_VAL
Wrapper.unwrap(Class)
method namepublic static final String ISWRAPPERFOR_VAL
Wrapper.isWrapperFor(Class)
method namepublic static final String ISVALID_VAL
Connection.isValid(int)
method namepublic static final String EQUALS_VAL
public static final String HASHCODE_VAL
protected Map<String,PoolProperties.InterceptorProperty> properties
public JdbcInterceptor()
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
Connection
is invoked.
invoke
in interface InvocationHandler
Throwable
public JdbcInterceptor getNext()
public void setNext(JdbcInterceptor next)
next
- public boolean compare(String name1, String name2)
name1
- name2
- useEquals
public boolean compare(String methodName, Method method)
compare(String,String)
Uses reference comparison unless the useEquals property is set to truemethodName
- method
- public abstract void reset(ConnectionPool parent, PooledConnection con)
parent
- - the connection pool owning the connectioncon
- - the pooled connectionpublic void disconnected(ConnectionPool parent, PooledConnection con, boolean finalizing)
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.parent
- - the connection pool that this connection belongs tocon
- - the pooled connection that holds this connectionfinalizing
- - if this connection is finalizing. True means that the pooled connection will not reconnect the underlying connectionpublic Map<String,PoolProperties.InterceptorProperty> getProperties()
public void setProperties(Map<String,PoolProperties.InterceptorProperty> properties)
properties
- public boolean isUseEquals()
public void setUseEquals(boolean useEquals)
compare(String, Method)
and compare(String, String)
methods) should use the Object.equals(Object) method
The default is falseuseEquals
- public void poolClosed(ConnectionPool pool)
pool
- - the pool that is being closed.public void poolStarted(ConnectionPool pool)
pool
- - the pool that is being closed.Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.