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
This commit is contained in:
David E. Jones
2006-10-01 16:56:16 +00:00
parent 62aa8c5628
commit 2fb751a670
2 changed files with 10 additions and 11 deletions
+1
View File
@@ -333,6 +333,7 @@ under the License.
<xs:attributeGroup name="attlist.complex-alias-field">
<xs:attribute type="xs:string" name="entity-alias" use="required"/>
<xs:attribute type="xs:string" name="field" use="required"/>
<xs:attribute type="xs:string" name="default-value"/>
<xs:attribute name="function">
<xs:simpleType>
<xs:restriction base="xs:token">
@@ -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) {