You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/03/01 13:40:16 UTC

[23/37] incubator-ignite git commit: # ignite-322: move txTransactions rollback at finally-block

# ignite-322: move txTransactions rollback at finally-block


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/5ed43d19
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/5ed43d19
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/5ed43d19

Branch: refs/heads/ignite-239
Commit: 5ed43d19995f70e0bd338c74626d5236be3b639a
Parents: 4e57996
Author: Artem Shutak <as...@gridgain.com>
Authored: Thu Feb 26 13:18:12 2015 +0300
Committer: Artem Shutak <as...@gridgain.com>
Committed: Thu Feb 26 13:18:12 2015 +0300

----------------------------------------------------------------------
 .../HibernateReadWriteAccessStrategy.java       | 81 +++++++++++++++-----
 1 file changed, 63 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5ed43d19/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
index 1b083a1..21320f3 100644
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
+++ b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
@@ -74,30 +74,46 @@ public class HibernateReadWriteAccessStrategy extends HibernateAccessStrategyAda
 
     /** {@inheritDoc} */
     @Override protected Object get(Object key) throws CacheException {
+        boolean success = false;
+        
         try {
-            return cache.get(key);
+            Object o = cache.get(key);
+            
+            success = true;
+            
+            return o;
         }
         catch (IgniteCheckedException e) {
-            rollbackCurrentTx();
-
             throw new CacheException(e);
         }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
     }
 
     /** {@inheritDoc} */
     @Override protected void putFromLoad(Object key, Object val) throws CacheException {
+        boolean success = false;
+        
         try {
             cache.putx(key, val);
+            
+            success = true;
         }
         catch (IgniteCheckedException e) {
-            rollbackCurrentTx();
-
             throw new CacheException(e);
         }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
     }
 
     /** {@inheritDoc} */
     @Override protected SoftLock lock(Object key) throws CacheException {
+        boolean success = false;
+        
         try {
             TxContext ctx = txCtx.get();
 
@@ -107,29 +123,39 @@ public class HibernateReadWriteAccessStrategy extends HibernateAccessStrategyAda
             lockKey(key);
 
             ctx.locked(key);
+            
+            success = true;
 
             return null;
         }
         catch (IgniteCheckedException e) {
-            rollbackCurrentTx();
-
             throw new CacheException(e);
         }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
     }
 
     /** {@inheritDoc} */
     @Override protected void unlock(Object key, SoftLock lock) throws CacheException {
+        boolean success = false;
+        
         try {
             TxContext ctx = txCtx.get();
 
             if (ctx != null)
                 unlock(ctx, key);
+            
+            success = true;
         }
         catch (Exception e) {
-            rollbackCurrentTx();
-
             throw new CacheException(e);
         }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
     }
 
     /** {@inheritDoc} */
@@ -139,6 +165,9 @@ public class HibernateReadWriteAccessStrategy extends HibernateAccessStrategyAda
 
     /** {@inheritDoc} */
     @Override protected boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException {
+        boolean success = false;
+        boolean res = false;
+        
         try {
             TxContext ctx = txCtx.get();
 
@@ -146,17 +175,21 @@ public class HibernateReadWriteAccessStrategy extends HibernateAccessStrategyAda
                 cache.putx(key, val);
 
                 unlock(ctx, key);
-
-                return true;
+                
+                res = true;
             }
+            
+            success = true;
 
-            return false;
+            return res;
         }
         catch (Exception e) {
-            rollbackCurrentTx();
-
             throw new CacheException(e);
         }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
     }
 
     /** {@inheritDoc} */
@@ -166,31 +199,43 @@ public class HibernateReadWriteAccessStrategy extends HibernateAccessStrategyAda
 
     /** {@inheritDoc} */
     @Override protected boolean afterInsert(Object key, Object val) throws CacheException {
+        boolean success = false;
+        
         try {
             cache.putx(key, val);
 
+            success = true;
+            
             return true;
         }
         catch (IgniteCheckedException e) {
-            rollbackCurrentTx();
-
             throw new CacheException(e);
         }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
     }
 
     /** {@inheritDoc} */
     @Override protected void remove(Object key) throws CacheException {
+        boolean success = false;
+        
         try {
             TxContext ctx = txCtx.get();
 
             if (ctx != null)
                 cache.removex(key);
+            
+            success = true;
         }
         catch (IgniteCheckedException e) {
-            rollbackCurrentTx();
-
             throw new CacheException(e);
         }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
     }
 
     /**