From a6c3c08cc0fb80e13d20bb815ef994c0115a6efd Mon Sep 17 00:00:00 2001 From: Nicolas Malin Date: Fri, 24 May 2019 15:07:30 +0000 Subject: [PATCH] Fixed: Manage EECAs on delegator.removeBy (OFBIZ-11040) When you delete some entities through removeByAnd or removeByCondition, eeca aren't enable and the remove is quite as regard implemented rules. With And delegator.removeByAnd('GoodIdentification', [productId: 'WG-1111']) The service indexProductKeywords wasn't call for the productId WG-1111 To solve this situation, the idea would be delegator.removeValue for each element to delete when an eeca is present otherwise call the standard helper.removeByCondition. Thanks to Leila Mekika for raise and fix this issue, Jacques Leroux and Mathieu Lirzin for the review git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1859887 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/ofbiz/entity/GenericDelegator.java | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java index 4d8980e007..a5cd969d6e 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.net.URL; import java.sql.Timestamp; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -80,6 +81,8 @@ import org.apache.ofbiz.entity.util.EntityListIterator; import org.apache.ofbiz.entity.util.EntityQuery; import org.apache.ofbiz.entity.util.EntityStoreOptions; import org.apache.ofbiz.entity.util.SequenceUtil; +import org.apache.ofbiz.entityext.eca.EntityEcaRule; +import org.apache.ofbiz.entityext.eca.EntityEcaUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -1073,14 +1076,28 @@ public class GenericDelegator implements Delegator { ModelEntity modelEntity = getModelReader().getModelEntity(entityName); GenericHelper helper = getEntityHelper(entityName); - List removedEntities = null; - if (testMode) { - removedEntities = this.findList(entityName, condition, null, null, null, false); - } + // We check if there are eca rules for this entity + String entityEcaReaderName = EntityEcaUtil.getEntityEcaReaderName(this.delegatorBaseName); + boolean hasEntityEcaRules = UtilValidate.isNotEmpty( + EntityEcaUtil.getEntityEcaCache(entityEcaReaderName).get(entityName)); - int rowsAffected = helper.removeByCondition(this, modelEntity, condition); - if (rowsAffected > 0) { - this.clearCacheLine(entityName); + // When we delete in mass, if we are in test mode or the entity have an eeca linked we will remove one by one + // for test mode to help the rollback + // for eeca to analyse each value to check if a condition match + List removedEntities = (testMode || hasEntityEcaRules) + ? findList(entityName, condition, null, null, null, false) + : Collections.emptyList(); + + int rowsAffected = 0; + if (! removedEntities.isEmpty()) { + for (GenericValue entity : removedEntities) { + rowsAffected += removeValue(entity); + } + } else { + rowsAffected = helper.removeByCondition(this, modelEntity, condition); + if (rowsAffected > 0) { + this.clearCacheLine(entityName); + } } if (testMode) {