svn commit: r1802684 - /ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java

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

svn commit: r1802684 - /ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java

nmalin
Author: nmalin
Date: Sat Jul 22 12:23:59 2017
New Revision: 1802684

URL: http://svn.apache.org/viewvc?rev=1802684&view=rev
Log:
Improved: for EntityQuery.findOne() with context,
Instead of iterating fields, used GenericPk class object to get the PK fileds from parameters/fieldMap.
Thanks Deepak for this nice improvement

Modified:
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java?rev=1802684&r1=1802683&r2=1802684&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java Sat Jul 22 12:23:59 2017
@@ -36,6 +36,7 @@ import org.apache.ofbiz.base.util.UtilVa
 import org.apache.ofbiz.base.util.collections.PagedList;
 import org.apache.ofbiz.entity.Delegator;
 import org.apache.ofbiz.entity.GenericEntityException;
+import org.apache.ofbiz.entity.GenericPK;
 import org.apache.ofbiz.entity.GenericValue;
 import org.apache.ofbiz.entity.condition.EntityCondition;
 import org.apache.ofbiz.entity.model.DynamicViewEntity;
@@ -483,17 +484,10 @@ public class EntityQuery {
             if (this.searchPkOnly) {
                 //Resolve if the map contains a sub map parameters, use a containsKeys to avoid error when a GenericValue is given as map
                 Map<String, Object> parameters = fieldMap.containsKey("parameters") ? (Map<String, Object>) fieldMap.get("parameters") : null;
-                Map<String, Object> resolveFieldMap = new HashMap<>();
-                ModelEntity modelEntity = delegator.getModelEntity(entityName);
-                List<String> fieldNames = modelEntity.getPkFieldNames();
-                for (String fieldName : fieldNames) {
-                    if (fieldMap.containsKey(fieldName)) {
-                        resolveFieldMap.put(fieldName, fieldMap.get(fieldName));
-                    } else if (parameters != null && parameters.containsKey(fieldName)) {
-                        resolveFieldMap.put(fieldName, parameters.get(fieldName));
-                    }
-                }
-                this.whereEntityCondition = EntityCondition.makeCondition(resolveFieldMap);
+                GenericPK pk = GenericPK.create(delegator.getModelEntity(entityName));
+                pk.setPKFields(parameters);
+                pk.setPKFields(fieldMap);
+                this.whereEntityCondition = EntityCondition.makeCondition(pk.getPrimaryKey());
             } else {
                 this.whereEntityCondition = EntityCondition.makeCondition(fieldMap);
             }