Class TrapException
- java.lang.Object
-
- org.apache.tomcat.jdbc.pool.JdbcInterceptor
-
- org.apache.tomcat.jdbc.pool.TrapException
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler
public class TrapException extends JdbcInterceptor
Interceptor that translates an exception type the invoked method does not declare into a type it does, so that a call through the pool's connection proxy respects theInvocationHandlercontract: the exception is re-thrown unchanged when the method declares it (a subclass of a declared type passes as well), replaced by anSQLExceptioncarrying it as the cause when the method declaresSQLException, and replaced by aRuntimeExceptioncarrying it as the cause otherwise. AnErroris always re-thrown as it is, including one carried by anInvocationTargetException.The pool prepends this interceptor to the definitions parsed from
jdbcInterceptors, so it heads the chain of every connection that has an interceptor chain at all; a pool configured without an interceptor list has no chain and therefore no trap. An undeclared checked exception reaching such an untrapped connection still respects the proxy contract - the JDK proxy itself turns it into anUndeclaredThrowableException- what the trap adds on top of that is the declared, JDBC-shaped exception with the original preserved as its cause.
-
-
Field Summary
-
Fields inherited from class org.apache.tomcat.jdbc.pool.JdbcInterceptor
ABORT_VAL, CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VAL
-
-
Constructor Summary
Constructors Constructor Description TrapException()Constructs a new TrapException interceptor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)Gets invoked each time an operation onConnectionis invoked.booleanisDeclaredException(java.lang.reflect.Method m, java.lang.Class<?> clazz)Checks if the given exception class is declared in the throws clause of the specified method.voidreset(ConnectionPool parent, PooledConnection con)no-op for this interceptor. no state is stored.-
Methods inherited from class org.apache.tomcat.jdbc.pool.JdbcInterceptor
compare, compare, disconnected, getNext, getProperties, isUseEquals, poolClosed, poolStarted, setNext, setProperties, setUseEquals, unregisterMBean
-
-
-
-
Method Detail
-
invoke
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.ThrowableDescription copied from class:JdbcInterceptorGets invoked each time an operation onConnectionis invoked.The base implementation passes the call to the
nextinterceptor in the chain. When there is no next interceptor, the call fails fast with aNullPointerException: a chain built by the pool always ends in theProxyConnectionterminal, so reaching this case means a chain was hand-built without a terminal link. Interceptors that do not answer a call themselves continue it withsuper.invoke(proxy, method, args).- Specified by:
invokein interfacejava.lang.reflect.InvocationHandler- Overrides:
invokein classJdbcInterceptor- Throws:
java.lang.Throwable
-
isDeclaredException
public boolean isDeclaredException(java.lang.reflect.Method m, java.lang.Class<?> clazz)Checks if the given exception class is declared in the throws clause of the specified method.- Parameters:
m- The method to checkclazz- The exception class to look for- Returns:
trueif the exception is declared,falseotherwise
-
reset
public void reset(ConnectionPool parent, PooledConnection con)
no-op for this interceptor. no state is stored.- Specified by:
resetin classJdbcInterceptor- Parameters:
parent- - the connection pool owning the connectioncon- - the pooled connection
-
-