svn commit: r792836 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/ entity/src/org/ofbiz/entity/condition/ entity/src/org/ofbiz/entity/datasource/ entity/src/org/ofbiz/entity/model/ example/entitydef/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r792836 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/ entity/src/org/ofbiz/entity/condition/ entity/src/org/ofbiz/entity/datasource/ entity/src/org/ofbiz/entity/model/ example/entitydef/

jonesde
Author: jonesde
Date: Fri Jul 10 08:47:16 2009
New Revision: 792836

URL: http://svn.apache.org/viewvc?rev=792836&view=rev
Log:
Added example of nested view-entity with entity-condition on a view member entity; adjusted view-entity entity-condition to handle naming consistent to other places for nested views, other small cleanups

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java
    ofbiz/trunk/framework/example/entitydef/entitymodel_view.xml

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java?rev=792836&r1=792835&r2=792836&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilMisc.java Fri Jul 10 08:47:16 2009
@@ -51,6 +51,30 @@
         return throwable;
     }
 
+    public static <T> int compare(T obj1, T obj2) {
+        if (obj1 == null) {
+            if (obj2 == null) {
+                return 0;
+            } else {
+                return 1;
+            }
+        } else {
+            return ((Comparable<T>) obj1).compareTo(obj2);
+        }
+    }
+    
+    public static <T> int compare(Comparable<T> obj1, T obj2) {
+        if (obj1 == null) {
+            if (obj2 == null) {
+                return 0;
+            } else {
+                return 1;
+            }
+        } else {
+            return obj1.compareTo(obj2);
+        }
+    }
+    
     /**
      * Get an iterator from a collection, returning null if collection is null
      * @param col The collection to be turned in to an iterator

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java?rev=792836&r1=792835&r2=792836&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java Fri Jul 10 08:47:16 2009
@@ -24,7 +24,10 @@
 
 import javolution.context.ObjectFactory;
 import javolution.lang.Reusable;
+import javolution.util.FastList;
 
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntity;
@@ -33,6 +36,7 @@
 import org.ofbiz.entity.model.ModelEntity;
 import org.ofbiz.entity.model.ModelField;
 import org.ofbiz.entity.model.ModelViewEntity;
+import org.ofbiz.entity.model.ModelViewEntity.ModelAlias;
 
 /**
  * Encapsulates operations between entities and entity fields. This is a immutable class.
@@ -41,6 +45,8 @@
 @SuppressWarnings("serial")
 public class EntityFieldValue extends EntityConditionValue implements Reusable {
 
+    public static final String module = EntityFieldValue.class.getName();
+
     protected static final ObjectFactory<EntityFieldValue> entityFieldValueFactory = new ObjectFactory<EntityFieldValue>() {
         @Override
         protected EntityFieldValue create() {
@@ -50,17 +56,18 @@
 
     protected String fieldName = null;
     protected String entityAlias = null;
+    protected List<String> entityAliasStack = null;
     protected ModelViewEntity modelViewEntity = null;
 
     public static EntityFieldValue makeFieldValue(String fieldName) {
         EntityFieldValue efv = EntityFieldValue.entityFieldValueFactory.object();
-        efv.init(fieldName, null, null);
+        efv.init(fieldName, null, null, null);
         return efv;
     }
 
-    public static EntityFieldValue makeFieldValue(String fieldName, String entityAlias, ModelViewEntity modelViewEntity) {
+    public static EntityFieldValue makeFieldValue(String fieldName, String entityAlias, List<String> entityAliasStack, ModelViewEntity modelViewEntity) {
         EntityFieldValue efv = EntityFieldValue.entityFieldValueFactory.object();
-        efv.init(fieldName, entityAlias, modelViewEntity);
+        efv.init(fieldName, entityAlias, entityAliasStack, modelViewEntity);
         return efv;
     }
 
@@ -69,17 +76,33 @@
     /** @deprecated Use EntityFieldValue.makeFieldValue() instead */
     @Deprecated
     public EntityFieldValue(String fieldName) {
-        this.init(fieldName, null, null);
+        this.init(fieldName, null, null, null);
     }
 
-    public void init(String fieldName, String entityAlias, ModelViewEntity modelViewEntity) {
+    public void init(String fieldName, String entityAlias, List<String> entityAliasStack, ModelViewEntity modelViewEntity) {
         this.fieldName = fieldName;
         this.entityAlias = entityAlias;
+        if (UtilValidate.isNotEmpty(entityAliasStack)) {
+            this.entityAliasStack = FastList.newInstance();
+            this.entityAliasStack.addAll(entityAliasStack);
+        }
         this.modelViewEntity = modelViewEntity;
+        if (UtilValidate.isNotEmpty(this.entityAliasStack) && UtilValidate.isEmpty(this.entityAlias)) {
+            // look it up on the view entity so it can be part of the big list, this only happens for aliased fields, so find the entity-alias and field-name for the alias
+            ModelAlias modelAlias = this.modelViewEntity.getAlias(this.fieldName);
+            if (modelAlias != null) {
+                this.entityAlias = modelAlias.getEntityAlias();
+                this.fieldName = modelAlias.getField();
+            }
+            // TODO/NOTE: this will ignore function, group-by, etc... should maybe support those in conditions too at some point
+        }
     }
 
     public void reset() {
-    this.fieldName = null;
+        this.fieldName = null;
+        this.entityAlias = null;
+        this.entityAliasStack = null;
+        this.modelViewEntity = null;
     }
 
     public String getFieldName() {
@@ -88,14 +111,21 @@
 
     @Override
     public int hashCode() {
-        return fieldName.hashCode();
+        int hash = fieldName.hashCode();
+        if (this.entityAlias != null) hash |= this.entityAlias.hashCode();
+        if (this.entityAliasStack != null) hash |= this.entityAliasStack.hashCode();
+        if (this.modelViewEntity != null) hash |= this.modelViewEntity.hashCode();
+        return hash;
     }
 
     @Override
     public boolean equals(Object obj) {
         if (!(obj instanceof EntityFieldValue)) return false;
         EntityFieldValue otherValue = (EntityFieldValue) obj;
-        return fieldName.equals(otherValue.fieldName);
+        if (!fieldName.equals(otherValue.fieldName)) return false;
+        if (UtilMisc.compare(this.entityAlias, otherValue.entityAlias) != 0) return false;
+        if (UtilMisc.compare(this.entityAliasStack, otherValue.entityAliasStack) != 0) return false;
+        return true;
     }
 
     @Override
@@ -106,12 +136,33 @@
     @Override
     public void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) {
         if (this.modelViewEntity != null) {
+            // NOTE: this section is a bit of a hack; the other code is terribly complex and really needs to be refactored to incorporate support for this
+            
             if (UtilValidate.isNotEmpty(entityAlias)) {
                 ModelEntity memberModelEntity = modelViewEntity.getMemberModelEntity(entityAlias);
                 ModelField modelField = memberModelEntity.getField(fieldName);
-                sql.append(entityAlias);
-                sql.append(".");
-                sql.append(modelField.getColName());
+
+                // using entityAliasStack (ordered top to bottom) build a big long alias; not that dots will be replaced after it is combined with the column name in the SQL gen
+                if (UtilValidate.isNotEmpty(this.entityAliasStack)) {
+                    boolean dotUsed = false;
+                    for (String curEntityAlias: entityAliasStack) {
+                        sql.append(curEntityAlias);
+                        if (dotUsed) {
+                            sql.append("_");
+                        } else {
+                            sql.append(".");
+                            dotUsed = true;
+                        }
+                      
+                    }
+                    sql.append(entityAlias);
+                    sql.append("_");
+                    sql.append(modelField.getColName());
+                } else {
+                    sql.append(entityAlias);
+                    sql.append(".");
+                    sql.append(modelField.getColName());
+                }
             } else {
                 sql.append(getColName(tableAliases, modelViewEntity, fieldName, includeTableNamePrefix, datasourceInfo));
             }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=792836&r1=792835&r2=792836&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Fri Jul 10 08:47:16 2009
@@ -670,12 +670,23 @@
             sqlBuffer.append("*");
         }
 
+        // populate the info from entity-condition in the view-entity, if it is one and there is one
+        List<EntityCondition> viewWhereConditions = null;
+        List<EntityCondition> viewHavingConditions = null;
+        List<String> viewOrderByList = null;
+        if (modelViewEntity != null) {
+            viewWhereConditions = FastList.newInstance();
+            viewHavingConditions = FastList.newInstance();
+            viewOrderByList = FastList.newInstance();
+            modelViewEntity.populateViewEntityConditionInformation(modelFieldTypeReader, viewWhereConditions, viewHavingConditions, viewOrderByList, null);
+        }
+
         // FROM clause and when necessary the JOIN or LEFT JOIN clause(s) as well
         sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, datasourceInfo));
-
+        
         // WHERE clause
         List<EntityConditionParam> whereEntityConditionParams = FastList.newInstance();
-        StringBuilder whereString = makeConditionWhereString(modelEntity, whereEntityCondition, whereEntityConditionParams);
+        StringBuilder whereString = makeConditionWhereString(modelEntity, whereEntityCondition, viewWhereConditions, whereEntityConditionParams);
         if (whereString.length() > 0) {
             sqlBuffer.append(" WHERE ");
             sqlBuffer.append(whereString.toString());
@@ -693,7 +704,7 @@
 
         // HAVING clause
         List<EntityConditionParam> havingEntityConditionParams = FastList.newInstance();
-        StringBuilder havingString = makeConditionHavingString(modelEntity, havingEntityCondition, havingEntityConditionParams);
+        StringBuilder havingString = makeConditionHavingString(modelEntity, havingEntityCondition, viewHavingConditions, havingEntityConditionParams);
         if (havingString.length() > 0) {
             sqlBuffer.append(" HAVING ");
             sqlBuffer.append(havingString);
@@ -705,11 +716,9 @@
         if (orderBy != null) {
             orderByExpanded.addAll(orderBy);
         }
-        if (modelViewEntity != null) {
-            List<String> viewOrderBy = modelViewEntity.getViewEntityConditionOrderBy();
-            if (viewOrderBy != null && viewOrderBy.size() > 0) {
-                orderByExpanded.addAll(viewOrderBy);
-            }
+        if (viewOrderByList != null) {
+            // add to end of other order by so that those in method call will override those in view
+            orderByExpanded.addAll(viewOrderByList);
         }
         sqlBuffer.append(SqlJdbcUtil.makeOrderByClause(modelEntity, orderByExpanded, datasourceInfo));
         
@@ -752,7 +761,7 @@
         return new EntityListIterator(sqlP, modelEntity, selectFields, modelFieldTypeReader);
     }
     
-    protected StringBuilder makeConditionWhereString(ModelEntity modelEntity, EntityCondition whereEntityCondition, List<EntityConditionParam> whereEntityConditionParams) throws GenericEntityException {
+    protected StringBuilder makeConditionWhereString(ModelEntity modelEntity, EntityCondition whereEntityCondition, List<EntityCondition> viewWhereConditions, List<EntityConditionParam> whereEntityConditionParams) throws GenericEntityException {
         ModelViewEntity modelViewEntity = null;
         if (modelEntity instanceof ModelViewEntity) {
             modelViewEntity = (ModelViewEntity) modelEntity;
@@ -765,7 +774,7 @@
 
         String viewEntityCondWhereString = null;
         if (modelViewEntity != null) {
-            EntityCondition viewWhereEntityCondition = modelViewEntity.getViewEntityConditionWhere(this.modelFieldTypeReader);
+            EntityCondition viewWhereEntityCondition = EntityCondition.makeCondition(viewWhereConditions);
             if (viewWhereEntityCondition != null) {
                 viewEntityCondWhereString = viewWhereEntityCondition.makeWhereString(modelEntity, whereEntityConditionParams, this.datasourceInfo);
             }
@@ -803,7 +812,7 @@
         return whereString;
     }
     
-    protected StringBuilder makeConditionHavingString(ModelEntity modelEntity, EntityCondition havingEntityCondition, List<EntityConditionParam> havingEntityConditionParams) throws GenericEntityException {
+    protected StringBuilder makeConditionHavingString(ModelEntity modelEntity, EntityCondition havingEntityCondition, List<EntityCondition> viewHavingConditions, List<EntityConditionParam> havingEntityConditionParams) throws GenericEntityException {
         ModelViewEntity modelViewEntity = null;
         if (modelEntity instanceof ModelViewEntity) {
             modelViewEntity = (ModelViewEntity) modelEntity;
@@ -816,7 +825,7 @@
         
         String viewEntityCondHavingString = null;
         if (modelViewEntity != null) {
-            EntityCondition viewHavingEntityCondition = modelViewEntity.getViewEntityConditionHaving(this.modelFieldTypeReader);
+            EntityCondition viewHavingEntityCondition = EntityCondition.makeCondition(viewHavingConditions);
             if (viewHavingEntityCondition != null) {
                 viewEntityCondHavingString = viewHavingEntityCondition.makeWhereString(modelEntity, havingEntityConditionParams, this.datasourceInfo);
             }
@@ -996,13 +1005,23 @@
             sqlBuffer.append("COUNT(1) ");
         }
 
+        // populate the info from entity-condition in the view-entity, if it is one and there is one
+        List<EntityCondition> viewWhereConditions = null;
+        List<EntityCondition> viewHavingConditions = null;
+        List<String> viewOrderByList = null;
+        if (modelViewEntity != null) {
+            viewWhereConditions = FastList.newInstance();
+            viewHavingConditions = FastList.newInstance();
+            viewOrderByList = FastList.newInstance();
+            modelViewEntity.populateViewEntityConditionInformation(modelFieldTypeReader, viewWhereConditions, viewHavingConditions, viewOrderByList, null);
+        }
 
         // FROM clause and when necessary the JOIN or LEFT JOIN clause(s) as well
         sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, datasourceInfo));
 
         // WHERE clause
         List<EntityConditionParam> whereEntityConditionParams = FastList.newInstance();
-        StringBuilder whereString = makeConditionWhereString(modelEntity, whereEntityCondition, whereEntityConditionParams);
+        StringBuilder whereString = makeConditionWhereString(modelEntity, whereEntityCondition, viewWhereConditions, whereEntityConditionParams);
         if (whereString.length() > 0) {
             sqlBuffer.append(" WHERE ");
             sqlBuffer.append(whereString.toString());
@@ -1018,7 +1037,7 @@
 
         // HAVING clause
         List<EntityConditionParam> havingEntityConditionParams = FastList.newInstance();
-        StringBuilder havingString = makeConditionHavingString(modelEntity, havingEntityCondition, havingEntityConditionParams);
+        StringBuilder havingString = makeConditionHavingString(modelEntity, havingEntityCondition, viewHavingConditions, havingEntityConditionParams);
         if (havingString.length() > 0) {
             sqlBuffer.append(" HAVING ");
             sqlBuffer.append(havingString);

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=792836&r1=792835&r2=792836&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 Fri Jul 10 08:47:16 2009
@@ -32,25 +32,18 @@
 import javolution.util.FastMap;
 
 import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.StringUtil;
 import org.ofbiz.base.util.UtilFormatOut;
 import org.ofbiz.base.util.UtilTimer;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
-import org.ofbiz.base.util.collections.FlexibleMapAccessor;
-import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.entity.condition.EntityComparisonOperator;
 import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.condition.EntityConditionValue;
 import org.ofbiz.entity.condition.EntityFieldValue;
 import org.ofbiz.entity.condition.EntityFunction;
 import org.ofbiz.entity.condition.EntityJoinOperator;
 import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.finder.ByConditionFinder;
-import org.ofbiz.entity.finder.EntityFinderUtil.Condition;
-import org.ofbiz.entity.finder.EntityFinderUtil.ConditionExpr;
-import org.ofbiz.entity.finder.EntityFinderUtil.ConditionList;
-import org.ofbiz.entity.finder.EntityFinderUtil.ConditionObject;
 import org.ofbiz.entity.jdbc.SqlJdbcUtil;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
@@ -292,19 +285,41 @@
         this.viewLinks.add(viewLink);
     }
     
-    public EntityCondition getViewEntityConditionWhere(ModelFieldTypeReader modelFieldTypeReader) {
-        if (this.viewEntityCondition == null) return null;
-        EntityCondition viewEntityConditionWhere = this.viewEntityCondition.getWhereCondition(modelFieldTypeReader);
-        return viewEntityConditionWhere;
-    }
-    public EntityCondition getViewEntityConditionHaving(ModelFieldTypeReader modelFieldTypeReader) {
-        if (this.viewEntityCondition == null) return null;
-        EntityCondition viewEntityConditionHaving = this.viewEntityCondition.getHavingCondition(modelFieldTypeReader);
-        return viewEntityConditionHaving;
-    }
-    public List<String> getViewEntityConditionOrderBy() {
-        if (this.viewEntityCondition == null) return null;
-        return this.viewEntityCondition.getOrderByList();
+    public void populateViewEntityConditionInformation(ModelFieldTypeReader modelFieldTypeReader, List<EntityCondition> whereConditions, List<EntityCondition> havingConditions, List<String> orderByList, List<String> entityAliasStack) {
+        if (entityAliasStack == null) {
+            entityAliasStack = FastList.newInstance();
+        }
+        
+        if (this.viewEntityCondition != null) {
+            EntityCondition whereCondition = this.viewEntityCondition.getWhereCondition(modelFieldTypeReader, entityAliasStack);
+            if (whereCondition != null) {
+                whereConditions.add(whereCondition);
+            }
+        }
+        
+        if (this.viewEntityCondition != null) {
+            EntityCondition havingCondition = this.viewEntityCondition.getHavingCondition(modelFieldTypeReader, entityAliasStack);
+            if (havingCondition != null) {
+                havingConditions.add(havingCondition);
+            }
+        }
+        
+        // add the current one first so it overrides the lower level ones
+        if (this.viewEntityCondition != null) {
+            List<String> currentOrderByList = this.viewEntityCondition.getOrderByList();
+            if (currentOrderByList != null) {
+                orderByList.addAll(currentOrderByList);
+            }
+        }
+        
+        for (Map.Entry<String, ModelEntity> memberEntityEntry: this.memberModelEntities.entrySet()) {
+            if (memberEntityEntry.getValue() instanceof ModelViewEntity) {
+                ModelViewEntity memberViewEntity = (ModelViewEntity) memberEntityEntry.getValue();
+                entityAliasStack.add(memberEntityEntry.getKey());
+                memberViewEntity.populateViewEntityConditionInformation(modelFieldTypeReader, whereConditions, havingConditions, orderByList, entityAliasStack);
+                entityAliasStack.remove(entityAliasStack.size() - 1);
+            }
+        }
     }
 
     @Override
@@ -1115,6 +1130,7 @@
     
     public static class ViewEntityCondition {
         protected ModelViewEntity modelViewEntity;
+        protected ModelViewLink modelViewLink;
         protected boolean filterByDate;
         protected boolean distinct;
         protected List<String> orderByList;
@@ -1123,6 +1139,7 @@
 
         public ViewEntityCondition(ModelViewEntity modelViewEntity, ModelViewLink modelViewLink, Element element) {
             this.modelViewEntity = modelViewEntity;
+            this.modelViewLink = modelViewLink;
             this.filterByDate = "true".equals(element.getAttribute("filter-by-date"));
             this.distinct = "true".equals(element.getAttribute("distinct"));
             // process order-by
@@ -1152,17 +1169,17 @@
             return this.orderByList;
         }
         
-        public EntityCondition getWhereCondition(ModelFieldTypeReader modelFieldTypeReader) {
+        public EntityCondition getWhereCondition(ModelFieldTypeReader modelFieldTypeReader, List<String> entityAliasStack) {
             if (this.whereCondition != null) {
-                return this.whereCondition.createCondition(modelFieldTypeReader);
+                return this.whereCondition.createCondition(modelFieldTypeReader, entityAliasStack);
             } else {
                 return null;
             }
         }
         
-        public EntityCondition getHavingCondition(ModelFieldTypeReader modelFieldTypeReader) {
+        public EntityCondition getHavingCondition(ModelFieldTypeReader modelFieldTypeReader, List<String> entityAliasStack) {
             if (this.havingCondition != null) {
-                return this.havingCondition.createCondition(modelFieldTypeReader);
+                return this.havingCondition.createCondition(modelFieldTypeReader, entityAliasStack);
             } else {
                 return null;
             }
@@ -1170,8 +1187,9 @@
     }
 
     public static interface ViewCondition extends Serializable {
-        public EntityCondition createCondition(ModelFieldTypeReader modelFieldTypeReader);
+        public EntityCondition createCondition(ModelFieldTypeReader modelFieldTypeReader, List<String> entityAliasStack);
     }
+    
     public static class ViewConditionExpr implements ViewCondition {
         protected ViewEntityCondition viewEntityCondition;
         protected String entityAlias;
@@ -1192,10 +1210,20 @@
             this.relFieldName = conditionExprElement.getAttribute("rel-field-name");
             this.value = conditionExprElement.getAttribute("value");
             this.ignoreCase = "true".equals(conditionExprElement.getAttribute("ignore-case"));
+            
+            // if we are in a view-link, default to the entity-alias and rel-entity-alias there
+            if (this.viewEntityCondition.modelViewLink != null) {
+                if (UtilValidate.isEmpty(this.entityAlias)) {
+                    this.entityAlias = this.viewEntityCondition.modelViewLink.getEntityAlias();
+                }
+                if (UtilValidate.isEmpty(this.relEntityAlias)) {
+                    this.relEntityAlias = this.viewEntityCondition.modelViewLink.getRelEntityAlias();
+                }
+            }
         }
-
-        public EntityCondition createCondition(ModelFieldTypeReader modelFieldTypeReader) {
-            EntityOperator operator = EntityOperator.lookup(this.operator);
+        
+        public EntityCondition createCondition(ModelFieldTypeReader modelFieldTypeReader, List<String> entityAliasStack) {
+            EntityOperator<?> operator = EntityOperator.lookup(this.operator);
             if (operator == null) {
                 throw new IllegalArgumentException("Could not find an entity operator for the name: " + this.operator);
             }
@@ -1227,12 +1255,12 @@
 
             if (Debug.verboseOn()) Debug.logVerbose("Got value for fieldName [" + fieldName + "]: " + value, module);
             
-            Object lhs = EntityFieldValue.makeFieldValue(fieldName, entityAlias, this.viewEntityCondition.modelViewEntity);
+            EntityConditionValue lhs = EntityFieldValue.makeFieldValue(this.fieldName, this.entityAlias, entityAliasStack, this.viewEntityCondition.modelViewEntity);
             Object rhs = null;
             if (value != null) {
                 rhs = value;
             } else {
-                rhs = EntityFieldValue.makeFieldValue(relFieldName, relEntityAlias, this.viewEntityCondition.modelViewEntity);
+                rhs = EntityFieldValue.makeFieldValue(this.relFieldName, this.relEntityAlias, entityAliasStack, this.viewEntityCondition.modelViewEntity);
             }
             
             if (operator == EntityOperator.NOT_EQUAL && value != null) {
@@ -1281,24 +1309,24 @@
             }
         }
 
-        public EntityCondition createCondition(ModelFieldTypeReader modelFieldTypeReader) {
+        public EntityCondition createCondition(ModelFieldTypeReader modelFieldTypeReader, List<String> entityAliasStack) {
             if (this.conditionList.size() == 0) {
                 return null;
             }
             if (this.conditionList.size() == 1) {
                 ViewCondition condition = this.conditionList.get(0);
-                return condition.createCondition(modelFieldTypeReader);
+                return condition.createCondition(modelFieldTypeReader, entityAliasStack);
             }
 
             List<EntityCondition> entityConditionList = FastList.<EntityCondition>newInstance();
             for (ViewCondition curCondition: conditionList) {
-                EntityCondition econd = curCondition.createCondition(modelFieldTypeReader);
+                EntityCondition econd = curCondition.createCondition(modelFieldTypeReader, entityAliasStack);
                 if (econd != null) {
                     entityConditionList.add(econd);
                 }
             }
 
-            EntityOperator operator = EntityOperator.lookup(this.combine);
+            EntityOperator<?> operator = EntityOperator.lookup(this.combine);
             if (operator == null) {
                 throw new IllegalArgumentException("Could not find an entity operator for the name: " + operator);
             }

Modified: ofbiz/trunk/framework/example/entitydef/entitymodel_view.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/entitydef/entitymodel_view.xml?rev=792836&r1=792835&r2=792836&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/entitydef/entitymodel_view.xml (original)
+++ ofbiz/trunk/framework/example/entitydef/entitymodel_view.xml Fri Jul 10 08:47:16 2009
@@ -70,7 +70,6 @@
         <view-link entity-alias="EXFTAP" rel-entity-alias="EXFTAPTP">
             <key-map field-name="exampleFeatureApplTypeId"/>
         </view-link>
-        <entity-condition filter-by-date="true"/>
     </view-entity>
     <view-entity entity-name="ExampleFeatureAndApplAndType" package-name="org.ofbiz.example.example">
         <member-entity entity-alias="EXFT" entity-name="ExampleFeature"/>
@@ -101,16 +100,36 @@
             <order-by field-name="exampleName"/>
         </entity-condition>
     </view-entity>
+
+    <!-- example for nested view-entity with conditions on nested views -->
+    <view-entity entity-name="ExampleFeatureApplAndTypeDesired" package-name="org.ofbiz.example.example">
+        <member-entity entity-alias="EXFTAP" entity-name="ExampleFeatureAppl"/>
+        <member-entity entity-alias="EXFTAPTP" entity-name="ExampleFeatureApplType"/>
+        <alias-all entity-alias="EXFTAP"/>
+        <alias-all entity-alias="EXFTAPTP"/>
+        <view-link entity-alias="EXFTAP" rel-entity-alias="EXFTAPTP">
+            <key-map field-name="exampleFeatureApplTypeId"/>
+        </view-link>
+        <entity-condition>
+            <condition-expr field-name="exampleFeatureApplTypeId" value="DESIRED"/>
+        </entity-condition>
+    </view-entity>
     <view-entity entity-name="AllExamplesWithDesiredCustomerFeaturesReport" package-name="org.ofbiz.example.example">
-        <member-entity entity-alias="EFAAFV" entity-name="ExampleFeatureAndApplFullView"/>
-        <alias-all entity-alias="EFAAFV"/>
+        <member-entity entity-alias="EFAATD" entity-name="ExampleFeatureApplAndTypeDesired"/>
+        <member-entity entity-alias="EXFT" entity-name="ExampleFeature"/>
+        <member-entity entity-alias="EX" entity-name="Example"/>
+        <alias-all entity-alias="EFAATD"/>
+        <alias-all entity-alias="EXFT"/>
+        <alias-all entity-alias="EX"/>
+        <view-link entity-alias="EFAATD" rel-entity-alias="EXFT">
+            <key-map field-name="exampleFeatureId"/>
+        </view-link>
+        <view-link entity-alias="EFAATD" rel-entity-alias="EX">
+            <key-map field-name="exampleId"/>
+        </view-link>
         <entity-condition>
-            <condition-list combine="and">
-                <condition-expr field-name="featureSourceEnumId" value="EXFTSRC_CUSTOMER"/>
-                <condition-expr field-name="exampleFeatureApplTypeId" value="DESIRED"/>
-            </condition-list>
+            <condition-expr field-name="featureSourceEnumId" value="EXFTSRC_CUSTOMER"/>
             <order-by field-name="exampleName"/>
         </entity-condition>
     </view-entity>
-    <!-- TODO: add example for nested view-entity with conditions on nested views, and fix underlying code since probably won't work right now -->
 </entitymodel>