Author: jleroux
Date: Fri Apr 27 06:57:45 2012 New Revision: 1331251 URL: http://svn.apache.org/viewvc?rev=1331251&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/release11.04/ (props changed) ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java Propchange: ofbiz/branches/release11.04/ ------------------------------------------------------------------------------ Merged /ofbiz/trunk:r1327735 Modified: ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java?rev=1331251&r1=1331250&r2=1331251&view=diff ============================================================================== --- ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java (original) +++ ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java Fri Apr 27 06:57:45 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.jdbc.JdbcValueHandler; @@ -413,11 +415,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 modelViewEntity.colNameString(modelViewEntity.getGroupBysCopy(), sql, " GROUP BY ", ", ", "", false); sql.append(")"); Modified: ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java?rev=1331251&r1=1331250&r2=1331251&view=diff ============================================================================== --- ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java (original) +++ ofbiz/branches/release11.04/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java Fri Apr 27 06:57:45 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); - } - } } @Deprecated @Override |
Free forum by Nabble | Edit this page |