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 2014/08/30 05:04:35 UTC
svn commit: r1621415 - in /ofbiz/branches/release13.07: ./
framework/entity/src/org/ofbiz/entity/GenericDelegator.java
framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
Author: adrianc
Date: Sat Aug 30 03:04:35 2014
New Revision: 1621415
URL: http://svn.apache.org/r1621415
Log:
Merged revision(s) 1621413 from ofbiz/trunk:
Fixed bugs in GenericDelegator.java - storeByCondition and removeByCondition did not update the cache, resulting in stale cache entries.
Modified:
ofbiz/branches/release13.07/ (props changed)
ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
Propchange: ofbiz/branches/release13.07/
------------------------------------------------------------------------------
Merged /ofbiz/trunk:r1621413
Modified: ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=1621415&r1=1621414&r2=1621415&view=diff
==============================================================================
--- ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original)
+++ ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Sat Aug 30 03:04:35 2014
@@ -1112,10 +1112,6 @@ public class GenericDelegator implements
beganTransaction = TransactionUtil.begin();
}
- if (doCacheClear) {
- // always clear cache before the operation
- this.clearCacheLineByCondition(entityName, condition);
- }
ModelEntity modelEntity = getModelReader().getModelEntity(entityName);
GenericHelper helper = getEntityHelper(entityName);
@@ -1125,6 +1121,9 @@ public class GenericDelegator implements
}
int rowsAffected = helper.removeByCondition(modelEntity, condition);
+ if (rowsAffected > 0 && doCacheClear) {
+ this.clearCacheLine(entityName);
+ }
if (testMode) {
for (GenericValue entity : removedEntities) {
@@ -1213,10 +1212,6 @@ public class GenericDelegator implements
beganTransaction = TransactionUtil.begin();
}
- if (doCacheClear) {
- // always clear cache before the operation
- this.clearCacheLineByCondition(entityName, condition);
- }
ModelEntity modelEntity = getModelReader().getModelEntity(entityName);
GenericHelper helper = getEntityHelper(entityName);
@@ -1226,6 +1221,9 @@ public class GenericDelegator implements
}
int rowsAffected = helper.storeByCondition(modelEntity, fieldsToSet, condition);
+ if (rowsAffected > 0 && doCacheClear) {
+ this.clearCacheLine(entityName);
+ }
if (testMode) {
for (GenericValue entity : updatedEntities) {
Modified: ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java?rev=1621415&r1=1621414&r2=1621415&view=diff
==============================================================================
--- ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java (original)
+++ ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java Sat Aug 30 03:04:35 2014
@@ -54,6 +54,8 @@ import org.ofbiz.entity.transaction.Tran
import org.ofbiz.entity.util.EntityFindOptions;
import org.ofbiz.entity.util.EntityListIterator;
import org.ofbiz.entity.util.EntitySaxReader;
+import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.entity.util.SequenceUtil;
public class EntityTestSuite extends EntityTestCase {
@@ -195,8 +197,21 @@ public class EntityTestSuite extends Ent
testValue.store();
testValue = delegator.findOne("TestingType", true, "testingTypeId", "TEST-CACHE-1");
assertEquals("Retrieved from cache value has the correct description", "New Testing Type #Cache-1", testValue.getString("description"));
+ // Test storeByCondition updates the cache
+ testValue = EntityUtil.getFirst(delegator.findByAnd("TestingType", UtilMisc.toMap("testingTypeId", "TEST-CACHE-1"), null, true));
+ EntityCondition storeByCondition = EntityCondition.makeCondition(UtilMisc.toMap("testingTypeId", "TEST-CACHE-1",
+ "lastUpdatedStamp", testValue.get("lastUpdatedStamp")));
+ int qtyChanged = delegator.storeByCondition("TestingType", UtilMisc.toMap("description", "New Testing Type #Cache-0"), storeByCondition);
+ assertEquals("Delegator.storeByCondition updated one value", 1, qtyChanged);
+ testValue = EntityUtil.getFirst(delegator.findByAnd("TestingType", UtilMisc.toMap("testingTypeId", "TEST-CACHE-1"), null, true));
+ assertEquals("Retrieved from cache value has the correct description", "New Testing Type #Cache-0", testValue.getString("description"));
+ // Test removeByCondition updates the cache
+ qtyChanged = delegator.removeByCondition("TestingType", storeByCondition);
+ assertEquals("Delegator.removeByCondition removed one value", 1, qtyChanged);
+ testValue = EntityUtil.getFirst(delegator.findByAnd("TestingType", UtilMisc.toMap("testingTypeId", "TEST-CACHE-1"), null, true));
+ assertEquals("Retrieved from cache value is null", null, testValue);
// Test entity value remove operation updates the cache
- testValue = (GenericValue) testValue.clone();
+ testValue = delegator.create("TestingType", "testingTypeId", "TEST-CACHE-1", "description", "Testing Type #Cache-1");
testValue.remove();
testValue = delegator.findOne("TestingType", true, "testingTypeId", "TEST-CACHE-1");
assertEquals("Retrieved from cache value is null", null, testValue);