[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-1737) The new BorrowedConnectionProxy prevents users from accessing the native connection

Steve Ebersole (JIRA) noreply at atlassian.com
Fri Nov 3 11:24:05 EST 2006


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1737?page=all ]
     
Steve Ebersole resolved HHH-1737:
---------------------------------

    Fix Version: 3.2.1
     Resolution: Fixed

trunk/3.2

> The new BorrowedConnectionProxy prevents users from accessing the native connection
> -----------------------------------------------------------------------------------
>
>          Key: HHH-1737
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1737
>      Project: Hibernate3
>         Type: Bug

>   Components: core
>     Versions: 3.1.1, 3.1.2, 3.1.3
>  Environment: Hibernate 3.1.3, Oracle 9.2.0.4
>     Reporter: Nick Reid
>     Assignee: Steve Ebersole
>      Fix For: 3.2.1

>
>
> The borrowConnection functionality now prevents us from accessing the native connection to perform necessary operations (LOB handling, OAQ integration).  Instead of just returning a simple proxy the implements java.sql.Connection the proxy could additionally implement an interface that allows users to access the wrapped connection returned by the ConnectionManager.
> i.e.
> public interface BorrowedConnection extends java.sql.Connection
> {
>      java.sql.Connection getTargetConnection()
> }
> public class BorrowedConnectionProxy implements InvocationHandler {
> 	private final ConnectionManager connectionManager;
> 	private boolean useable = true;
> 	public BorrowedConnectionProxy(ConnectionManager connectionManager) {
> 		this.connectionManager = connectionManager;
> 	}
> 	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
> 		if ( "close".equals( method.getName() ) ) {
> 			connectionManager.releaseBorrowedConnection();
> 			return null;
> 		}
> 		if ( "getTargetConnection".equals( method.getName() ) ) {
> 			return connectionManager.getConnection();
> 		}
> 		// should probably no-op commit/rollback here, at least in JTA scenarios
> 		if ( !useable ) {
> 			throw new HibernateException( "connnection proxy not usable after transaction completion" );
> 		}
> 		try {
> 			return method.invoke( connectionManager.getConnection(), args );
> 		}
> 		catch( InvocationTargetException e ) {
> 			throw e.getTargetException();
> 		}
> 	}
> 	public static Connection generateProxy(ConnectionManager connectionManager) {
> 		BorrowedConnectionProxy handler = new BorrowedConnectionProxy( connectionManager );
> 		return ( Connection ) Proxy.newProxyInstance(
> 				Connection.class.getClassLoader(),
> 		        new Class[] { BorrowedConnection.class },
> 		        handler
> 		);
> 	}
> 	public static void renderUnuseable(Connection connection) {
> 		if ( connection != null && Proxy.isProxyClass( connection.getClass() ) ) {
> 			InvocationHandler handler = Proxy.getInvocationHandler( connection );
> 			if ( BorrowedConnectionProxy.class.isAssignableFrom( handler.getClass() ) ) {
> 				( ( BorrowedConnectionProxy ) handler ).useable = false;
> 			}
> 		}
> 	}
> }
> We could always get access to the connectionManager field of the invocation handler via reflection, but this is not supportable or maintainable.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list