aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggrzy...@apache.org
Subject [aries] 01/01: [ARIES-2050] Different coordination management across TX behavior boundaries
Date Mon, 14 Jun 2021 07:30:47 GMT
This is an automated email from the ASF dual-hosted git repository.

ggrzybek pushed a commit to branch ARIES-2050
in repository https://gitbox.apache.org/repos/asf/aries.git

commit 6a2cf9c155c3d7bb838a2517aa8687c89012a0bf
Author: Grzegorz Grzybek <gr.grzybek@gmail.com>
AuthorDate: Mon Jun 14 09:09:16 2021 +0200

    [ARIES-2050] Different coordination management across TX behavior boundaries
---
 .../apache/aries/transaction/TransactionAttribute.java    | 14 +++++++-------
 .../org/apache/aries/transaction/TransactionToken.java    | 15 ++++++++++++++-
 .../org/apache/aries/transaction/TxInterceptorImpl.java   | 11 ++++++++---
 transaction/transaction-itests/pom.xml                    |  2 +-
 4 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionAttribute.java
b/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionAttribute.java
index ff1d32c..c04957b 100644
--- a/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionAttribute.java
+++ b/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionAttribute.java
@@ -42,7 +42,7 @@ public enum TransactionAttribute {
           throw new IllegalStateException("No transaction present when calling method that
mandates a transaction.");
         }
 
-        return new TransactionToken(man.getTransaction(), null, MANDATORY);
+        return new TransactionToken(man.getTransaction(), null, MANDATORY, false, false);
       }
     },
     NEVER
@@ -54,7 +54,7 @@ public enum TransactionAttribute {
           throw new IllegalStateException("Transaction present when calling method that forbids
a transaction.");
         }
 
-        return new TransactionToken(null, null, NEVER);
+        return new TransactionToken(null, null, NEVER, false, false);
       }
     },
     NOT_SUPPORTED
@@ -63,10 +63,10 @@ public enum TransactionAttribute {
       public TransactionToken begin(TransactionManager man) throws SystemException
       {
         if (man.getStatus() == Status.STATUS_ACTIVE) {
-          return new TransactionToken(null, man.suspend(), this);
+          return new TransactionToken(null, man.suspend(), NOT_SUPPORTED, false, true);
         }
 
-        return new TransactionToken(null, null, NOT_SUPPORTED);
+        return new TransactionToken(null, null, NOT_SUPPORTED, false, false);
       }
 
       @Override
@@ -86,10 +86,10 @@ public enum TransactionAttribute {
       {
         if (man.getStatus() == Status.STATUS_NO_TRANSACTION) {
           man.begin();
-          return new TransactionToken(man.getTransaction(), null, REQUIRED, true);
+          return new TransactionToken(man.getTransaction(), null, REQUIRED, true, true);
         }
 
-        return new TransactionToken(man.getTransaction(), null, REQUIRED);
+        return new TransactionToken(man.getTransaction(), null, REQUIRED, false, false);
       }
 
       @Override
@@ -123,7 +123,7 @@ public enum TransactionAttribute {
           man.resume(suspendedTransaction);
           throw e;
         }
-        return new TransactionToken(man.getTransaction(), suspendedTransaction, REQUIRES_NEW,
true);
+        return new TransactionToken(man.getTransaction(), suspendedTransaction, REQUIRES_NEW,
true, true);
       }
 
       @Override
diff --git a/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java
b/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java
index 9b7137c..4eaf1f8 100644
--- a/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java
+++ b/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java
@@ -28,6 +28,7 @@ public class TransactionToken
    private Transaction suspendedTransaction;
    private TransactionAttribute transactionAttribute;
    private boolean isCompletionAllowed;
+   private boolean requiresNewCoordination;
    private Coordination coordination;
    
    public TransactionToken(Transaction activeTransaction, Transaction suspendedTransaction,
@@ -39,10 +40,18 @@ public class TransactionToken
    TransactionToken(Transaction activeTransaction, Transaction suspendedTransaction,
            TransactionAttribute transactionAttribute, boolean isCompletionAllowed)
    {
+       this(activeTransaction, suspendedTransaction, transactionAttribute, isCompletionAllowed,
true);
+   }
+
+   TransactionToken(Transaction activeTransaction, Transaction suspendedTransaction,
+           TransactionAttribute transactionAttribute, boolean isCompletionAllowed,
+            boolean requiresNewCoordination)
+   {
        this.activeTransaction = activeTransaction;
        this.suspendedTransaction = suspendedTransaction;
        this.transactionAttribute = transactionAttribute;
        this.isCompletionAllowed = isCompletionAllowed;
+       this.requiresNewCoordination = requiresNewCoordination;
    }
 
    public Transaction getActiveTransaction() {
@@ -68,7 +77,11 @@ public class TransactionToken
    public boolean isCompletionAllowed() {
        return isCompletionAllowed;
    }
-   
+
+   public boolean requiresNewCoordination() {
+       return requiresNewCoordination;
+   }
+
    public Coordination getCoordination() {
     return coordination;
    }
diff --git a/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
b/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
index 8974a40..60d9a8c 100644
--- a/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
+++ b/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
@@ -61,9 +61,14 @@ public class TxInterceptorImpl implements Interceptor {
 
         LOGGER.debug("PreCall for bean {}, method {} with tx strategy {}.", getCmId(cm),
m.getName(), txAttribute);
         TransactionToken token = txAttribute.begin(tm);
-        String coordName = "txInterceptor." + m.getDeclaringClass().getName() + "." + m.getName();
-        Coordination coord = coordinator.begin(coordName , 0);
-        token.setCoordination(coord);
+        if (token.requiresNewCoordination()) {
+            String coordName = "txInterceptor." + m.getDeclaringClass().getName() + "." +
m.getName();
+            Coordination coord = coordinator.begin(coordName , 0);
+            // @javax.transaction.Transactional is only part of 1.2 and even if it's about
time that all previous
+            // JTA versions should be forgotten, we can't rely on it...
+            coord.getVariables().put(Transaction.class, txAttribute.name());
+            token.setCoordination(coord);
+        }
         return token;
     }
 
diff --git a/transaction/transaction-itests/pom.xml b/transaction/transaction-itests/pom.xml
index abb3482..c014f05 100644
--- a/transaction/transaction-itests/pom.xml
+++ b/transaction/transaction-itests/pom.xml
@@ -41,7 +41,7 @@
 
     <properties>
         <exam.version>3.4.0</exam.version>
-        <url.version>1.6.0</url.version>
+        <url.version>2.6.7</url.version>
     </properties>
 
     <dependencyManagement>

Mime
View raw message