You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by cu...@apache.org on 2011/08/09 21:17:08 UTC

svn commit: r1155500 - /openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java

Author: curtisr7
Date: Tue Aug  9 19:17:07 2011
New Revision: 1155500

URL: http://svn.apache.org/viewvc?rev=1155500&view=rev
Log:
OPENJPA-1803: Fix EM.unwrap(java.sql.Connection.class) to account for a non-jdbc(sql) backed store.

Modified:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java?rev=1155500&r1=1155499&r2=1155500&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java Tue Aug  9 19:17:07 2011
@@ -1660,6 +1660,7 @@ public class EntityManagerImpl
      * @exception if the given class is null, generic <code>Object.class</code> or a class
      * that is not wrapped by this receiver.  
      */
+    @SuppressWarnings("unchecked")
     public <T> T unwrap(Class<T> cls) {
         if (cls != null && cls != Object.class) {
             Object[] delegates = new Object[] { _broker.getInnermostDelegate(), _broker.getDelegate(), _broker, this };
@@ -1669,7 +1670,13 @@ public class EntityManagerImpl
             }
             // Only call getConnection() once we are certain that is the type that we need to unwrap.
             if (cls.isAssignableFrom(Connection.class)) {
-                return (T) getConnection();
+                Object o = getConnection();
+                if(Connection.class.isInstance(o)){
+                    return (T) o;   
+                }else{
+                    // Try and cleanup if  aren't going to return the connection back to the caller.
+                    ImplHelper.close(o);
+                }
             }
         }
         // Set this transaction to rollback only (as per spec) here because the raised exception