Methods Summary |
---|
public static java.sql.Connection | generateProxy(ConnectionManager connectionManager)Generates a Connection proxy wrapping the connection managed by the passed
connection manager.
BorrowedConnectionProxy handler = new BorrowedConnectionProxy( connectionManager );
return ( Connection ) Proxy.newProxyInstance(
getProxyClassLoader(),
PROXY_INTERFACES,
handler
);
|
public static java.lang.ClassLoader | getProxyClassLoader()Determines the appropriate class loader to which the generated proxy
should be scoped.
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if ( cl == null ) {
cl = BorrowedConnectionProxy.class.getClassLoader();
}
return cl;
|
public static java.sql.Connection | getWrappedConnection(java.sql.Connection connection)Convience method for unwrapping a connection proxy and getting a
handle to an underlying connection.
if ( connection != null && connection instanceof ConnectionWrapper ) {
return ( ( ConnectionWrapper ) connection ).getWrappedConnection();
}
else {
return connection;
}
|
public java.lang.Object | invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args){@inheritDoc}
if ( "close".equals( method.getName() ) ) {
connectionManager.releaseBorrowedConnection();
return null;
}
// should probably no-op commit/rollback here, at least in JTA scenarios
if ( !useable ) {
throw new HibernateException( "connnection proxy not usable after transaction completion" );
}
if ( "getWrappedConnection".equals( method.getName() ) ) {
return connectionManager.getConnection();
}
try {
return method.invoke( connectionManager.getConnection(), args );
}
catch( InvocationTargetException e ) {
throw e.getTargetException();
}
|
public static void | renderUnuseable(java.sql.Connection connection)Marks a borrowed connection as no longer usable.
if ( connection != null && Proxy.isProxyClass( connection.getClass() ) ) {
InvocationHandler handler = Proxy.getInvocationHandler( connection );
if ( BorrowedConnectionProxy.class.isAssignableFrom( handler.getClass() ) ) {
( ( BorrowedConnectionProxy ) handler ).useable = false;
}
}
|