Michael Kublin has uploaded a new change for review.

Change subject: core: Reduced un needed look up for TransactionManager
......................................................................

core: Reduced un needed look up for TransactionManager

The following patch will remove un needed look up for TransactionManager
in case of running a piece of code at scope Suppress or Required.

Change-Id: I10cc4f7e46560ff97df199582db4f3687badc030
Signed-off-by: Michael Kublin <mkub...@redhat.com>
---
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/transaction/TransactionSupport.java
1 file changed, 6 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/30/8230/1

diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/transaction/TransactionSupport.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/transaction/TransactionSupport.java
index 52d11a2..d437695 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/transaction/TransactionSupport.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/transaction/TransactionSupport.java
@@ -90,8 +90,9 @@
     public static <T> T executeInScope(TransactionScopeOption scope, 
TransactionMethod<T> code) {
         // check if we are already in rollback
 
+        TransactionManager tm = null;
         try {
-            TransactionManager tm = findTransactionManager();
+            tm = findTransactionManager();
             if (needToRollback(tm.getStatus())) {
                 throw new TransactionRolledbackLocalException(
                         "Current transaction is marked for rollback, no 
further operations are possible or desired");
@@ -104,9 +105,9 @@
         case RequiresNew:
             return executeInNewTransaction(code);
         case Suppress:
-            return executeInSuppressed(code);
+            return executeInSuppressed(tm, code);
         case Required:
-            return executeInRequired(code);
+            return executeInRequired(tm, code);
         default:
             throw new RuntimeException("Undefined Scope: " + scope);
         }
@@ -125,10 +126,8 @@
      * start with transaction from JBoss That assumption should always hold - 
if not we need to look at specific case
      * where it fails
      */
-    private static <T> T executeInRequired(TransactionMethod<T> code) {
+    private static <T> T executeInRequired(TransactionManager tm, 
TransactionMethod<T> code) {
         try {
-            TransactionManager tm = findTransactionManager();
-
             // verify we are not in a bad state
             int status = tm.getStatus();
             if (statusOneOf(status, Status.STATUS_COMMITTED, 
Status.STATUS_COMMITTING, Status.STATUS_MARKED_ROLLBACK,
@@ -153,12 +152,11 @@
     /**
      * Forces "SUPRESS" and executes the code in that scope
      */
-    private static <T> T executeInSuppressed(TransactionMethod<T> code) {
+    private static <T> T executeInSuppressed(TransactionManager tm, 
TransactionMethod<T> code) {
         T result = null;
 
         try {
 
-            TransactionManager tm = findTransactionManager();
             Transaction transaction = tm.getTransaction();
 
             if (transaction != null)


--
To view, visit http://gerrit.ovirt.org/8230
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I10cc4f7e46560ff97df199582db4f3687badc030
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Michael Kublin <mkub...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to