OPENJPA-1803: Fix EM.unwrap(java.sql.Connection.class) to account for a non-jdbc(sql) backed store.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1155500 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Richard G. Curtis 2011-08-09 19:17:07 +00:00
parent 67d00f4fca
commit 29213af88a

View File

@ -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