[OFBiz] SVN: r5510 - in trunk/applications/product: entitydef
script/org/ofbiz/product/product src/org/ofbiz/product/product
jonesde at svn.ofbiz.org
jonesde at svn.ofbiz.org
Wed Aug 10 23:40:48 EDT 2005
Author: jonesde
Date: 2005-08-10 22:40:43 -0500 (Wed, 10 Aug 2005)
New Revision: 5510
Modified:
trunk/applications/product/entitydef/entitygroup.xml
trunk/applications/product/entitydef/entitymodel.xml
trunk/applications/product/script/org/ofbiz/product/product/ProductServices.xml
trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java
Log:
Finally decided to fix the issue where these summary fields are on the Product entity, have created new ProductCalculatedInfo entity and moved these fields over, avoids so many updates on the Product entity
Modified: trunk/applications/product/entitydef/entitygroup.xml
===================================================================
--- trunk/applications/product/entitydef/entitygroup.xml 2005-08-11 03:37:56 UTC (rev 5509)
+++ trunk/applications/product/entitydef/entitygroup.xml 2005-08-11 03:40:43 UTC (rev 5510)
@@ -136,6 +136,7 @@
<entity-group group="org.ofbiz" entity="ProductAssoc" />
<entity-group group="org.ofbiz" entity="ProductAssocType" />
<entity-group group="org.ofbiz" entity="ProductAttribute" />
+ <entity-group group="org.ofbiz" entity="ProductCalculatedInfo" />
<entity-group group="org.ofbiz" entity="ProductContent" />
<entity-group group="org.ofbiz" entity="ProductContentAndInfo" />
<entity-group group="org.ofbiz" entity="ProductContentType" />
Modified: trunk/applications/product/entitydef/entitymodel.xml
===================================================================
--- trunk/applications/product/entitydef/entitymodel.xml 2005-08-11 03:37:56 UTC (rev 5509)
+++ trunk/applications/product/entitydef/entitymodel.xml 2005-08-11 03:40:43 UTC (rev 5510)
@@ -1559,9 +1559,6 @@
<field name="isVirtual" type="indicator"></field>
<field name="isVariant" type="indicator"></field>
<field name="requirementMethodEnumId" type="id"></field>
- <field name="totalQuantityOrdered" type="floating-point"></field>
- <field name="totalTimesViewed" type="numeric"></field>
- <field name="averageCustomerRating" type="floating-point"></field>
<field name="billOfMaterialLevel" type="numeric"></field>
<!-- maximum number of persons who can rent this asset at the same time -->
<field name="reservMaxPersons" type="floating-point"/>
@@ -1686,6 +1683,18 @@
<key-map field-name="attrName"/>
</relation>
</entity>
+ <entity entity-name="ProductCalculatedInfo"
+ package-name="org.ofbiz.product.product"
+ title="Product Calculated Info Entity">
+ <field name="productId" type="id-ne"></field>
+ <field name="totalQuantityOrdered" type="floating-point"></field>
+ <field name="totalTimesViewed" type="numeric"></field>
+ <field name="averageCustomerRating" type="floating-point"></field>
+ <prim-key field="productId"/>
+ <relation type="one" fk-name="PROD_ATTR" rel-entity-name="Product">
+ <key-map field-name="productId"/>
+ </relation>
+ </entity>
<entity entity-name="ProductContent"
package-name="org.ofbiz.product.product"
title="Product Data Object Entity">
Modified: trunk/applications/product/script/org/ofbiz/product/product/ProductServices.xml
===================================================================
--- trunk/applications/product/script/org/ofbiz/product/product/ProductServices.xml 2005-08-11 03:37:56 UTC (rev 5509)
+++ trunk/applications/product/script/org/ofbiz/product/product/ProductServices.xml 2005-08-11 03:40:43 UTC (rev 5510)
@@ -333,21 +333,28 @@
</simple-method>
<simple-method method-name="countProductView" short-description="Count Product View" login-required="false">
- <env-to-env env-name="parameters.productId" to-env-name="productLookupMap.productId"/>
- <string-to-list string="totalTimesViewed" list-name="fieldsToSelect"/>
- <string-to-list string="isVariant" list-name="fieldsToSelect"/>
- <find-by-primary-key entity-name="Product" map-name="productLookupMap" fields-to-select-list="fieldsToSelect" value-name="product" use-cache="false"/>
<if-empty field-name="parameters.weight">
<calculate field-name="parameters.weight" type="Long"><number value="1"/></calculate>
</if-empty>
- <calculate field-name="product.totalTimesViewed" type="Long">
- <calcop field-name="product.totalTimesViewed" operator="add">
- <calcop field-name="parameters.weight" operator="get"></calcop>
- </calcop>
- </calculate>
- <store-value value-name="product"/>
+ <entity-one entity-name="ProductCalculatedInfo" value-name="productCalculatedInfo"/>
+ <if-empty field-name="productCalculatedInfo">
+ <!-- go ahead and create it -->
+ <make-value value-name="productCalculatedInfo" entity-name="ProductCalculatedInfo"/>
+ <env-to-env env-name="parameters.productId" to-env-name="productCalculatedInfo.productId"/>
+ <env-to-env env-name="parameters.weight" to-env-name="productCalculatedInfo.totalTimesViewed"/>
+ <create-value value-name="productCalculatedInfo"/>
+ <else>
+ <calculate field-name="productCalculatedInfo.totalTimesViewed" type="Long">
+ <calcop field-name="productCalculatedInfo.totalTimesViewed" operator="add">
+ <calcop field-name="parameters.weight" operator="get"></calcop>
+ </calcop>
+ </calculate>
+ <store-value value-name="productCalculatedInfo"/>
+ </else>
+ </if-empty>
<!-- do the same for the virtual product... -->
+ <entity-one entity-name="Product" value-name="product" use-cache="true"/>
<call-class-method class-name="org.ofbiz.product.product.ProductWorker" method-name="getVariantVirtualId" ret-field-name="virtualProductId">
<field field-name="product" type="GenericValue"/>
</call-class-method>
@@ -358,21 +365,28 @@
</if-not-empty>
</simple-method>
<simple-method method-name="countProductQuantityOrdered" short-description="Count Product Quantity Ordered" login-required="true">
- <env-to-env env-name="parameters.productId" to-env-name="productLookupMap.productId"/>
- <string-to-list string="totalQuantityOrdered" list-name="fieldsToSelect"/>
- <string-to-list string="isVariant" list-name="fieldsToSelect"/>
- <find-by-primary-key entity-name="Product" map-name="productLookupMap" fields-to-select-list="fieldsToSelect" value-name="product" use-cache="false"/>
<if-empty field-name="parameters.quantity">
<calculate field-name="parameters.quantity" type="Double"><number value="1"/></calculate>
</if-empty>
- <calculate field-name="product.totalQuantityOrdered" type="Double">
- <calcop field-name="product.totalQuantityOrdered" operator="add">
- <calcop field-name="parameters.quantity" operator="get"></calcop>
- </calcop>
- </calculate>
- <store-value value-name="product"/>
+ <entity-one entity-name="ProductCalculatedInfo" value-name="productCalculatedInfo"/>
+ <if-empty field-name="productCalculatedInfo">
+ <!-- go ahead and create it -->
+ <make-value value-name="productCalculatedInfo" entity-name="ProductCalculatedInfo"/>
+ <env-to-env env-name="parameters.productId" to-env-name="productCalculatedInfo.productId"/>
+ <env-to-env env-name="parameters.quantity" to-env-name="productCalculatedInfo.totalQuantityOrdered"/>
+ <create-value value-name="productCalculatedInfo"/>
+ <else>
+ <calculate field-name="productCalculatedInfo.totalQuantityOrdered" type="Double">
+ <calcop field-name="productCalculatedInfo.totalQuantityOrdered" operator="add">
+ <calcop field-name="parameters.quantity" operator="get"></calcop>
+ </calcop>
+ </calculate>
+ <store-value value-name="productCalculatedInfo"/>
+ </else>
+ </if-empty>
<!-- do the same for the virtual product... -->
+ <entity-one entity-name="Product" value-name="product" use-cache="true"/>
<call-class-method class-name="org.ofbiz.product.product.ProductWorker" method-name="getVariantVirtualId" ret-field-name="virtualProductId">
<field field-name="product" type="GenericValue"/>
</call-class-method>
@@ -550,16 +564,25 @@
</simple-method>
<simple-method method-name="updateProductWithReviewRatingAvg" short-description="Update Product with new Review Rating Avg">
<!-- this method is meant to be called in-line and depends in a productId parameter -->
- <!-- update the review average on the Product entity -->
- <make-value entity-name="Product" value-name="product"/>
- <env-to-env env-name="productId" to-env-name="product.productId"/>
- <call-class-method class-name="org.ofbiz.product.product.ProductWorker" method-name="getAverageProductRating" ret-field-name="product.averageCustomerRating">
+ <call-class-method class-name="org.ofbiz.product.product.ProductWorker" method-name="getAverageProductRating" ret-field-name="averageCustomerRating">
<field field-name="delegator" type="org.ofbiz.entity.GenericDelegator"/>
<field field-name="productId" type="java.lang.String"/>
</call-class-method>
<log level="info" message="Got new average customer rating ${product.averageCustomerRating}"/>
-
- <store-value value-name="product"/>
+
+ <!-- update the review average on the ProductCalculatedInfo entity -->
+ <entity-one entity-name="ProductCalculatedInfo" value-name="productCalculatedInfo"/>
+ <if-empty field-name="productCalculatedInfo">
+ <!-- go ahead and create it -->
+ <make-value value-name="productCalculatedInfo" entity-name="ProductCalculatedInfo"/>
+ <env-to-env env-name="parameters.productId" to-env-name="productCalculatedInfo.productId"/>
+ <env-to-env env-name="averageCustomerRating" to-env-name="productCalculatedInfo.averageCustomerRating"/>
+ <create-value value-name="productCalculatedInfo"/>
+ <else>
+ <env-to-env env-name="averageCustomerRating" to-env-name="productCalculatedInfo.averageCustomerRating"/>
+ <store-value value-name="productCalculatedInfo"/>
+ </else>
+ </if-empty>
</simple-method>
<simple-method method-name="copyToProductVariants" short-description="Updates the Product's Variants">
<string-to-field string="copyToProductVariants" field-name="callingMethodName"/>
Modified: trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java
===================================================================
--- trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java 2005-08-11 03:37:56 UTC (rev 5509)
+++ trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java 2005-08-11 03:40:43 UTC (rev 5510)
@@ -167,6 +167,8 @@
this.delegator = delegator;
this.visitId = visitId;
dynamicViewEntity.addMemberEntity("PROD", "Product");
+ dynamicViewEntity.addMemberEntity("PRODCI", "ProductCalculatedInfo");
+ dynamicViewEntity.addViewLink("PROD", "PRODCI", Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId"));
}
public GenericDelegator getDelegator() {
@@ -1063,7 +1065,11 @@
}
public void setSortOrder(ProductSearchContext productSearchContext) {
- productSearchContext.dynamicViewEntity.addAlias("PROD", fieldName);
+ if (productSearchContext.getDelegator().getModelEntity("Product").isField(fieldName)) {
+ productSearchContext.dynamicViewEntity.addAlias("PROD", fieldName);
+ } else if (productSearchContext.getDelegator().getModelEntity("ProductCalculatedInfo").isField(fieldName)) {
+ productSearchContext.dynamicViewEntity.addAlias("PRODCI", fieldName);
+ }
if (ascending) {
productSearchContext.orderByList.add("+" + fieldName);
} else {
More information about the Svn
mailing list