svn commit: r1471284 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: cache/EntityListCache.java test/EntityTestSuite.java

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

svn commit: r1471284 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: cache/EntityListCache.java test/EntityTestSuite.java

adrianc
Author: adrianc
Date: Wed Apr 24 08:11:53 2013
New Revision: 1471284

URL: http://svn.apache.org/r1471284
Log:
GenericEntity instances coming from EntityListCache are now immutable.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityListCache.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java

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=1471284&r1=1471283&r2=1471284&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 Wed Apr 24 08:11:53 2013
@@ -20,10 +20,13 @@ package org.ofbiz.entity.cache;
 
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ConcurrentMap;
 
+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;
 
 public class EntityListCache extends AbstractEntityConditionCache<Object, List<GenericValue>> {
@@ -64,7 +67,16 @@ public class EntityListCache extends Abs
     }
 
     public List<GenericValue> put(String entityName, EntityCondition condition, List<String> orderBy, List<GenericValue> entities) {
-        return super.put(entityName, getFrozenConditionKey(condition), getOrderByKey(orderBy), entities);
+        ModelEntity entity = this.getDelegator().getModelEntity(entityName);
+        if (entity.getNeverCache()) {
+            Debug.logWarning("Tried to put a value of the " + entityName + " entity in the cache but this entity has never-cache set to true, not caching.", module);
+            return null;
+        }
+        for (GenericValue memberValue : entities) {
+            memberValue.setImmutable();
+        }
+        Map<Object, List<GenericValue>> conditionCache = getOrCreateConditionCache(entityName, getFrozenConditionKey(condition));
+        return conditionCache.put(getOrderByKey(orderBy), entities);
     }
 
     public List<GenericValue> remove(String entityName, EntityCondition condition, List<String> orderBy) {

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java?rev=1471284&r1=1471283&r2=1471284&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java Wed Apr 24 08:11:53 2013
@@ -124,25 +124,37 @@ public class EntityTestSuite extends Ent
         // Test primary key cache
         GenericValue testValue = delegator.findOne("TestingType", true, "testingTypeId", "TEST-2");
         assertEquals("Retrieved from cache value has the correct description", "Testing Type #2", testValue.getString("description"));
+        // Test immutable
         try {
             testValue.put("description", "New Testing Type #2");
             testValue.store();
             fail("Modified an immutable GenericValue");
         } catch (IllegalStateException e) {
         }
+        try {
+            testValue.remove("description");
+            fail("Modified an immutable GenericValue");
+        } catch (UnsupportedOperationException e) {
+        }
         // Test entity condition cache
-        /* Commenting this out for now because the tests fail due to flaws in the EntityListCache implementation.
         EntityCondition testCondition = EntityCondition.makeCondition("description", EntityOperator.EQUALS, "Testing Type #2");
         List<GenericValue> testList = delegator.findList("TestingType", testCondition, null, null, null, true);
         assertEquals("Delegator findList returned one value", 1, testList.size());
         testValue = testList.get(0);
         assertEquals("Retrieved from cache value has the correct description", "Testing Type #2", testValue.getString("description"));
+        // Test immutable
         try {
             testValue.put("description", "New Testing Type #2");
             testValue.store();
             fail("Modified an immutable GenericValue");
         } catch (IllegalStateException e) {
         }
+        try {
+            testValue.remove("description");
+            fail("Modified an immutable GenericValue");
+        } catch (UnsupportedOperationException e) {
+        }
+        /* Commenting this out for now because the tests fail due to flaws in the EntityListCache implementation.
         testValue = (GenericValue) testValue.clone();
         testValue.put("description", "New Testing Type #2");
         testValue.store();