[hibernate-commits] Hibernate SVN: r10714 - branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Nov 3 11:23:04 EST 2006


Author: steve.ebersole at jboss.com
Date: 2006-11-03 11:23:02 -0500 (Fri, 03 Nov 2006)
New Revision: 10714

Added:
   branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/ConnectionWrapper.java
Modified:
   branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/BorrowedConnectionProxy.java
Log:
HHH-1737 : ConnectionWrapper

Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/BorrowedConnectionProxy.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/BorrowedConnectionProxy.java	2006-11-03 16:20:54 UTC (rev 10713)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/BorrowedConnectionProxy.java	2006-11-03 16:23:02 UTC (rev 10714)
@@ -20,6 +20,8 @@
  */
 public class BorrowedConnectionProxy implements InvocationHandler {
 
+	private static final Class[] PROXY_INTERFACES = new Class[] { Connection.class, ConnectionWrapper.class };
+
 	private final ConnectionManager connectionManager;
 	private boolean useable = true;
 
@@ -36,6 +38,11 @@
 		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 );
 		}
@@ -48,7 +55,7 @@
 		BorrowedConnectionProxy handler = new BorrowedConnectionProxy( connectionManager );
 		return ( Connection ) Proxy.newProxyInstance(
 				Connection.class.getClassLoader(),
-		        new Class[] { Connection.class },
+		        PROXY_INTERFACES,
 		        handler
 		);
 	}
@@ -61,4 +68,14 @@
 			}
 		}
 	}
+
+	public static Connection getWrappedConnection(Connection connection) {
+		if ( connection == null ) {
+			return null;
+		}
+		if ( connection instanceof ConnectionWrapper ) {
+			( ( ConnectionWrapper ) connection ).getWrappedConnection();
+		}
+		return connection;
+	}
 }

Added: branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/ConnectionWrapper.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/ConnectionWrapper.java	2006-11-03 16:20:54 UTC (rev 10713)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/jdbc/ConnectionWrapper.java	2006-11-03 16:23:02 UTC (rev 10714)
@@ -0,0 +1,18 @@
+package org.hibernate.jdbc;
+
+import java.sql.Connection;
+
+/**
+ * Interface implemented by JDBC connection wrappers in order to give
+ * access to the underlying wrapped connection.
+ *
+ * @author Steve Ebersole
+ */
+public interface ConnectionWrapper {
+	/**
+	 * Get a reference to the wrapped connection.
+	 *
+	 * @return The wrapped connection.
+	 */
+	public Connection getWrappedConnection();
+}




More information about the hibernate-commits mailing list