commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ozeigerm...@apache.org
Subject svn commit: r560557 - in /jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction: AbstractTransactionalResourceManager.java ManageableResourceManager.java TransactionException.java TransactionImpl.java
Date Sat, 28 Jul 2007 15:47:05 GMT
Author: ozeigermann
Date: Sat Jul 28 08:47:04 2007
New Revision: 560557

URL: http://svn.apache.org/viewvc?view=rev&rev=560557
Log:
Added additional prepare step to make Transaction 2PC enabled.

Modified:
    jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/AbstractTransactionalResourceManager.java
    jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/ManageableResourceManager.java
    jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/TransactionException.java
    jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/TransactionImpl.java

Modified: jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/AbstractTransactionalResourceManager.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/AbstractTransactionalResourceManager.java?view=diff&rev=560557&r1=560556&r2=560557
==============================================================================
--- jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/AbstractTransactionalResourceManager.java
(original)
+++ jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/AbstractTransactionalResourceManager.java
Sat Jul 28 08:47:04 2007
@@ -54,12 +54,7 @@
 
     @Override
     public boolean isTransactionMarkedForRollback() {
-        T txContext = getActiveTx();
-
-        if (txContext == null) {
-            throw new IllegalStateException("Active thread " + Thread.currentThread()
-                    + " not associated with a transaction!");
-        }
+        T txContext = getCheckedActiveTx();
 
         return (txContext.isMarkedForRollback());
     }
@@ -78,12 +73,7 @@
 
     @Override
     public void rollbackTransaction() {
-        T txContext = getActiveTx();
-
-        if (txContext == null) {
-            throw new IllegalStateException("Active thread " + Thread.currentThread()
-                    + " not associated with a transaction!");
-        }
+        T txContext = getCheckedActiveTx();
 
         txContext.dispose();
         setActiveTx(null);
@@ -91,12 +81,7 @@
 
     @Override
     public boolean commitTransaction() {
-        T txContext = getActiveTx();
-
-        if (txContext == null) {
-            throw new IllegalStateException("Active thread " + Thread.currentThread()
-                    + " not associated with a transaction!");
-        }
+        T txContext = getCheckedActiveTx();
 
         if (txContext.isMarkedForRollback()) {
             throw new IllegalStateException("Active thread " + Thread.currentThread()
@@ -113,18 +98,22 @@
         return activeTx.get();
     }
 
-    protected void setActiveTx(T txContext) {
-        activeTx.set(txContext);
-    }
-
-    public boolean isReadOnlyTransaction() {
+    protected T getCheckedActiveTx() {
         T txContext = getActiveTx();
 
         if (txContext == null) {
             throw new IllegalStateException("Active thread " + Thread.currentThread()
                     + " not associated with a transaction!");
         }
+        return txContext;
+    }
+    
+    protected void setActiveTx(T txContext) {
+        activeTx.set(txContext);
+    }
 
+    public boolean isReadOnlyTransaction() {
+        T txContext = getCheckedActiveTx();
         return (txContext.isReadOnly());
     }
 
@@ -183,6 +172,10 @@
         public void commit() {
 
         }
+        
+        public boolean prepare() {
+            return true;
+        }
     }
 
     public LockManager<Object, String> getLm() {
@@ -215,16 +208,20 @@
 
     }
 
+    @Override
     public void setRollbackOnly() {
-        T txContext = getActiveTx();
-
-        if (txContext == null) {
-            throw new IllegalStateException("Active thread " + Thread.currentThread()
-                    + " not associated with a transaction!");
-        }
+        T txContext = getCheckedActiveTx();
         txContext.markForRollback();
 
     }
+
+    @Override
+    public boolean prepareTransaction() {
+        T txContext = getCheckedActiveTx();
+        return txContext.prepare();
+        
+    }
+
 
 
 }

Modified: jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/ManageableResourceManager.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/ManageableResourceManager.java?view=diff&rev=560557&r1=560556&r2=560557
==============================================================================
--- jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/ManageableResourceManager.java
(original)
+++ jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/ManageableResourceManager.java
Sat Jul 28 08:47:04 2007
@@ -22,6 +22,8 @@
     void setRollbackOnly();
 
     boolean commitCanFail();
+    
+    boolean prepareTransaction();
 
     /**
      * Checks whether this transaction has been marked to allow a rollback as

Modified: jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/TransactionException.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/TransactionException.java?view=diff&rev=560557&r1=560556&r2=560557
==============================================================================
--- jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/TransactionException.java
(original)
+++ jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/TransactionException.java
Sat Jul 28 08:47:04 2007
@@ -24,7 +24,7 @@
     private static final long serialVersionUID = 7650329971392401844L;
 
     public enum Code {
-        COMMIT_FAILED, ROLLBACK_ONLY
+        COMMIT_FAILED, ROLLBACK_ONLY, PREPARE_FAILED
     }
 
     protected Code code;

Modified: jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/TransactionImpl.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/TransactionImpl.java?view=diff&rev=560557&r1=560556&r2=560557
==============================================================================
--- jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/TransactionImpl.java
(original)
+++ jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/TransactionImpl.java
Sat Jul 28 08:47:04 2007
@@ -47,6 +47,10 @@
         if (isRollbackOnly()) {
             throw new TransactionException(TransactionException.Code.ROLLBACK_ONLY);
         }
+        if (!prepare()) {
+            throw new TransactionException(TransactionException.Code.PREPARE_FAILED);
+        }
+
         for (ManageableResourceManager manager : rms) {
             if (!manager.isReadOnlyTransaction()) {
                 try {
@@ -97,4 +101,11 @@
         lm.startWork(timeout, unit);
     }
 
+    protected boolean prepare() {
+        for (ManageableResourceManager manager : rms) {
+            if (!manager.prepareTransaction())
+                return false;
+        }
+        return true;
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message