From: erik Date: Fri, 30 Apr 2010 14:19:35 +0000 (+0000) Subject: jpauserset now working. X-Git-Tag: wamblee-utils-0.2.2^2~22 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=790bc19469692473ccc8aa4e9c4fab287aed8be1;p=utils jpauserset now working. --- diff --git a/test/enterprise/src/main/java/org/wamblee/support/persistence/TransactionProxyFactory.java b/test/enterprise/src/main/java/org/wamblee/support/persistence/TransactionProxyFactory.java index 4e72f484..d3d2884b 100644 --- a/test/enterprise/src/main/java/org/wamblee/support/persistence/TransactionProxyFactory.java +++ b/test/enterprise/src/main/java/org/wamblee/support/persistence/TransactionProxyFactory.java @@ -20,6 +20,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import javax.management.RuntimeErrorException; import javax.persistence.EntityManager; import org.wamblee.support.ThreadSpecificProxyFactory; @@ -29,8 +30,8 @@ import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork; * This utility makes sure that each invocation on a certain interface is * carried out within a JPA unit of work. * - * Use {@link #getTransactionScopedEntityManager()} to get the transaction scoped - * entity manager to pass to services. + * Use {@link #getTransactionScopedEntityManager()} to get the transaction + * scoped entity manager to pass to services. * * @param T * Type of interface to proxy. @@ -58,8 +59,15 @@ public class TransactionProxyFactory { ENTITY_MANAGER.set(aEm); return aMethod.invoke(service, aArgs); } catch (InvocationTargetException e) { - throw (Exception)e.getCause(); - } finally { + Throwable cause = e.getCause(); + if (cause instanceof Exception) { + throw (Exception) cause; + } else if (cause instanceof Error) { + throw (Error) cause; + } + // last resort. + throw new RuntimeException(e); + } finally { ENTITY_MANAGER.set(null); } } @@ -68,9 +76,9 @@ public class TransactionProxyFactory { } - private static final ThreadSpecificProxyFactory ENTITY_MANAGER = - new ThreadSpecificProxyFactory(EntityManager.class); - + private static final ThreadSpecificProxyFactory ENTITY_MANAGER = new ThreadSpecificProxyFactory( + EntityManager.class); + private JpaBuilder jpaBuilder; private Class clazz; @@ -83,8 +91,8 @@ public class TransactionProxyFactory { jpaBuilder = aJpaBuilder; clazz = aClass; } - - public EntityManager getTransactionScopedEntityManager() { + + public EntityManager getTransactionScopedEntityManager() { return ENTITY_MANAGER.getProxy(); } @@ -98,8 +106,9 @@ public class TransactionProxyFactory { new Class[] { InvocationHandler.class }).newInstance( new Object[] { handler }); return proxy; - } catch (Exception e) { - throw new RuntimeException("Could not create proxy for " + clazz.getName(), e); + } catch (Exception e) { + throw new RuntimeException("Could not create proxy for " + + clazz.getName(), e); } } }