You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2013/05/19 14:29:45 UTC
svn commit: r1484279 - in /ofbiz/trunk/framework/entity:
entitydef/entitymodel_test.xml src/org/ofbiz/entity/cache/EntityCache.java
src/org/ofbiz/entity/test/EntityTestSuite.java
Author: adrianc
Date: Sun May 19 12:29:44 2013
New Revision: 1484279
URL: http://svn.apache.org/r1484279
Log:
Fixed a bug in the entity engine pk cache where view entities went stale - https://issues.apache.org/jira/browse/OFBIZ-5192.
Modified:
ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
Modified: ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml?rev=1484279&r1=1484278&r2=1484279&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml (original)
+++ ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml Sun May 19 12:29:44 2013
@@ -71,6 +71,27 @@ under the License.
<prim-key field="testingTypeId"/>
</entity>
<!-- =========================================================
+ Used for testing views with pks.
+ This simulates the Party->PartyGroup and Party->Person entity relationships.
+ ========================================================= -->
+ <entity entity-name="TestingSubtype" package-name="org.ofbiz.entity.test" title="Testing Subtype Entity">
+ <field name="testingTypeId" type="id-ne" />
+ <field name="subtypeDescription" type="description" />
+ <prim-key field="testingTypeId" />
+ </entity>
+ <!-- =========================================================
+ Used for testing views with pks
+ ========================================================= -->
+ <view-entity entity-name="TestingViewPks" package-name="org.ofbiz.entity.test" title="Testing And TestingSubtype View">
+ <member-entity entity-alias="TST" entity-name="TestingType" />
+ <member-entity entity-alias="TSTSUB" entity-name="TestingSubtype" />
+ <alias-all entity-alias="TST" />
+ <alias-all entity-alias="TSTSUB" />
+ <view-link entity-alias="TST" rel-entity-alias="TSTSUB">
+ <key-map field-name="testingTypeId" />
+ </view-link>
+ </view-entity>
+ <!-- =========================================================
An entity for testing the BLOB data type
========================================================== -->
<entity entity-name="TestBlob"
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=1484279&r1=1484278&r2=1484279&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 Sun May 19 12:29:44 2013
@@ -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 Abstrac
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;
}
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=1484279&r1=1484278&r2=1484279&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 Sun May 19 12:29:44 2013
@@ -218,7 +218,20 @@ public class EntityTestSuite extends Ent
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"));
}
/*