From 4e69fb07640d004fe7e0c899792b2406f2f2e9a9 Mon Sep 17 00:00:00 2001 From: Adam Heath Date: Fri, 13 Nov 2009 03:59:34 +0000 Subject: [PATCH] Allow for setting groupBy fields with just a simple list. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@835729 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/ofbiz/entity/model/DynamicViewEntity.java | 13 +++++++++++++ .../src/org/ofbiz/entity/model/ModelViewEntity.java | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/framework/entity/src/org/ofbiz/entity/model/DynamicViewEntity.java b/framework/entity/src/org/ofbiz/entity/model/DynamicViewEntity.java index 455fb0c94c..5ee02959ba 100644 --- a/framework/entity/src/org/ofbiz/entity/model/DynamicViewEntity.java +++ b/framework/entity/src/org/ofbiz/entity/model/DynamicViewEntity.java @@ -60,6 +60,9 @@ public class DynamicViewEntity { /** List of aliases with information in addition to what is in the standard field list */ protected List aliases = new ArrayList(); + /** List of fields to group by */ + protected List groupBy; + /** List of view links to define how entities are connected (or "joined") */ protected List viewLinks = new ArrayList(); @@ -211,4 +214,14 @@ public class DynamicViewEntity { public void addAllRelationsToList(List addList) { addList.addAll(this.relations); } + + public void setGroupBy(List groupBy) { + this.groupBy = groupBy; + } + + public void addAllGroupByFieldsToList(List addList) { + if (groupBy != null) { + addList.addAll(this.groupBy); + } + } } diff --git a/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java b/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java index 06956dc2a6..dba4e56e12 100644 --- a/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java +++ b/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java @@ -88,6 +88,9 @@ public class ModelViewEntity extends ModelEntity { /** A List of the Field objects for the View Entity, one for each GROUP BY field */ protected List groupBys = FastList.newInstance(); + /** List of field names to group by */ + protected List groupByFields = FastList.newInstance(); + protected Map> conversions = FastMap.newInstance(); protected ViewEntityCondition viewEntityCondition = null; @@ -165,6 +168,8 @@ public class ModelViewEntity extends ModelEntity { // relations dynamicViewEntity.addAllRelationsToList(this.relations); + dynamicViewEntity.addAllGroupByFieldsToList(this.groupByFields); + // finalize stuff // note that this doesn't result in a call to populateReverseLinks because a DynamicViewEntity should never be cached anyway, and will blow up when attempting to make the reverse links to the DynamicViewEntity this.populateFieldsBasic(modelReader); @@ -430,7 +435,7 @@ public class ModelViewEntity extends ModelEntity { field.description = alias.description; // if this is a groupBy field, add it to the groupBys list - if (alias.groupBy) { + if (alias.groupBy || groupByFields.contains(alias.name)) { this.groupBys.add(field); }