svn commit: r1818478 - in /ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache: AbstractEntityConditionCache.java Cache.java EntityCache.java EntityListCache.java

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

svn commit: r1818478 - in /ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache: AbstractEntityConditionCache.java Cache.java EntityCache.java EntityListCache.java

mbrohl
Author: mbrohl
Date: Sun Dec 17 11:34:39 2017
New Revision: 1818478

URL: http://svn.apache.org/viewvc?rev=1818478&view=rev
Log:
Improved: General refactoring and code improvements, package
org.apache.ofbiz.entity.cache.
(OFBIZ-9949)

Thanks Dennis Balkir for reporting and providing the patches.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/AbstractEntityConditionCache.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/Cache.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/EntityCache.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/EntityListCache.java

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/AbstractEntityConditionCache.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/AbstractEntityConditionCache.java?rev=1818478&r1=1818477&r2=1818478&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/AbstractEntityConditionCache.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/AbstractEntityConditionCache.java Sun Dec 17 11:34:39 2017
@@ -26,7 +26,6 @@ import java.util.concurrent.ConcurrentMa
 
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.UtilMisc;
-import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.base.util.cache.UtilCache;
 import org.apache.ofbiz.entity.GenericEntity;
 import org.apache.ofbiz.entity.GenericPK;
@@ -44,7 +43,9 @@ public abstract class AbstractEntityCond
 
     protected V get(String entityName, EntityCondition condition, K key) {
         ConcurrentMap<K, V> conditionCache = getConditionCache(entityName, condition);
-        if (conditionCache == null) return null;
+        if (conditionCache == null) {
+            return null;
+        }
         return conditionCache.get(key);
     }
 
@@ -74,13 +75,17 @@ public abstract class AbstractEntityCond
 
     public void remove(String entityName, EntityCondition condition) {
         UtilCache<EntityCondition, ConcurrentMap<K, V>> cache = getCache(entityName);
-        if (cache == null) return;
+        if (cache == null) {
+            return;
+        }
         cache.remove(condition);
     }
 
     protected V remove(String entityName, EntityCondition condition, K key) {
         ConcurrentMap<K, V> conditionCache = getConditionCache(entityName, condition);
-        if (conditionCache == null) return null;
+        if (conditionCache == null) {
+            return null;
+        }
         return conditionCache.remove(key);
     }
 
@@ -90,19 +95,14 @@ public abstract class AbstractEntityCond
 
     public static final EntityCondition getFrozenConditionKey(EntityCondition condition) {
         EntityCondition frozenCondition = condition != null ? condition.freeze() : null;
-        // This is no longer needed, fixed issue with unequal conditions after freezing
-        //if (condition != null) {
-        //    if (!condition.equals(frozenCondition)) {
-        //        Debug.logWarning("Frozen condition does not equal condition:\n -=-=-=-Original=" + condition + "\n -=-=-=-Frozen=" + frozenCondition, module);
-        //        Debug.logWarning("Frozen condition not equal info: condition class=" + condition.getClass().getName() + "; frozenCondition class=" + frozenCondition.getClass().getName(), module);
-        //    }
-        //}
         return frozenCondition;
     }
 
     protected ConcurrentMap<K, V> getConditionCache(String entityName, EntityCondition condition) {
         UtilCache<EntityCondition, ConcurrentMap<K, V>> cache = getCache(entityName);
-        if (cache == null) return null;
+        if (cache == null) {
+            return null;
+        }
         return cache.get(getConditionKey(condition));
     }
 
@@ -156,7 +156,9 @@ public abstract class AbstractEntityCond
     }
 
     protected List<? extends Map<String, Object>> convert(String targetEntityName, GenericEntity entity) {
-        if (isNull(entity)) return null;
+        if (isNull(entity)) {
+            return null;
+        }
         return entity.getModelEntity().convertToViewValues(targetEntityName, entity);
     }
 
@@ -179,7 +181,6 @@ public abstract class AbstractEntityCond
             return;
         }
         for (EntityCondition condition: entityCache.getCacheLineKeys()) {
-            //Debug.logInfo("In storeHook entityName [" + entityName + "] checking against condition: " + condition, module);
             boolean shouldRemove = false;
             if (condition == null) {
                 shouldRemove = true;
@@ -196,13 +197,11 @@ public abstract class AbstractEntityCond
                     T1 oldValue = oldValueIter.next();
                     if (condition.mapMatches(getDelegator(), oldValue)) {
                         oldMatched = true;
-                        //Debug.logInfo("In storeHook, oldMatched for entityName [" + entityName + "]; shouldRemove is false", module);
                         if (newValues != null) {
                             Iterator<T2> newValueIter = newValues.iterator();
                             while (newValueIter.hasNext() && !shouldRemove) {
                                 T2 newValue = newValueIter.next();
                                 shouldRemove |= isNull(newValue) || condition.mapMatches(getDelegator(), newValue);
-                                //Debug.logInfo("In storeHook, for entityName [" + entityName + "] shouldRemove is now " + shouldRemove, module);
                             }
                         } else {
                             shouldRemove = true;
@@ -211,12 +210,13 @@ public abstract class AbstractEntityCond
                 }
                 // QUESTION: what is this? why would we do this?
                 if (!oldMatched && isPK) {
-                    //Debug.logInfo("In storeHook, for entityName [" + entityName + "] oldMatched is false and isPK is true, so setting shouldRemove to true (will remove from cache)", module);
                     shouldRemove = true;
                 }
             }
             if (shouldRemove) {
-                if (Debug.verboseOn()) Debug.logVerbose("In storeHook, matched condition, removing from cache for entityName [" + entityName + "] in cache with name [" + entityCache.getName() + "] entry with condition: " + condition, module);
+                if (Debug.verboseOn()) {
+                    Debug.logVerbose("In storeHook, matched condition, removing from cache for entityName [" + entityName + "] in cache with name [" + entityCache.getName() + "] entry with condition: " + condition, module);
+                }
                 // doesn't work anymore since this is a copy of the cache keySet, can call remove directly though with a concurrent mod exception: cacheKeyIter.remove();
                 entityCache.remove(condition);
             }

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/Cache.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/Cache.java?rev=1818478&r1=1818477&r2=1818478&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/Cache.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/Cache.java Sun Dec 17 11:34:39 2017
@@ -110,18 +110,20 @@ public class Cache {
     }
 
     public GenericValue remove(GenericEntity entity) {
-        if (Debug.verboseOn()) Debug.logVerbose("Cache remove GenericEntity: " + entity, module);
+        if (Debug.verboseOn()) {
+            Debug.logVerbose("Cache remove GenericEntity: " + entity, module);
+        }
         GenericValue oldEntity = entityCache.remove(entity.getPrimaryKey());
         // Workaround because AbstractEntityConditionCache.storeHook doesn't work.
         entityListCache.remove(entity);
         entityObjectCache.remove(entity);
-        // entityListCache.storeHook(entity, null);
-        // entityObjectCache.storeHook(entity, null);
         return oldEntity;
     }
 
     public GenericValue remove(GenericPK pk) {
-        if (Debug.verboseOn()) Debug.logVerbose("Cache remove GenericPK: " + pk, module);
+        if (Debug.verboseOn()) {
+            Debug.logVerbose("Cache remove GenericPK: " + pk, module);
+        }
         GenericValue oldEntity = entityCache.remove(pk);
         // Workaround because AbstractEntityConditionCache.storeHook doesn't work.
         entityListCache.remove(pk);

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/EntityCache.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/EntityCache.java?rev=1818478&r1=1818477&r2=1818478&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/EntityCache.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/EntityCache.java Sun Dec 17 11:34:39 2017
@@ -36,12 +36,16 @@ public class EntityCache extends Abstrac
 
     public GenericValue get(GenericPK pk) {
         UtilCache<GenericPK, GenericValue> entityCache = getCache(pk.getEntityName());
-        if (entityCache == null) return null;
+        if (entityCache == null) {
+            return null;
+        }
         return entityCache.get(pk);
     }
 
     public GenericValue put(GenericValue entity) {
-        if (entity == null) return null;
+        if (entity == null) {
+            return null;
+        }
         return put(entity.getPrimaryKey(), entity);
     }
 
@@ -63,11 +67,17 @@ public class EntityCache extends Abstrac
 
     public void remove(String entityName, EntityCondition condition) {
         UtilCache<GenericPK, GenericValue> entityCache = getCache(entityName);
-        if (entityCache == null) return;
+        if (entityCache == null) {
+            return;
+        }
         for (GenericPK pk: entityCache.getCacheLineKeys()) {
             GenericValue entity = entityCache.get(pk);
-            if (entity == null) continue;
-            if (condition.entityMatches(entity)) entityCache.remove(pk);
+            if (entity == null) {
+                continue;
+            }
+            if (condition.entityMatches(entity)) {
+                entityCache.remove(pk);
+            }
         }
     }
 
@@ -77,8 +87,12 @@ public class EntityCache extends Abstrac
 
     public GenericValue remove(GenericPK pk) {
         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;
+        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;
+        }
         GenericValue retVal = entityCache.remove(pk);
         ModelEntity model = pk.getModelEntity();
         if (model != null) {
@@ -88,7 +102,9 @@ public class EntityCache extends Abstrac
                 UtilCache.clearCache(getCacheName(targetEntityName));
             }
         }
-        if (Debug.verboseOn()) Debug.logVerbose("Removing from EntityCache with PK [" + pk + "], found this in the cache: " + retVal, module);
+        if (Debug.verboseOn()) {
+            Debug.logVerbose("Removing from EntityCache with PK [" + pk + "], found this in the cache: " + retVal, module);
+        }
         return retVal;
     }
 }

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/EntityListCache.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/EntityListCache.java?rev=1818478&r1=1818477&r2=1818478&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/EntityListCache.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/cache/EntityListCache.java Sun Dec 17 11:34:39 2017
@@ -44,13 +44,17 @@ public class EntityListCache extends Abs
 
     public List<GenericValue> get(String entityName, EntityCondition condition, List<String> orderBy) {
         ConcurrentMap<Object, List<GenericValue>> conditionCache = getConditionCache(entityName, condition);
-        if (conditionCache == null) return null;
+        if (conditionCache == null) {
+            return null;
+        }
         Object orderByKey = getOrderByKey(orderBy);
         List<GenericValue> valueList = conditionCache.get(orderByKey);
         if (valueList == null) {
             // the valueList was not found for the given ordering, so grab the first one and order it in memory
             Iterator<List<GenericValue>> it = conditionCache.values().iterator();
-            if (it.hasNext()) valueList = it.next();
+            if (it.hasNext()) {
+                valueList = it.next();
+            }
 
             if (valueList != null) {
                 // Does not need to be synchronized; if 2 threads do the same ordering,