[hibernate-commits] Hibernate SVN: r10715 - trunk/Hibernate3/src/org/hibernate/jdbc
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Nov 3 11:23:22 EST 2006
Author: steve.ebersole at jboss.com
Date: 2006-11-03 11:23:21 -0500 (Fri, 03 Nov 2006)
New Revision: 10715
Added:
trunk/Hibernate3/src/org/hibernate/jdbc/ConnectionWrapper.java
Modified:
trunk/Hibernate3/src/org/hibernate/jdbc/BorrowedConnectionProxy.java
Log:
HHH-1737 : ConnectionWrapper
Modified: trunk/Hibernate3/src/org/hibernate/jdbc/BorrowedConnectionProxy.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/jdbc/BorrowedConnectionProxy.java 2006-11-03 16:23:02 UTC (rev 10714)
+++ trunk/Hibernate3/src/org/hibernate/jdbc/BorrowedConnectionProxy.java 2006-11-03 16:23:21 UTC (rev 10715)
@@ -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: trunk/Hibernate3/src/org/hibernate/jdbc/ConnectionWrapper.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/jdbc/ConnectionWrapper.java 2006-11-03 16:23:02 UTC (rev 10714)
+++ trunk/Hibernate3/src/org/hibernate/jdbc/ConnectionWrapper.java 2006-11-03 16:23:21 UTC (rev 10715)
@@ -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