Top Description Fields Constructors Methods
org.apache.tomcat.jdbc.pool

public abstract Class JdbcInterceptor

extends Object
implements InvocationHandler
Class Inheritance
All Implemented Interfaces
java.lang.reflect.InvocationHandler
Known Direct Subclasses
org.apache.tomcat.jdbc.pool.ProxyConnection, org.apache.tomcat.jdbc.pool.TrapException, org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor, org.apache.tomcat.jdbc.pool.interceptor.ConnectionState, org.apache.tomcat.jdbc.pool.DisposableConnectionFacade
Imports
java.lang.reflect.InvocationHandler, .Method, java.util.Map, org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorProperty

Abstract class that is to be extended for implementations of interceptors. Everytime an operation is called on the java.sql.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.
Interceptors can receive a set of properties. Each sub class is responsible for parsing the properties during runtime when they are needed or simply override the 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.

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
private volatile JdbcInterceptor
next

The next interceptor in the chain

protected Map<String, PoolProperties.InterceptorProperty>
properties

Properties for this interceptor.

public static final String
public static final String
private boolean
useEquals

Property that decides how we do string comparison, default is to use String#equals(Object).

Constructor Summary

AccessConstructor and Description
public
JdbcInterceptor()

Public constructor for instantiation through reflection

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if name1 is equal to name2 based on useEquals
compare
(String
The first name
name1
,
String
The second name
name2
)

Performs a string comparison, using references unless the useEquals property is set to true.

public boolean

Returns:

true if the name matches
compare
(String
The method name
methodName
,
Method
The 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

public void
disconnected(ConnectionPool
- the connection pool that this connection belongs to
parent
,
PooledConnection
- the pooled connection that holds this connection
con
,
boolean
- if this connection is finalizing. True means that the pooled connection will not reconnect the underlying connection
finalizing
)

Called when java.sql.Connection#close() is called on the underlying connection.

public JdbcInterceptor

Returns:

the next interceptor in the chain
getNext
()

Returns the next interceptor in the chain

public Map<String, PoolProperties.InterceptorProperty>

Returns:

the configured properties for this interceptor
getProperties
()

Returns the properties configured for this interceptor

public Object
invoke(Object
the proxy instance that the method was invoked on
proxy
,
Method
the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
method
,
Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
args
)

Implements java.lang.reflect.InvocationHandler.invoke.

Gets invoked each time an operation on java.sql.Connection is invoked.

public boolean

Returns:

true if the compare method uses the Object.equals(Object) method false if comparison is done on a reference level
isUseEquals
()

public void
poolClosed(ConnectionPool
- the pool that is being closed.
pool
)

This method is invoked by a connection pool when the pool is closed.

public void
poolStarted(ConnectionPool
- the pool that is being closed.
pool
)

This method is invoked by a connection pool when the pool is first started up, usually when the first connection is requested.

public abstract void
reset(ConnectionPool
- the connection pool owning the connection
parent
,
PooledConnection
- the pooled connection
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.

public void
setNext(JdbcInterceptor
The next chain item
next
)

configures the next interceptor in the chain

public void
setProperties(Map<String, PoolProperties.InterceptorProperty>
The properties
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

public void
setUseEquals(boolean
true if equals will be used for comparisons
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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLOSE_VALback to summary
public static final String CLOSE_VAL

java.sql.Connection#close() method name

EQUALS_VALback to summary
public static final String EQUALS_VAL

java.lang.Object#equals(Object)

GETCONNECTION_VALback to summary
public static final String GETCONNECTION_VAL

javax.sql.PooledConnection#getConnection() method name

HASHCODE_VALback to summary
public static final String HASHCODE_VAL

java.lang.Object#hashCode()

ISCLOSED_VALback to summary
public static final String ISCLOSED_VAL

java.sql.Connection#isClosed() method name

ISVALID_VALback to summary
public static final String ISVALID_VAL

java.sql.Connection#isValid(int) method name

ISWRAPPERFOR_VALback to summary
public static final String ISWRAPPERFOR_VAL

java.sql.Wrapper#isWrapperFor(Class) method name

nextback to summary
private volatile JdbcInterceptor next

The next interceptor in the chain

propertiesback to summary
protected Map<String, PoolProperties.InterceptorProperty> properties

Properties for this interceptor.

TOSTRING_VALback to summary
public static final String TOSTRING_VAL

Object#toString() method name

UNWRAP_VALback to summary
public static final String UNWRAP_VAL

java.sql.Wrapper#unwrap(Class) method name

useEqualsback to summary
private boolean useEquals

Property that decides how we do string comparison, default is to use String#equals(Object). If set to false then the equality operator (==) is used.

Constructor Detail

JdbcInterceptorback to summary
public JdbcInterceptor()

Public constructor for instantiation through reflection

Method Detail

compareback to summary
public boolean compare(String name1, String name2)

Performs a string comparison, using references unless the useEquals property is set to true.

Parameters
name1:String

The first name

name2:String

The second name

Returns:boolean

true if name1 is equal to name2 based on useEquals

compareback to summary
public 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

Parameters
methodName:String

The method name

method:Method

The method

Returns:boolean

true if the name matches

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

Called when java.sql.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.

Parameters
parent:ConnectionPool

- the connection pool that this connection belongs to

con:PooledConnection

- the pooled connection that holds this connection

finalizing:boolean

- if this connection is finalizing. True means that the pooled connection will not reconnect the underlying connection

getNextback to summary
public JdbcInterceptor getNext()

Returns the next interceptor in the chain

Returns:JdbcInterceptor

the next interceptor in the chain

getPropertiesback to summary
public Map<String, PoolProperties.InterceptorProperty> getProperties()

Returns the properties configured for this interceptor

Returns:Map<String, PoolProperties.InterceptorProperty>

the configured properties for this interceptor

invokeback to summary
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable

Implements java.lang.reflect.InvocationHandler.invoke.

Doc from java.lang.reflect.InvocationHandler.invoke.

Gets invoked each time an operation on java.sql.Connection is invoked. Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.

Parameters
proxy:Object

the proxy instance that the method was invoked on

method:Method

the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.

args:Object[]

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.

Returns:Object

the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.

Annotations
@Override
Exceptions
Throwable:
the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.
isUseEqualsback to summary
public boolean isUseEquals()
Returns:boolean

true if the compare method uses the Object.equals(Object) method false if comparison is done on a reference level

poolClosedback to summary
public void poolClosed(ConnectionPool pool)

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.

Parameters
pool:ConnectionPool

- the pool that is being closed.

poolStartedback to summary
public 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. 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.

Parameters
pool:ConnectionPool

- the pool that is being closed.

resetback to summary
public 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.
This method may be called with null as both arguments when we are closing down the connection.

Parameters
parent:ConnectionPool

- the connection pool owning the connection

con:PooledConnection

- the pooled connection

setNextback to summary
public void setNext(JdbcInterceptor next)

configures the next interceptor in the chain

Parameters
next:JdbcInterceptor

The next chain item

setPropertiesback to summary
public 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

Parameters
properties:Map<String, PoolProperties.InterceptorProperty>

The properties

setUseEqualsback to summary
public 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

Parameters
useEquals:boolean

true if equals will be used for comparisons