ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jler...@apache.org
Subject svn commit: r1726184 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityQuery.java
Date Fri, 22 Jan 2016 11:50:49 GMT
Author: jleroux
Date: Fri Jan 22 11:50:49 2016
New Revision: 1726184

URL: http://svn.apache.org/viewvc?rev=1726184&view=rev
Log:
A slightly formatted patch from Gareth Carter for "Add getFieldList method to EntityQuery"
https://issues.apache.org/jira/browse/OFBIZ-6848

Improves EntityQuery by adding method getFieldList so we don't have to chain to EntityUtils.getFieldListFromEntityList
or getFieldListFromEntityListIterator

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

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityQuery.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityQuery.java?rev=1726184&r1=1726183&r2=1726184&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityQuery.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityQuery.java Fri Jan 22 11:50:49
2016
@@ -22,11 +22,14 @@ import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.Delegator;
@@ -506,4 +509,38 @@ public class EntityQuery {
         }
         return EntityCondition.makeCondition(conditions);
     }
+
+    public <T> List<T> getFieldList(final String fieldName) throws GenericEntityException
{select(fieldName);
+        EntityListIterator genericValueEli = null;
+        try {
+            genericValueEli = queryIterator();
+            if (this.distinct) {
+                Set<T> distinctSet = new HashSet<T>();
+                GenericValue value = null;
+                while ((value = genericValueEli.next()) != null) {
+                    T fieldValue = UtilGenerics.<T>cast(value.get(fieldName));
+                    if (fieldValue != null) {
+                        distinctSet.add(fieldValue);
+                    }
+                }
+                return new ArrayList<T>(distinctSet);
+            }
+            else {
+                List<T> fieldList = new LinkedList<T>();
+                GenericValue value = null;
+                while ((value = genericValueEli.next()) != null) {
+                    T fieldValue = UtilGenerics.<T>cast(value.get(fieldName));
+                    if (fieldValue != null) {
+                        fieldList.add(fieldValue);
+                    }
+                }
+                return fieldList;
+            }
+        }
+        finally {
+            if (genericValueEli != null) {
+                genericValueEli.close();
+            }
+        }
+    }
 }



Mime
View raw message