Author: jacopoc
Date: Wed Dec 10 08:25:45 2014
New Revision: 1644348
URL: http://svn.apache.org/r1644348
Log:
OFBIZ-5146: added support for three new ModelViewEntity functions for the
extraction of year, month, day from a date field: extract-year, extract-month,
extract-day.
They are mapped to the Standard SQL:2011 EXTRACT function that is already
supported by several DBMS including PostgreSQL and MySQL (but not yet Derby).
Modified:
ofbiz/trunk/framework/entity/dtd/entitymodel.xsd
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=1644348&r1=1644347&r2=1644348&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/dtd/entitymodel.xsd (original)
+++ ofbiz/trunk/framework/entity/dtd/entitymodel.xsd Wed Dec 10 08:25:45 2014
@@ -39,6 +39,9 @@ under the License.
<xs:enumeration value="count-distinct"/>
<xs:enumeration value="upper"/>
<xs:enumeration value="lower"/>
+ <xs:enumeration value="extract-year"/>
+ <xs:enumeration value="extract-month"/>
+ <xs:enumeration value="extract-day"/>
</xs:restriction>
</xs:simpleType>
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=1644348&r1=1644347&r2=1644348&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
Wed Dec 10 08:25:45 2014
@@ -55,7 +55,8 @@ import org.w3c.dom.NodeList;
public class ModelViewEntity extends ModelEntity {
public static final String module = ModelViewEntity.class.getName();
- public static Map<String, String> functionPrefixMap = new HashMap<String,
String>();
+ private static final Map<String, String> functionPrefixMap = new
HashMap<String, String>();
+ private static final Set<String> numericFunctionsSet = new
HashSet<String>(); // names of functions that return a numeric type
static {
functionPrefixMap.put("min", "MIN(");
functionPrefixMap.put("max", "MAX(");
@@ -65,6 +66,14 @@ public class ModelViewEntity extends Mod
functionPrefixMap.put("count-distinct", "COUNT(DISTINCT ");
functionPrefixMap.put("upper", "UPPER(");
functionPrefixMap.put("lower", "LOWER(");
+ functionPrefixMap.put("extract-year", "EXTRACT(YEAR FROM ");
+ functionPrefixMap.put("extract-month", "EXTRACT(MONTH FROM ");
+ functionPrefixMap.put("extract-day", "EXTRACT(DAY FROM ");
+ numericFunctionsSet.add("count");
+ numericFunctionsSet.add("count-distinct");
+ numericFunctionsSet.add("extract-year");
+ numericFunctionsSet.add("extract-month");
+ numericFunctionsSet.add("extract-day");
}
/** Contains member-entity alias name definitions: key is alias, value is
ModelMemberEntity */
@@ -480,8 +489,8 @@ public class ModelViewEntity extends Mod
fieldSet = alias.getFieldSet();
}
}
- if ("count".equals(alias.function) ||
"count-distinct".equals(alias.function)) {
- // if we have a "count" function we have to change the type
+ if (numericFunctionsSet.contains(alias.function)) {
+ // if we have a numeric function we have to change the type
type = "numeric";
}
if (UtilValidate.isNotEmpty(alias.function)) {