Author: adrianc
Date: Mon Apr 22 22:14:07 2013
New Revision: 1470736
URL: http://svn.apache.org/r1470736
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=1470736&r1=1470735&r2=1470736&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
Mon Apr 22 22:14:07 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=1470736&r1=1470735&r2=1470736&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
Mon Apr 22 22:14:07 2013
@@ -135,18 +135,24 @@ public class EntityTestSuite extends Ent
} 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();