You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2012/04/27 08:57:39 UTC

svn commit: r1331250 - in /ofbiz/branches/release10.04: ./ framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java

Author: jleroux
Date: Fri Apr 27 06:57:39 2012
New Revision: 1331250

URL: http://svn.apache.org/viewvc?rev=1331250&view=rev
Log:
"Applied fix from trunk for revision: 1327735" 
------------------------------------------------------------------------
r1327735 | doogie | 2012-04-19 01:48:40 +0200 (jeu., 19 avr. 2012) | 11 lines

FEATURE/FIX: <entity-condition> on views are now done correctly.  When a
view was previously joined to another view, the conditions on the inner
view were added to the outer-most WHERE clause.  This caused multiple
problems.  One, if the join was optional, the generated sql actually made
it required(because it was in the WHERE, and not in the ON clause).
Second, the outer WHERE may reference a field that was not available *at
all* in the generated nested select(view table).

The fix is to *not* recurse thru all view member entities when finding
conditions, and instead attach them to a new WHERE clause on the
generated inner SELECT(view table).
------------------------------------------------------------------------


Modified:
    ofbiz/branches/release10.04/   (props changed)
    ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java
    ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java

Propchange: ofbiz/branches/release10.04/
------------------------------------------------------------------------------
  Merged /ofbiz/trunk:r1327735

Modified: ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java?rev=1331250&r1=1331249&r2=1331250&view=diff
==============================================================================
--- ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java (original)
+++ ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java Fri Apr 27 06:57:39 2012
@@ -40,6 +40,7 @@ import java.util.TreeSet;
 import javax.sql.rowset.serial.SerialBlob;
 import javax.sql.rowset.serial.SerialClob;
 
+import javolution.util.FastList;
 import javolution.util.FastMap;
 
 import org.ofbiz.base.util.Debug;
@@ -53,6 +54,7 @@ import org.ofbiz.entity.GenericModelExce
 import org.ofbiz.entity.GenericNotImplementedException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.condition.EntityConditionParam;
+import org.ofbiz.entity.condition.EntityOperator;
 import org.ofbiz.entity.condition.OrderByList;
 import org.ofbiz.entity.config.DatasourceInfo;
 import org.ofbiz.entity.model.ModelEntity;
@@ -404,11 +406,31 @@ public class SqlJdbcUtil {
             }
             sql.append(makeFromClause(modelEntity, datasourceInfo));
             String viewWhereClause = makeViewWhereClause(modelEntity, datasourceInfo.joinStyle);
-            if (UtilValidate.isNotEmpty(viewWhereClause)) {
+            ModelViewEntity modelViewEntity = (ModelViewEntity)modelEntity;
+            List<EntityCondition> whereConditions = FastList.newInstance();
+            List<EntityCondition> havingConditions = FastList.newInstance();
+            List<String> orderByList = FastList.newInstance();
+
+            modelViewEntity.populateViewEntityConditionInformation(modelFieldTypeReader, whereConditions, havingConditions, orderByList, null);
+            String viewConditionClause;
+            if (!whereConditions.isEmpty()) {
+                viewConditionClause = EntityCondition.makeCondition(whereConditions, EntityOperator.AND).makeWhereString(modelViewEntity,  null, datasourceInfo);
+            } else {
+                viewConditionClause = null;
+            }
+            if (UtilValidate.isNotEmpty(viewWhereClause) || UtilValidate.isNotEmpty(viewConditionClause)) {
                 sql.append(" WHERE ");
-                sql.append(viewWhereClause);
+                if (UtilValidate.isNotEmpty(viewWhereClause)) {
+                    sql.append("(").append(viewWhereClause).append(")");
+                    if (UtilValidate.isNotEmpty(viewConditionClause)) {
+                        sql.append(" AND ");
+                    }
+                }
+                if (UtilValidate.isNotEmpty(viewConditionClause)) {
+                    sql.append("(").append(viewConditionClause).append(")");
+                }
             }
-            ModelViewEntity modelViewEntity = (ModelViewEntity)modelEntity;
+            // FIXME: handling HAVING, don't need ORDER BY for nested views
             String groupByString = modelViewEntity.colNameString(modelViewEntity.getGroupBysCopy(), ", ", "", false);
             if (UtilValidate.isNotEmpty(groupByString)) {
                 sql.append(" GROUP BY ");

Modified: ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java?rev=1331250&r1=1331249&r2=1331250&view=diff
==============================================================================
--- ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java (original)
+++ ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java Fri Apr 27 06:57:39 2012
@@ -315,16 +315,6 @@ public class ModelViewEntity extends Mod
                 orderByList.addAll(currentOrderByList);
             }
         }
-
-        for (Map.Entry<String, String> memberEntityEntry: this.memberModelEntities.entrySet()) {
-            ModelEntity modelEntity = this.getModelReader().getModelEntityNoCheck(memberEntityEntry.getValue());
-            if (modelEntity instanceof ModelViewEntity) {
-                ModelViewEntity memberViewEntity = (ModelViewEntity) modelEntity;
-                entityAliasStack.add(memberEntityEntry.getKey());
-                memberViewEntity.populateViewEntityConditionInformation(modelFieldTypeReader, whereConditions, havingConditions, orderByList, entityAliasStack);
-                entityAliasStack.remove(entityAliasStack.size() - 1);
-            }
-        }
     }
 
     @Override