svn commit: r1859888 - /ofbiz/ofbiz-framework/branches/release18.12/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1859888 - /ofbiz/ofbiz-framework/branches/release18.12/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java

nmalin
Author: nmalin
Date: Fri May 24 15:08:22 2019
New Revision: 1859888

URL: http://svn.apache.org/viewvc?rev=1859888&view=rev
Log:
Fixed: Backport: 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
        <eca entity=GoodIndentification operation=create-store-remove event=return>
             <action service=indexProductKeywords mode=sync/>
        </eca>
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

Modified:
    ofbiz/ofbiz-framework/branches/release18.12/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java

Modified: ofbiz/ofbiz-framework/branches/release18.12/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java?rev=1859888&r1=1859887&r2=1859888&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java Fri May 24 15:08:22 2019
@@ -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.Enti
 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;
@@ -1091,14 +1094,28 @@ public class GenericDelegator implements
             ModelEntity modelEntity = getModelReader().getModelEntity(entityName);
             GenericHelper helper = getEntityHelper(entityName);
 
-            List<GenericValue> removedEntities = null;
-            if (testMode) {
-                removedEntities = this.findList(entityName, condition, null, null, null, false);
-            }
-
-            int rowsAffected = helper.removeByCondition(this, modelEntity, condition);
-            if (rowsAffected > 0) {
-                this.clearCacheLine(entityName);
+            // 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));
+
+            // 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<GenericValue> 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) {