updated JPA 2.0 compatibility to EclipseLink 2.0.0.M7

This commit is contained in:
Juergen Hoeller 2009-08-27 00:51:47 +00:00
parent d3a6c48cf0
commit 83289cb8b0
1 changed files with 5 additions and 9 deletions

View File

@ -71,7 +71,7 @@ public abstract class SharedEntityManagerCreator {
* @return a shareable transaction EntityManager proxy * @return a shareable transaction EntityManager proxy
*/ */
public static EntityManager createSharedEntityManager(EntityManagerFactory emf, Map properties) { public static EntityManager createSharedEntityManager(EntityManagerFactory emf, Map properties) {
Class[] emIfcs = null; Class[] emIfcs;
if (emf instanceof EntityManagerFactoryInfo) { if (emf instanceof EntityManagerFactoryInfo) {
EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf; EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf;
Class emIfc = emfInfo.getEntityManagerInterface(); Class emIfc = emfInfo.getEntityManagerInterface();
@ -154,10 +154,10 @@ public abstract class SharedEntityManagerCreator {
// JPA 2.0: return EntityManagerFactory without creating an EntityManager. // JPA 2.0: return EntityManagerFactory without creating an EntityManager.
return this.targetFactory; return this.targetFactory;
} }
else if (method.getName().equals("getQueryBuilder")) { else if (method.getName().equals("getQueryBuilder") || method.getName().equals("getMetamodel")) {
// JPA 2.0: return EntityManagerFactory's QueryBuilder (avoid creation of EntityManager). // JPA 2.0: return EntityManagerFactory's QueryBuilder/Metamodel (avoid creation of EntityManager)
try { try {
return EntityManagerFactory.class.getMethod("getQueryBuilder").invoke(this.targetFactory); return EntityManagerFactory.class.getMethod(method.getName()).invoke(this.targetFactory);
} }
catch (InvocationTargetException ex) { catch (InvocationTargetException ex) {
throw ex.getTargetException(); throw ex.getTargetException();
@ -202,15 +202,11 @@ public abstract class SharedEntityManagerCreator {
return target; return target;
} }
else if (method.getName().equals("unwrap")) { else if (method.getName().equals("unwrap")) {
// Handle JPA 2.0 unwrap method - could be a proxy match.
Class targetClass = (Class) args[0];
if (targetClass == null || targetClass.isInstance(proxy)) {
return proxy;
}
// We need a transactional target now. // We need a transactional target now.
if (target == null) { if (target == null) {
throw new IllegalStateException("No transactional EntityManager available"); throw new IllegalStateException("No transactional EntityManager available");
} }
// Still perform unwrap call on target EntityManager.
} }
// Regular EntityManager operations. // Regular EntityManager operations.