[hibernate-commits] Hibernate SVN: r10724 - trunk/Hibernate3/src/org/hibernate/jdbc
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Mon Nov 6 08:27:45 EST 2006
Author: steve.ebersole at jboss.com
Date: 2006-11-06 08:27:44 -0500 (Mon, 06 Nov 2006)
New Revision: 10724
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-06 13:27:28 UTC (rev 10723)
+++ trunk/Hibernate3/src/org/hibernate/jdbc/BorrowedConnectionProxy.java 2006-11-06 13:27:44 UTC (rev 10724)
@@ -29,6 +29,9 @@
this.connectionManager = connectionManager;
}
+ /**
+ * {@inheritDoc}
+ */
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ( "close".equals( method.getName() ) ) {
connectionManager.releaseBorrowedConnection();
@@ -51,15 +54,28 @@
}
}
+ /**
+ * Generates a Connection proxy wrapping the connection managed by the passed
+ * connection manager.
+ *
+ * @param connectionManager The connection manager to wrap with the
+ * connection proxy.
+ * @return The generated proxy.
+ */
public static Connection generateProxy(ConnectionManager connectionManager) {
BorrowedConnectionProxy handler = new BorrowedConnectionProxy( connectionManager );
return ( Connection ) Proxy.newProxyInstance(
- Connection.class.getClassLoader(),
+ getProxyClassLoader(),
PROXY_INTERFACES,
handler
);
}
+ /**
+ * Marks a borrowed connection as no longer usable.
+ *
+ * @param connection The connection (proxy) to be marked.
+ */
public static void renderUnuseable(Connection connection) {
if ( connection != null && Proxy.isProxyClass( connection.getClass() ) ) {
InvocationHandler handler = Proxy.getInvocationHandler( connection );
@@ -69,13 +85,33 @@
}
}
+ /**
+ * Convience method for unwrapping a connection proxy and getting a
+ * handle to an underlying connection.
+ *
+ * @param connection The connection (proxy) to be unwrapped.
+ * @return The unwrapped connection.
+ */
public static Connection getWrappedConnection(Connection connection) {
- if ( connection == null ) {
- return null;
+ if ( connection != null && connection instanceof ConnectionWrapper ) {
+ return ( ( ConnectionWrapper ) connection ).getWrappedConnection();
}
- if ( connection instanceof ConnectionWrapper ) {
- ( ( ConnectionWrapper ) connection ).getWrappedConnection();
+ else {
+ return connection;
}
- return connection;
}
+
+ /**
+ * Determines the appropriate class loader to which the generated proxy
+ * should be scoped.
+ *
+ * @return The class loader appropriate for proxy construction.
+ */
+ public static ClassLoader getProxyClassLoader() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if ( cl == null ) {
+ cl = BorrowedConnectionProxy.class.getClassLoader();
+ }
+ return cl;
+ }
}
More information about the hibernate-commits
mailing list