Author: jleroux
Date: Thu Sep 5 07:13:10 2019 New Revision: 1866439 URL: http://svn.apache.org/viewvc?rev=1866439&view=rev Log: Improved: Change current view-link requirement to allow use of entity-condition only in view-entities (OFBIZ-11179) To explain the subject, i will give an example encountered recently: We used, for a customer project, a view with Agreement, Virtual and Variant product entities and where the agreement can be attached to a virtual OR a variant product. So to make a view returning Variant Product, Virtual Product AND Agreement informations, i could not create a view, as the key-map link is mandatory and made it impossible. I can not have an alternative relation to the same entity so we have to duplicate member-entity and an alternative relation path. The result is a complicated and ugly entity-view I think this can have been much simpler if i could have done it directly through the entity-condition (see the AGPA/PDTA view link in attached file ExampleWithoutKeyMap.xml) So the purpose is to add the possibility to create a view-link without key map, if there is an entity-condition. You can test by applying the given patch and add the entity view from attached file ExampleWithoutKeyMap.xml Thanks: Leila Mekika Modified: ofbiz/ofbiz-framework/trunk/framework/entity/dtd/entitymodel.xsd ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/SqlJdbcUtil.java Modified: ofbiz/ofbiz-framework/trunk/framework/entity/dtd/entitymodel.xsd URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/dtd/entitymodel.xsd?rev=1866439&r1=1866438&r2=1866439&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entity/dtd/entitymodel.xsd (original) +++ ofbiz/ofbiz-framework/trunk/framework/entity/dtd/entitymodel.xsd Thu Sep 5 07:13:10 2019 @@ -384,7 +384,7 @@ under the License. <xs:complexType> <xs:sequence> <xs:element minOccurs="0" ref="description"/> - <xs:element maxOccurs="unbounded" ref="key-map"/> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="key-map"/> <xs:element minOccurs="0" ref="entity-condition"/> </xs:sequence> <xs:attributeGroup ref="attlist.view-link"/> Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/SqlJdbcUtil.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/SqlJdbcUtil.java?rev=1866439&r1=1866438&r2=1866439&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/SqlJdbcUtil.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/SqlJdbcUtil.java Thu Sep 5 07:13:10 2019 @@ -193,6 +193,7 @@ public final class SqlJdbcUtil { StringBuilder condBuffer = new StringBuilder(); + ModelViewEntity.ViewEntityCondition viewEntityCondition = viewLink.getViewEntityCondition(); for (int j = 0; j < viewLink.getKeyMapsSize(); j++) { ModelKeyMap keyMap = viewLink.getKeyMap(j); ModelField linkField = linkEntity.getField(keyMap.getFieldName()); @@ -218,14 +219,13 @@ public final class SqlJdbcUtil { condBuffer.append("."); condBuffer.append(relLinkField.getColName()); } - if (condBuffer.length() == 0) { + if (condBuffer.length() == 0 && viewEntityCondition == null) { throw new GenericModelException("No view-link/join key-maps found for the " + viewLink.getEntityAlias() + " and the " + viewLink.getRelEntityAlias() + " member-entities of the " + modelViewEntity.getEntityName() + " view-entity."); } - ModelViewEntity.ViewEntityCondition viewEntityCondition = viewLink.getViewEntityCondition(); if (viewEntityCondition != null) { EntityCondition whereCondition = viewEntityCondition.getWhereCondition(modelFieldTypeReader, null); - condBuffer.append(" AND "); + if (condBuffer.length() > 0) condBuffer.append(" AND "); condBuffer.append(whereCondition.makeWhereString(modelEntity, null, datasourceInfo)); } |
Free forum by Nabble | Edit this page |