aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1704115 - in /aries/trunk/jpa/jpa-support/src: main/java/org/apache/aries/jpa/support/osgi/impl/EmProxy.java test/java/org/apache/aries/jpa/support/osgi/impl/EmfTrackerTest.java
Date Sun, 20 Sep 2015 10:01:34 GMT
Author: cschneider
Date: Sun Sep 20 10:01:33 2015
New Revision: 1704115

URL: http://svn.apache.org/viewvc?rev=1704115&view=rev
Log:
[ARIES-1412] unwrap InvocationTargetException

Modified:
    aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/EmProxy.java
    aries/trunk/jpa/jpa-support/src/test/java/org/apache/aries/jpa/support/osgi/impl/EmfTrackerTest.java

Modified: aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/EmProxy.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/EmProxy.java?rev=1704115&r1=1704114&r2=1704115&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/EmProxy.java
(original)
+++ aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/EmProxy.java
Sun Sep 20 10:01:33 2015
@@ -19,6 +19,7 @@
 package org.apache.aries.jpa.support.osgi.impl;
 
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import javax.persistence.EntityManager;
@@ -38,7 +39,12 @@ public class EmProxy implements Invocati
         if (em == null) {
             throw new IllegalStateException("EntityManager not available. Make sure you run
in an @Transactional method");
         }
-        return method.invoke(em, args);
+        try {
+            return method.invoke(em, args);
+        } catch (InvocationTargetException ex) {
+            InvocationTargetException iex = (InvocationTargetException)ex;
+            throw iex.getTargetException();
+        }
     }
 
 }

Modified: aries/trunk/jpa/jpa-support/src/test/java/org/apache/aries/jpa/support/osgi/impl/EmfTrackerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-support/src/test/java/org/apache/aries/jpa/support/osgi/impl/EmfTrackerTest.java?rev=1704115&r1=1704114&r2=1704115&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-support/src/test/java/org/apache/aries/jpa/support/osgi/impl/EmfTrackerTest.java
(original)
+++ aries/trunk/jpa/jpa-support/src/test/java/org/apache/aries/jpa/support/osgi/impl/EmfTrackerTest.java
Sun Sep 20 10:01:33 2015
@@ -23,12 +23,16 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doThrow;
 
 import java.util.Dictionary;
 
+import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceException;
 import javax.persistence.spi.PersistenceUnitTransactionType;
 
+import org.apache.aries.jpa.supplier.EmSupplier;
 import org.apache.aries.jpa.support.osgi.impl.EMFTracker;
 import org.apache.aries.jpa.support.osgi.impl.EMFTracker.TrackedEmf;
 import org.junit.Assert;
@@ -76,4 +80,15 @@ public class EmfTrackerTest {
         verify(emProxyReg, times(1)).unregister();
         verify(puContext, times(1)).ungetService(ref);
     }
+    
+    @Test(expected=PersistenceException.class)
+    public void testOriginalExceptionThrown() {
+        EmSupplier emSupplier = mock(EmSupplier.class);
+        EntityManager em = mock(EntityManager.class);
+        when(emSupplier.get()).thenReturn(em);
+        doThrow(new PersistenceException("Message")).when(em).flush();
+
+        EntityManager emProxy = EMFTracker.createProxy(emSupplier);
+        emProxy.flush();
+    }
 }



Mime
View raw message