tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-2048 @Transactional(NEVER) should throw TransactionalException from within a tx
Date Fri, 02 Jun 2017 09:23:28 GMT
Repository: tomee
Updated Branches:
  refs/heads/master f271f89a9 -> 64704e8fb


TOMEE-2048 @Transactional(NEVER) should throw TransactionalException from within a tx


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/64704e8f
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/64704e8f
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/64704e8f

Branch: refs/heads/master
Commit: 64704e8fb37a6e46b091b91df6aa3e4f896a716a
Parents: f271f89
Author: rmannibucau <rmannibucau@apache.org>
Authored: Fri Jun 2 11:23:22 2017 +0200
Committer: rmannibucau <rmannibucau@apache.org>
Committed: Fri Jun 2 11:23:22 2017 +0200

----------------------------------------------------------------------
 .../cdi/transactional/NeverInterceptor.java     |  8 +++++-
 .../cdi/transactional/TransactionalTest.java    | 28 ++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/64704e8f/container/openejb-core/src/main/java/org/apache/openejb/cdi/transactional/NeverInterceptor.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/transactional/NeverInterceptor.java
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/transactional/NeverInterceptor.java
index 0701416..8e45e10 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/transactional/NeverInterceptor.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/transactional/NeverInterceptor.java
@@ -26,6 +26,8 @@ import javax.interceptor.AroundInvoke;
 import javax.interceptor.Interceptor;
 import javax.interceptor.InvocationContext;
 import javax.transaction.Transactional;
+import javax.transaction.TransactionalException;
+import java.rmi.RemoteException;
 
 @Interceptor
 @Transactional(Transactional.TxType.NEVER)
@@ -33,7 +35,11 @@ import javax.transaction.Transactional;
 public class NeverInterceptor extends InterceptorBase {
     @AroundInvoke
     public Object intercept(final InvocationContext ic) throws Exception {
-        return super.intercept(ic);
+        try {
+            return super.intercept(ic);
+        } catch (final RemoteException re) {
+            throw new TransactionalException(re.getMessage(), re);
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tomee/blob/64704e8f/container/openejb-core/src/test/java/org/apache/openejb/cdi/transactional/TransactionalTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/cdi/transactional/TransactionalTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/cdi/transactional/TransactionalTest.java
index 468754b..c5362c0 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/cdi/transactional/TransactionalTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/cdi/transactional/TransactionalTest.java
@@ -41,6 +41,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 
 import static javax.transaction.Transactional.TxType.MANDATORY;
+import static javax.transaction.Transactional.TxType.NEVER;
 import static javax.transaction.Transactional.TxType.NOT_SUPPORTED;
 import static javax.transaction.Transactional.TxType.REQUIRED;
 import static javax.transaction.Transactional.TxType.REQUIRES_NEW;
@@ -71,6 +72,23 @@ public class TransactionalTest {
         assertNull(OpenEJB.getTransactionManager().getTransaction());
     }
 
+    @Test
+    public void neverInTx() throws SystemException {
+        assertNull(OpenEJB.getTransactionManager().getTransaction());
+        try {
+            bean.createTx(new Runnable() {
+                @Override
+                public void run() {
+                    bean.never();
+                }
+            });
+            fail();
+        } catch (final TransactionalException e) {
+            // expected
+        }
+        assertNull(OpenEJB.getTransactionManager().getTransaction());
+    }
+
     @Test(expected = TransactionalException.class)
     public void mandatoryKO() {
         for (int i = 0; i < 2; i++) {
@@ -409,6 +427,16 @@ public class TransactionalTest {
         }
 
         @Transactional(REQUIRED)
+        public void createTx(Runnable runnable) {
+            runnable.run();
+        }
+
+        @Transactional(NEVER)
+        public void never() {
+            // no-op
+        }
+
+        @Transactional(REQUIRED)
         public void runtimeChecked(Runnable runnable) throws AnException {
             runnable.run();
             throw new AnException();


Mime
View raw message