This is an automated email from the ASF dual-hosted git repository.
mbrohl pushed a commit to branch release17.12 in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/release17.12 by this push: new 651231d Fixed: Fluent API Bug in getFieldList(). 651231d is described below commit 651231d04116ef029a59375798d33e97031b15c3 Author: Michael Brohl <[hidden email]> AuthorDate: Tue Feb 25 21:15:44 2020 +0100 Fixed: Fluent API Bug in getFieldList(). (OFBIZ-10298) Thanks Benjamin Jugl for reporting and providing the patch. --- .../org/apache/ofbiz/entity/util/EntityQuery.java | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java index 068a319..1b4867c 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityQuery.java @@ -22,7 +22,7 @@ import java.sql.Timestamp; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -63,7 +63,7 @@ public class EntityQuery { private Integer resultSetType = EntityFindOptions.TYPE_FORWARD_ONLY; private Integer fetchSize = null; private Integer maxRows = null; - private Boolean distinct = null; + private boolean distinct = false; private EntityCondition havingEntityCondition = null; private boolean filterByDate = false; private Timestamp filterByDateMoment; @@ -471,9 +471,7 @@ public class EntityQuery { if (maxRows != null) { findOptions.setMaxRows(maxRows); } - if (distinct != null) { - findOptions.setDistinct(distinct); - } + findOptions.setDistinct(distinct); return findOptions; } @@ -519,10 +517,21 @@ public class EntityQuery { return EntityCondition.makeCondition(conditions); } - public <T> List<T> getFieldList(final String fieldName) throws GenericEntityException {select(fieldName); + /** + * Gets a list of values (no matter which type) for a specified entity field name. + * <p> + * The field of the entity is first selected and the cache usage turned off to ensure no values are missing. + * @param <T> + * @param fieldName + * @return list with field values + * @throws GenericEntityException + */ + public <T> List<T> getFieldList(final String fieldName) throws GenericEntityException { + select(fieldName); + cache(false); try (EntityListIterator genericValueEli = queryIterator()) { - if (Boolean.TRUE.equals(this.distinct)) { - Set<T> distinctSet = new HashSet<T>(); + if (this.distinct) { + Set<T> distinctSet = new LinkedHashSet<T>(); GenericValue value = null; while ((value = genericValueEli.next()) != null) { T fieldValue = UtilGenerics.<T>cast(value.get(fieldName)); |
Free forum by Nabble | Edit this page |