svn commit: r1693701 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: cache/Cache.java cache/EntityCache.java cache/EntityListCache.java transaction/TransactionListener.java transaction/TransactionUtil.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1693701 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: cache/Cache.java cache/EntityCache.java cache/EntityListCache.java transaction/TransactionListener.java transaction/TransactionUtil.java

Deepak Dixit-5
Author: deepak
Date: Sat Aug  1 10:12:39 2015
New Revision: 1693701

URL: http://svn.apache.org/r1693701
Log:
(OFBIZ-6561) Reverted r#1668267 and related changes done in r1674064, 1669537 to fix the cache issue,

Removed:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionListener.java
Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/Cache.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityListCache.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/Cache.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/Cache.java?rev=1693701&r1=1693700&r2=1693701&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/Cache.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/Cache.java Sat Aug  1 10:12:39 2015
@@ -23,24 +23,25 @@ import java.util.List;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.entity.GenericEntity;
-import org.ofbiz.entity.GenericPK;
 import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.GenericPK;
 import org.ofbiz.entity.condition.EntityCondition;
-import org.ofbiz.entity.transaction.TransactionUtil;
 
 public class Cache {
 
     public static final String module = Cache.class.getName();
 
-    private final EntityCache entityCache;
-    private final EntityListCache entityListCache;
-    private final EntityObjectCache entityObjectCache;
+    protected EntityCache entityCache;
+    protected EntityListCache entityListCache;
+    protected EntityObjectCache entityObjectCache;
+
+    protected String delegatorName;
 
     public Cache(String delegatorName) {
+        this.delegatorName = delegatorName;
         entityCache = new EntityCache(delegatorName);
-        entityListCache = new EntityListCache(delegatorName);
         entityObjectCache = new EntityObjectCache(delegatorName);
-        TransactionUtil.addListener(entityCache);
+        entityListCache = new EntityListCache(delegatorName);
     }
 
     public void clear() {

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java?rev=1693701&r1=1693700&r2=1693701&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java Sat Aug  1 10:12:39 2015
@@ -18,12 +18,7 @@
  *******************************************************************************/
 package org.ofbiz.entity.cache;
 
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.transaction.UserTransaction;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.cache.UtilCache;
@@ -31,34 +26,15 @@ import org.ofbiz.entity.GenericPK;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.condition.EntityCondition;
 import org.ofbiz.entity.model.ModelEntity;
-import org.ofbiz.entity.transaction.GenericTransactionException;
-import org.ofbiz.entity.transaction.TransactionFactoryLoader;
-import org.ofbiz.entity.transaction.TransactionListener;
-import org.ofbiz.entity.transaction.TransactionUtil;
 
-public class EntityCache extends AbstractCache<GenericPK, GenericValue> implements TransactionListener {
+public class EntityCache extends AbstractCache<GenericPK, GenericValue> {
     public static final String module = EntityCache.class.getName();
-    private final ConcurrentHashMap<UserTransaction, Map<GenericPK, GenericValue>> txCacheMap = new ConcurrentHashMap<UserTransaction, Map<GenericPK, GenericValue>>();
 
     public EntityCache(String delegatorName) {
         super(delegatorName, "entity");
     }
 
     public GenericValue get(GenericPK pk) {
-        try {
-            if (TransactionUtil.getStatus() == TransactionUtil.STATUS_ACTIVE) {
-                UserTransaction tx = TransactionFactoryLoader.getInstance().getUserTransaction();
-                Map<GenericPK, GenericValue> tempCache = txCacheMap.get(tx);
-                if (tempCache != null) {
-                    GenericValue value = tempCache.get(pk);
-                    if (value != null) {
-                        return value;
-                    }
-                }
-            }
-        } catch (GenericTransactionException e) {
-            Debug.logWarning(e, "Exception thrown while getting transaction status: ", module);
-        }
         UtilCache<GenericPK, GenericValue> entityCache = getCache(pk.getEntityName());
         if (entityCache == null) return null;
         return entityCache.get(pk);
@@ -74,46 +50,18 @@ public class EntityCache extends Abstrac
             Debug.logWarning("Tried to put a value of the " + pk.getEntityName() + " entity in the BY PRIMARY KEY cache but this entity has never-cache set to true, not caching.", module);
             return null;
         }
-        pk.setImmutable();
+
         if (entity == null) {
             entity = GenericValue.NULL_VALUE;
         } else {
             // before going into the cache, make this value immutable
             entity.setImmutable();
         }
-        try {
-            if (TransactionUtil.getStatus() == TransactionUtil.STATUS_ACTIVE) {
-                UserTransaction tx = TransactionFactoryLoader.getInstance().getUserTransaction();
-                Map<GenericPK, GenericValue> tempCache = txCacheMap.get(tx);
-                if (tempCache != null) {
-                    return tempCache.put(pk, entity);
-                }
-            }
-        } catch (GenericTransactionException e) {
-            Debug.logWarning(e, "Exception thrown while getting transaction status: ", module);
-        }
         UtilCache<GenericPK, GenericValue> entityCache = getOrCreateCache(pk.getEntityName());
         return entityCache.put(pk, entity);
     }
 
     public void remove(String entityName, EntityCondition condition) {
-        try {
-            if (TransactionUtil.getStatus() == TransactionUtil.STATUS_ACTIVE) {
-                UserTransaction tx = TransactionFactoryLoader.getInstance().getUserTransaction();
-                Map<GenericPK, GenericValue> tempCache = txCacheMap.get(tx);
-                if (tempCache != null) {
-                    for (Map.Entry<GenericPK, GenericValue> entry : tempCache.entrySet()) {
-                        GenericPK pk = entry.getKey();
-                        GenericValue value = entry.getValue();
-                        if (condition.entityMatches(value)) {
-                            tempCache.remove(pk);
-                        }
-                    }
-                }
-            }
-        } catch (GenericTransactionException e) {
-            Debug.logWarning(e, "Exception thrown while getting transaction status: ", module);
-        }
         UtilCache<GenericPK, GenericValue> entityCache = getCache(entityName);
         if (entityCache == null) return;
         for (GenericPK pk: entityCache.getCacheLineKeys()) {
@@ -128,17 +76,6 @@ public class EntityCache extends Abstrac
     }
 
     public GenericValue remove(GenericPK pk) {
-        try {
-            if (TransactionUtil.getStatus() == TransactionUtil.STATUS_ACTIVE) {
-                UserTransaction tx = TransactionFactoryLoader.getInstance().getUserTransaction();
-                Map<GenericPK, GenericValue> tempCache = txCacheMap.get(tx);
-                if (tempCache != null) {
-                    return tempCache.remove(pk);
-                }
-            }
-        } catch (GenericTransactionException e) {
-            Debug.logWarning(e, "Exception thrown while getting transaction status: ", module);
-        }
         UtilCache<GenericPK, GenericValue> entityCache = getCache(pk.getEntityName());
         if (Debug.verboseOn()) Debug.logVerbose("Removing from EntityCache with PK [" + pk + "], will remove from this cache: " + (entityCache == null ? "[No cache found to remove from]" : entityCache.getName()), module);
         if (entityCache == null) return null;
@@ -154,59 +91,4 @@ public class EntityCache extends Abstrac
         if (Debug.verboseOn()) Debug.logVerbose("Removing from EntityCache with PK [" + pk + "], found this in the cache: " + retVal, module);
         return retVal;
     }
-
-    @Override
-    public void clear() {
-        try {
-            if (TransactionUtil.getStatus() == TransactionUtil.STATUS_ACTIVE) {
-                UserTransaction tx = TransactionFactoryLoader.getInstance().getUserTransaction();
-                txCacheMap.remove(tx);
-            }
-        } catch (GenericTransactionException e) {
-            Debug.logWarning(e, "Exception thrown while getting transaction status: ", module);
-        }
-        super.clear();
-    }
-
-    @Override
-    public void remove(String entityName) {
-        try {
-            if (TransactionUtil.getStatus() == TransactionUtil.STATUS_ACTIVE) {
-                UserTransaction tx = TransactionFactoryLoader.getInstance().getUserTransaction();
-                Map<GenericPK, GenericValue> tempCache = txCacheMap.get(tx);
-                if (tempCache != null) {
-                    for (GenericPK pk : tempCache.keySet()) {
-                        if (pk.getEntityName().equals(entityName)) {
-                            tempCache.remove(pk);
-                        }
-                    }
-                }
-            }
-        } catch (GenericTransactionException e) {
-            Debug.logWarning(e, "Exception thrown while getting transaction status: ", module);
-        }
-        super.remove(entityName);
-    }
-
-    @Override
-    public void update(UserTransaction tx, EventType notificationType) {
-        switch (notificationType) {
-            case BEGIN:
-                txCacheMap.put(tx, new HashMap<GenericPK, GenericValue>());
-                break;
-            case COMMIT:
-                Map<GenericPK, GenericValue> tempCache = txCacheMap.remove(tx);
-                if (tempCache != null) {
-                    for (Map.Entry<GenericPK, GenericValue> entry : tempCache.entrySet()) {
-                        GenericPK pk = entry.getKey();
-                        GenericValue value = entry.getValue();
-                        UtilCache<GenericPK, GenericValue> entityCache = getOrCreateCache(pk.getEntityName());
-                        entityCache.put(pk, value);
-                    }
-                }
-                break;
-            case ROLLBACK:
-                txCacheMap.remove(tx);
-        }
-    }
 }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityListCache.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityListCache.java?rev=1693701&r1=1693700&r2=1693701&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityListCache.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityListCache.java Sat Aug  1 10:12:39 2015
@@ -21,22 +21,18 @@ package org.ofbiz.entity.cache;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
-import javax.transaction.UserTransaction;
-
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.condition.EntityCondition;
 import org.ofbiz.entity.model.ModelEntity;
 import org.ofbiz.entity.util.EntityUtil;
-import org.ofbiz.entity.transaction.TransactionListener;
 
-public class EntityListCache extends AbstractEntityConditionCache<Object, List<GenericValue>> implements TransactionListener {
+
+public class EntityListCache extends AbstractEntityConditionCache<Object, List<GenericValue>> {
 
     public static final String module = EntityListCache.class.getName();
-    private final ConcurrentHashMap<UserTransaction, Map<Object, List<GenericValue>>> txCacheMap = new ConcurrentHashMap<UserTransaction, Map<Object, List<GenericValue>>>();
 
     public EntityListCache(String delegatorName) {
         super(delegatorName, "entity-list");
@@ -91,28 +87,4 @@ public class EntityListCache extends Abs
     public static final Object getOrderByKey(List<String> orderBy) {
         return orderBy != null ? (Object) orderBy : "{null}";
     }
-
-    @Override
-    public void update(UserTransaction tx, EventType notificationType) {
-        /*
-        switch (notificationType) {
-            case BEGIN:
-                txCacheMap.put(tx, new HashMap<GenericPK, GenericValue>());
-                break;
-            case COMMIT:
-                Map<Object, List<GenericValue>> tempCache = txCacheMap.remove(tx);
-                if (tempCache != null) {
-                    for (Map.Entry<GenericPK, GenericValue> entry : tempCache.entrySet()) {
-                        GenericPK pk = entry.getKey();
-                        GenericValue value = entry.getValue();
-                        UtilCache<GenericPK, GenericValue> entityCache = getOrCreateCache(pk.getEntityName());
-                        entityCache.put(pk, value);
-                    }
-                }
-                break;
-            case ROLLBACK:
-                txCacheMap.remove(tx);
-        }
-        */
-    }
 }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java?rev=1693701&r1=1693700&r2=1693701&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java Sat Aug  1 10:12:39 2015
@@ -27,7 +27,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Callable;
-import java.util.concurrent.CopyOnWriteArrayList;
 
 import javax.sql.XAConnection;
 import javax.transaction.HeuristicMixedException;
@@ -79,14 +78,7 @@ public class TransactionUtil implements
     // in order to improve performance allThreadsTransactionBeginStack and allThreadsTransactionBeginStackSave are only maintained when logging level INFO is on
     private static Map<Long, Exception> allThreadsTransactionBeginStack = Collections.<Long, Exception>synchronizedMap(new HashMap<Long, Exception>());
     private static Map<Long, List<Exception>> allThreadsTransactionBeginStackSave = Collections.<Long, List<Exception>>synchronizedMap(new HashMap<Long, List<Exception>>());
-    private static List<TransactionListener> listeners = new CopyOnWriteArrayList<TransactionListener>();
 
-    public static void addListener(TransactionListener listener) {
-        if (listener != null && !listeners.contains(listener)) {
-            listeners.add(listener);
-        }
-    }
-    
     public static <V> V doNewTransaction(Callable<V> callable, String ifErrorMessage, int timeout, boolean printException) throws GenericEntityException {
         return noTransaction(inTransaction(callable, ifErrorMessage, timeout, printException)).call();
     }
@@ -171,9 +163,7 @@ public class TransactionUtil implements
                         Debug.logError(e, module);
                     }
                 }
-                for (TransactionListener listener : listeners) {
-                    listener.update(ut, TransactionListener.EventType.BEGIN);
-                }
+
                 return true;
             } catch (NotSupportedException e) {
                 throw new GenericTransactionException("Not Supported error, could not begin transaction (probably a nesting problem)", e);
@@ -262,9 +252,7 @@ public class TransactionUtil implements
                     // clear out the stack too
                     clearTransactionBeginStack();
                     clearSetRollbackOnlyCause();
-                    for (TransactionListener listener : listeners) {
-                        listener.update(ut, TransactionListener.EventType.COMMIT);
-                    }
+
                     Debug.logVerbose("Transaction committed", module);
                 } else {
                     Debug.logWarning("Not committing transaction, status is " + getStatusString(), module);
@@ -340,9 +328,7 @@ public class TransactionUtil implements
                     // clear out the stack too
                     clearTransactionBeginStack();
                     clearSetRollbackOnlyCause();
-                    for (TransactionListener listener : listeners) {
-                        listener.update(ut, TransactionListener.EventType.ROLLBACK);
-                    }
+
                     ut.rollback();
                     Debug.logInfo("Transaction rolled back", module);
                 } else {