You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/10/15 09:28:49 UTC

svn commit: r584700 - in /ofbiz/trunk/framework/entity: dtd/entitymodel.xsd src/org/ofbiz/entity/model/ModelField.java src/org/ofbiz/entity/model/ModelViewEntity.java

Author: jacopoc
Date: Mon Oct 15 00:28:48 2007
New Revision: 584700

URL: http://svn.apache.org/viewvc?rev=584700&view=rev
Log:
Added 'description' field and accessor methods to the ModelField and ModelViewEntity.ModelAlias classes to store the field level description specified in the entity definition (<description></description> tags).
Added new optional attributes to the alias-all element: function and group-by. If specified then to all the aliased fields the function and/or group-by element will be applied.
In ModelViewEntity, added new method to get the list of group-by fields as a subset of the passed in list: this is useful to get the list of group-by fields limited to the felds that are in the select clause.

Modified:
    ofbiz/trunk/framework/entity/dtd/entitymodel.xsd
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java

Modified: ofbiz/trunk/framework/entity/dtd/entitymodel.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd?rev=584700&r1=584699&r2=584700&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/dtd/entitymodel.xsd (original)
+++ ofbiz/trunk/framework/entity/dtd/entitymodel.xsd Mon Oct 15 00:28:48 2007
@@ -270,6 +270,28 @@
     <xs:attributeGroup name="attlist.alias-all">
         <xs:attribute type="xs:string" name="entity-alias" use="required"/>
         <xs:attribute type="xs:string" name="prefix"/>
+        <xs:attribute name="group-by" default="false">
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="true"/>
+                    <xs:enumeration value="false"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
+        <xs:attribute name="function">
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="min"/>
+                    <xs:enumeration value="max"/>
+                    <xs:enumeration value="sum"/>
+                    <xs:enumeration value="avg"/>
+                    <xs:enumeration value="count"/>
+                    <xs:enumeration value="count-distinct"/>
+                    <xs:enumeration value="upper"/>
+                    <xs:enumeration value="lower"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
     </xs:attributeGroup>
     <xs:element name="exclude">
         <xs:complexType>

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java?rev=584700&r1=584699&r2=584700&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelField.java Mon Oct 15 00:28:48 2007
@@ -47,6 +47,9 @@
     /** validators to be called when an update is done */
     protected List validators = new ArrayList();
 
+    /** The description for documentation purposes */
+    protected String description = "";
+
     /** Default Constructor */
     public ModelField() {}
 
@@ -70,6 +73,7 @@
         this.setColName(UtilXml.checkEmpty(fieldElement.getAttribute("col-name")));
         this.isPk = false; // is set elsewhere
         this.encrypt = UtilXml.checkBoolean(fieldElement.getAttribute("encrypt"), false);
+        this.description = UtilXml.childElementValue(fieldElement, "description");
 
         NodeList validateList = fieldElement.getElementsByTagName("validate");
 
@@ -161,6 +165,15 @@
 
     public String removeValidator(int index) {
         return (String) this.validators.remove(index);
+    }
+
+    /** The description for documentation purposes */
+    public String getDescription() {
+        return this.description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
     }
 
     public boolean equals(Object obj) {

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java?rev=584700&r1=584699&r2=584700&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java Mon Oct 15 00:28:48 2007
@@ -238,8 +238,22 @@
     }
 
     public List getGroupBysCopy() {
+        return getGroupBysCopy(null);
+    }
+
+    public List getGroupBysCopy(List selectFields) {
         List newList = FastList.newInstance();
-        newList.addAll(this.groupBys);
+        if (UtilValidate.isEmpty(selectFields)) {
+            newList.addAll(this.groupBys);
+        } else {
+            Iterator groupBysIt = this.groupBys.iterator();
+            while (groupBysIt.hasNext()) {
+                ModelField groupByField = (ModelField)groupBysIt.next();
+                if (selectFields.contains(groupByField)) {
+                    newList.add(groupByField);
+                }
+            }
+        }
         return newList;
     }
 
@@ -549,6 +563,8 @@
         while (aliasAllIter.hasNext()) {
             ModelAliasAll aliasAll = (ModelAliasAll) aliasAllIter.next();
             String prefix = aliasAll.getPrefix();
+            String function = aliasAll.getFunction();
+            boolean groupBy = aliasAll.getGroupBy();
 
             ModelMemberEntity modelMemberEntity = (ModelMemberEntity) memberModelMemberEntities.get(aliasAll.getEntityAlias());
             if (modelMemberEntity == null) {
@@ -633,6 +649,9 @@
                 expandedAlias.entityAlias = aliasAll.getEntityAlias();
                 expandedAlias.isFromAliasAll = true;
                 expandedAlias.colAlias = ModelUtil.javaNameToDbName(UtilXml.checkEmpty(expandedAlias.name));
+                expandedAlias.function = function;
+                expandedAlias.groupBy = groupBy;
+               
                 aliases.add(expandedAlias);
             }
         }
@@ -664,6 +683,9 @@
         protected String entityAlias = "";
         protected String prefix = "";
         protected Set fieldsToExclude = null;
+        protected boolean groupBy = false;
+        // is specified this alias is a calculated value; can be: min, max, sum, avg, count, count-distinct
+        protected String function = null;
 
         protected ModelAliasAll() {}
 
@@ -675,6 +697,8 @@
         public ModelAliasAll(Element aliasAllElement) {
             this.entityAlias = UtilXml.checkEmpty(aliasAllElement.getAttribute("entity-alias"));
             this.prefix = UtilXml.checkEmpty(aliasAllElement.getAttribute("prefix"));
+            this.groupBy = "true".equals(UtilXml.checkEmpty(aliasAllElement.getAttribute("group-by")));
+            this.function = UtilXml.checkEmpty(aliasAllElement.getAttribute("function"));
             
             List excludes = UtilXml.childElementList(aliasAllElement, "exclude");
             if (excludes != null && excludes.size() > 0) {
@@ -696,6 +720,14 @@
             return this.prefix;
         }
 
+        public boolean getGroupBy() {
+            return this.groupBy;
+        }
+
+        public String getFunction() {
+            return this.function;
+        }
+
         public boolean shouldExclude(String fieldName) {
             if (this.fieldsToExclude == null) {
                 return false;
@@ -717,6 +749,8 @@
         protected String function = null;
         protected boolean isFromAliasAll = false;
         protected ComplexAliasMember complexAliasMember = null;
+        // The description for documentation purposes
+        protected String description = "";
 
         protected ModelAlias() {}
 
@@ -734,6 +768,7 @@
             }
             this.groupBy = "true".equals(UtilXml.checkEmpty(aliasElement.getAttribute("group-by")));
             this.function = UtilXml.checkEmpty(aliasElement.getAttribute("function"));
+            this.description = UtilXml.childElementValue(aliasElement, "description");
             
             Element complexAliasElement = UtilXml.firstChildElement(aliasElement, "complex-alias");
             if (complexAliasElement != null) {
@@ -795,6 +830,14 @@
 
         public String getFunction() {
             return this.function;
+        }
+
+        public String getDescription() {
+            return this.description;
+        }
+
+        public void setDescription(String description) {
+            this.description = description;
         }
 
         public boolean getIsFromAliasAll() {