Fixed a bug in the entity engine pk cache where view entities went stale - https://issues.apache.org/jira/browse/OFBIZ-5192.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1484279 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrian Crum
2013-05-19 12:29:44 +00:00
parent 00e0e6555d
commit fa77ee6655
3 changed files with 46 additions and 1 deletions
@@ -18,11 +18,14 @@
*******************************************************************************/
package org.ofbiz.entity.cache;
import java.util.Iterator;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.cache.UtilCache;
import org.ofbiz.entity.GenericPK;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.model.ModelEntity;
public class EntityCache extends AbstractCache<GenericPK, GenericValue> {
public static final String module = EntityCache.class.getName();
@@ -77,6 +80,14 @@ public class EntityCache extends AbstractCache<GenericPK, GenericValue> {
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) {
Iterator<String> it = model.getViewConvertorsIterator();
while (it.hasNext()) {
String targetEntityName = it.next();
UtilCache.clearCache(getCacheName(targetEntityName));
}
}
if (Debug.verboseOn()) Debug.logVerbose("Removing from EntityCache with PK [" + pk + "], found this in the cache: " + retVal, module);
return retVal;
}
@@ -218,7 +218,20 @@ public class EntityTestSuite extends EntityTestCase {
testValue.remove();
testList = delegator.findList("TestingType", testCondition, null, null, null, true);
assertEquals("Delegator findList returned empty list", 0, testList.size());
// TODO: Test view entities.
// Test view entities in the pk cache - updating an entity should clear pk caches for all view entities containing that entity.
testValue = delegator.create("TestingSubtype", "testingTypeId", "TEST-9", "subtypeDescription", "Testing Subtype #9");
assertNotNull("TestingSubtype created", testValue);
// Confirm member entity appears in the view
testValue = delegator.findOne("TestingViewPks", true, "testingTypeId", "TEST-9");
assertEquals("View retrieved from cache has the correct member description", "Testing Subtype #9", testValue.getString("subtypeDescription"));
testValue = delegator.findOne("TestingSubtype", true, "testingTypeId", "TEST-9");
// Modify member entity
testValue = (GenericValue) testValue.clone();
testValue.put("subtypeDescription", "New Testing Subtype #9");
testValue.store();
// Check if cached view contains the modification
testValue = delegator.findOne("TestingViewPks", true, "testingTypeId", "TEST-9");
assertEquals("View retrieved from cache has the correct member description", "New Testing Subtype #9", testValue.getString("subtypeDescription"));
}
/*