From 2fb751a67045252a0c6cdb34ee6c22fc2f1f76d2 Mon Sep 17 00:00:00 2001 From: "David E. Jones" Date: Sun, 1 Oct 2006 16:56:16 +0000 Subject: [PATCH] Applied patch from Leon Torres, with small change, to implement new default value feature for complex aliases in view entities; Apache Jira #OFBIZ-336 git-svn-id: https://svn.apache.org/repos/asf/incubator/ofbiz/trunk@451767 13f79535-47bb-0310-9956-ffa450edef68 --- framework/entity/dtd/entitymodel.xsd | 1 + .../ofbiz/entity/model/ModelViewEntity.java | 20 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/framework/entity/dtd/entitymodel.xsd b/framework/entity/dtd/entitymodel.xsd index 9e8cd1fe98..c3b510fa78 100644 --- a/framework/entity/dtd/entitymodel.xsd +++ b/framework/entity/dtd/entitymodel.xsd @@ -333,6 +333,7 @@ under the License. + diff --git a/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java b/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java index 6c62d17c4e..3c9c11bce3 100644 --- a/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java +++ b/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java @@ -857,31 +857,29 @@ public class ModelViewEntity extends ModelEntity { public static class ComplexAliasField implements ComplexAliasMember { protected String entityAlias = ""; protected String field = ""; + protected String defaultValue = null; protected String function = null; - public ComplexAliasField(String entityAlias , String field) { - this.entityAlias = entityAlias; - this.field = field; - } - - public ComplexAliasField(String entityAlias , String field, String function) { - this.entityAlias = entityAlias; - this.field = field; - this.function = function; - } - public ComplexAliasField(Element complexAliasFieldElement) { this.entityAlias = complexAliasFieldElement.getAttribute("entity-alias"); this.field = complexAliasFieldElement.getAttribute("field"); + this.defaultValue = complexAliasFieldElement.getAttribute("default-value"); this.function = complexAliasFieldElement.getAttribute("function"); } + /** + * Make the alias as follows: function(coalesce(entityAlias.field, defaultValue)) + */ public void makeAliasColName(StringBuffer colNameBuffer, StringBuffer fieldTypeBuffer, ModelViewEntity modelViewEntity, ModelReader modelReader) { ModelEntity modelEntity = modelViewEntity.getAliasedEntity(entityAlias, modelReader); ModelField modelField = modelViewEntity.getAliasedField(modelEntity, field, modelReader); String colName = entityAlias + "." + modelField.getColName(); + if (UtilValidate.isNotEmpty(defaultValue)) { + colName = "COALESCE(" + colName + "," + defaultValue + ")"; + } + if (UtilValidate.isNotEmpty(function)) { String prefix = (String) functionPrefixMap.get(function); if (prefix == null) {