You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by as...@apache.org on 2014/11/22 12:26:21 UTC
svn commit: r1641044 [2/4] - in
/ofbiz/trunk/applications/product/src/org/ofbiz: product/catalog/
product/category/ product/config/ product/feature/ product/imagemanagement/
product/inventory/ product/price/ product/product/ product/promo/
product/spre...
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java?rev=1641044&r1=1641043&r2=1641044&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java Sat Nov 22 11:26:20 2014
@@ -123,7 +123,7 @@ public class PriceServices {
productStoreGroupId = productStore.getString("primaryStoreGroupId");
} else {
// no ProductStore.primaryStoreGroupId, try ProductStoreGroupMember
- List<GenericValue> productStoreGroupMemberList = delegator.findByAnd("ProductStoreGroupMember", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("sequenceNum", "-fromDate"), true);
+ List<GenericValue> productStoreGroupMemberList = EntityQuery.use(delegator).from("ProductStoreGroupMember").where("productStoreId", productStoreId).orderBy("sequenceNum", "-fromDate").cache(true).queryList();
productStoreGroupMemberList = EntityUtil.filterByDate(productStoreGroupMemberList, true);
if (productStoreGroupMemberList.size() > 0) {
GenericValue productStoreGroupMember = EntityUtil.getFirst(productStoreGroupMemberList);
@@ -176,7 +176,7 @@ public class PriceServices {
List<GenericValue> virtualProductPrices = null;
if (virtualProductId != null) {
try {
- virtualProductPrices = delegator.findByAnd("ProductPrice", UtilMisc.toMap("productId", virtualProductId, "currencyUomId", currencyDefaultUomId, "productStoreGroupId", productStoreGroupId), UtilMisc.toList("-fromDate"), true);
+ virtualProductPrices = EntityQuery.use(delegator).from("ProductPrice").where("productId", virtualProductId, "currencyUomId", currencyDefaultUomId, "productStoreGroupId", productStoreGroupId).orderBy("-fromDate").cache(true).queryList();
} catch (GenericEntityException e) {
Debug.logError(e, "An error occurred while getting the product prices", module);
}
@@ -222,7 +222,7 @@ public class PriceServices {
// for prices, get all ProductPrice entities for this productId and currencyUomId
List<GenericValue> productPrices = null;
try {
- productPrices = delegator.findList("ProductPrice", productPriceEc, null, UtilMisc.toList("-fromDate"), null, true);
+ productPrices = EntityQuery.use(delegator).from("ProductPrice").where(productPriceEc).orderBy("-fromDate").cache(true).queryList();
} catch (GenericEntityException e) {
Debug.logError(e, "An error occurred while getting the product prices", module);
}
@@ -238,8 +238,7 @@ public class PriceServices {
// ProductPrice entity.
if (UtilValidate.isNotEmpty(agreementId)) {
try {
- List<GenericValue> agreementPrices = delegator.findByAnd("AgreementItemAndProductAppl", UtilMisc.toMap("agreementId", agreementId, "productId", productId, "currencyUomId", currencyDefaultUomId), null, false);
- GenericValue agreementPriceValue = EntityUtil.getFirst(agreementPrices);
+ GenericValue agreementPriceValue = EntityQuery.use(delegator).from("AgreementItemAndProductAppl").where("agreementId", agreementId, "productId", productId, "currencyUomId", currencyDefaultUomId).queryFirst();
if (agreementPriceValue != null && agreementPriceValue.get("price") != null) {
defaultPriceValue = agreementPriceValue;
}
@@ -266,12 +265,12 @@ public class PriceServices {
//use the cache to find the variant with the lowest default price
try {
- List<GenericValue> variantAssocList = EntityUtil.filterByDate(delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", product.get("productId"), "productAssocTypeId", "PRODUCT_VARIANT"), UtilMisc.toList("-fromDate"), true));
+ List<GenericValue> variantAssocList = EntityQuery.use(delegator).from("ProductAssoc").where("productId", product.get("productId"), "productAssocTypeId", "PRODUCT_VARIANT").orderBy("-fromDate").cache(true).filterByDate().queryList();
BigDecimal minDefaultPrice = null;
List<GenericValue> variantProductPrices = null;
for (GenericValue variantAssoc: variantAssocList) {
String curVariantProductId = variantAssoc.getString("productIdTo");
- List<GenericValue> curVariantPriceList = EntityUtil.filterByDate(delegator.findByAnd("ProductPrice", UtilMisc.toMap("productId", curVariantProductId), UtilMisc.toList("-fromDate"), true), nowTimestamp);
+ List<GenericValue> curVariantPriceList = EntityQuery.use(delegator).from("ProductPrice").where("productId", curVariantProductId).orderBy("-fromDate").cache(true).filterByDate(nowTimestamp).queryList();
List<GenericValue> tempDefaultPriceList = EntityUtil.filterByAnd(curVariantPriceList, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE"));
GenericValue curDefaultPriceValue = EntityUtil.getFirst(tempDefaultPriceList);
if (curDefaultPriceValue != null) {
@@ -430,7 +429,7 @@ public class PriceServices {
quantityProductPriceRules = FastList.newInstance();
nonQuantityProductPriceRules = FastList.newInstance();
for (GenericValue productPriceRule: allProductPriceRules) {
- List<GenericValue> productPriceCondList = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("productPriceRuleId", productPriceRule.get("productPriceRuleId")), null, true);
+ List<GenericValue> productPriceCondList = EntityQuery.use(delegator).from("ProductPriceCond").where("productPriceRuleId", productPriceRule.get("productPriceRuleId")).cache(true).queryList();
boolean foundQuantityInputParam = false;
// only consider a rule if all conditions except the quantity condition are true
@@ -655,7 +654,7 @@ public class PriceServices {
// by productCategoryId
// for we will always include any rules that go by category, shouldn't be too many to iterate through each time and will save on cache entries
// note that we always want to put the category, quantity, etc ones that find all rules with these conditions in separate cache lists so that they can be easily cleared
- Collection<GenericValue> productCategoryIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_CAT_ID"), null, true);
+ Collection<GenericValue> productCategoryIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PROD_CAT_ID").cache(true).queryList();
if (UtilValidate.isNotEmpty(productCategoryIdConds)) {
for (GenericValue productCategoryIdCond: productCategoryIdConds) {
productPriceRuleIds.add(productCategoryIdCond.getString("productPriceRuleId"));
@@ -663,7 +662,7 @@ public class PriceServices {
}
// by productFeatureId
- Collection<GenericValue> productFeatureIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_FEAT_ID"), null, true);
+ Collection<GenericValue> productFeatureIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PROD_FEAT_ID").cache(true).queryList();
if (UtilValidate.isNotEmpty(productFeatureIdConds)) {
for (GenericValue productFeatureIdCond: productFeatureIdConds) {
productPriceRuleIds.add(productFeatureIdCond.getString("productPriceRuleId"));
@@ -673,7 +672,7 @@ public class PriceServices {
// by quantity -- should we really do this one, ie is it necessary?
// we could say that all rules with quantity on them must have one of these other values
// but, no we'll do it the other way, any that have a quantity will always get compared
- Collection<GenericValue> quantityConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_QUANTITY"), null, true);
+ Collection<GenericValue> quantityConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_QUANTITY").cache(true).queryList();
if (UtilValidate.isNotEmpty(quantityConds)) {
for (GenericValue quantityCond: quantityConds) {
productPriceRuleIds.add(quantityCond.getString("productPriceRuleId"));
@@ -681,7 +680,7 @@ public class PriceServices {
}
// by roleTypeId
- Collection<GenericValue> roleTypeIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_ROLE_TYPE"), null, true);
+ Collection<GenericValue> roleTypeIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_ROLE_TYPE").cache(true).queryList();
if (UtilValidate.isNotEmpty(roleTypeIdConds)) {
for (GenericValue roleTypeIdCond: roleTypeIdConds) {
productPriceRuleIds.add(roleTypeIdCond.getString("productPriceRuleId"));
@@ -693,7 +692,7 @@ public class PriceServices {
// later: (by partyClassificationTypeId)
// by listPrice
- Collection<GenericValue> listPriceConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_LIST_PRICE"), null, true);
+ Collection<GenericValue> listPriceConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_LIST_PRICE").cache(true).queryList();
if (UtilValidate.isNotEmpty(listPriceConds)) {
for (GenericValue listPriceCond: listPriceConds) {
productPriceRuleIds.add(listPriceCond.getString("productPriceRuleId"));
@@ -703,7 +702,7 @@ public class PriceServices {
// ------- These are all of them that DO depend on the current inputs -------
// by productId
- Collection<GenericValue> productIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", productId), null, true);
+ Collection<GenericValue> productIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", productId).cache(true).queryList();
if (UtilValidate.isNotEmpty(productIdConds)) {
for (GenericValue productIdCond: productIdConds) {
productPriceRuleIds.add(productIdCond.getString("productPriceRuleId"));
@@ -712,7 +711,7 @@ public class PriceServices {
// by virtualProductId, if not null
if (virtualProductId != null) {
- Collection<GenericValue> virtualProductIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", virtualProductId), null, true);
+ Collection<GenericValue> virtualProductIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", virtualProductId).cache(true).queryList();
if (UtilValidate.isNotEmpty(virtualProductIdConds)) {
for (GenericValue virtualProductIdCond: virtualProductIdConds) {
productPriceRuleIds.add(virtualProductIdCond.getString("productPriceRuleId"));
@@ -722,7 +721,7 @@ public class PriceServices {
// by prodCatalogId - which is optional in certain cases
if (UtilValidate.isNotEmpty(prodCatalogId)) {
- Collection<GenericValue> prodCatalogIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_CLG_ID", "condValue", prodCatalogId), null, true);
+ Collection<GenericValue> prodCatalogIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PROD_CLG_ID", "condValue", prodCatalogId).cache(true).queryList();
if (UtilValidate.isNotEmpty(prodCatalogIdConds)) {
for (GenericValue prodCatalogIdCond: prodCatalogIdConds) {
productPriceRuleIds.add(prodCatalogIdCond.getString("productPriceRuleId"));
@@ -732,7 +731,7 @@ public class PriceServices {
// by productStoreGroupId
if (UtilValidate.isNotEmpty(productStoreGroupId)) {
- Collection<GenericValue> storeGroupConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_SGRP_ID", "condValue", productStoreGroupId), null, true);
+ Collection<GenericValue> storeGroupConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PROD_SGRP_ID", "condValue", productStoreGroupId).cache(true).queryList();
if (UtilValidate.isNotEmpty(storeGroupConds)) {
for (GenericValue storeGroupCond: storeGroupConds) {
productPriceRuleIds.add(storeGroupCond.getString("productPriceRuleId"));
@@ -742,7 +741,7 @@ public class PriceServices {
// by webSiteId
if (UtilValidate.isNotEmpty(webSiteId)) {
- Collection<GenericValue> webSiteIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_WEBSITE_ID", "condValue", webSiteId), null, true);
+ Collection<GenericValue> webSiteIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_WEBSITE_ID", "condValue", webSiteId).cache(true).queryList();
if (UtilValidate.isNotEmpty(webSiteIdConds)) {
for (GenericValue webSiteIdCond: webSiteIdConds) {
productPriceRuleIds.add(webSiteIdCond.getString("productPriceRuleId"));
@@ -752,7 +751,7 @@ public class PriceServices {
// by partyId
if (UtilValidate.isNotEmpty(partyId)) {
- Collection<GenericValue> partyIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PARTY_ID", "condValue", partyId), null, true);
+ Collection<GenericValue> partyIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PARTY_ID", "condValue", partyId).cache(true).queryList();
if (UtilValidate.isNotEmpty(partyIdConds)) {
for (GenericValue partyIdCond: partyIdConds) {
productPriceRuleIds.add(partyIdCond.getString("productPriceRuleId"));
@@ -761,7 +760,7 @@ public class PriceServices {
}
// by currencyUomId
- Collection<GenericValue> currencyUomIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_CURRENCY_UOMID", "condValue", currencyUomId), null, true);
+ Collection<GenericValue> currencyUomIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_CURRENCY_UOMID", "condValue", currencyUomId).cache(true).queryList();
if (UtilValidate.isNotEmpty(currencyUomIdConds)) {
for (GenericValue currencyUomIdCond: currencyUomIdConds) {
productPriceRuleIds.add(currencyUomIdCond.getString("productPriceRuleId"));
@@ -780,7 +779,7 @@ public class PriceServices {
// EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, UtilDateTime.nowTimestamp()));
// productPriceRules = delegator.findByOr("ProductPriceRule", pprExprs);
- productPriceRules = delegator.findList("ProductPriceRule", null, null, null, null, true);
+ productPriceRules = EntityQuery.use(delegator).from("ProductPriceRule").cache(true).queryList();
if (productPriceRules == null) productPriceRules = FastList.newInstance();
}
@@ -830,7 +829,7 @@ public class PriceServices {
// check all conditions
boolean allTrue = true;
StringBuilder condsDescription = new StringBuilder();
- List<GenericValue> productPriceConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("productPriceRuleId", productPriceRuleId), null, true);
+ List<GenericValue> productPriceConds = EntityQuery.use(delegator).from("ProductPriceCond").where("productPriceRuleId", productPriceRuleId).cache(true).queryList();
for (GenericValue productPriceCond: productPriceConds) {
totalConds++;
@@ -872,7 +871,7 @@ public class PriceServices {
isSale = true;
}
- List<GenericValue> productPriceActions = delegator.findByAnd("ProductPriceAction", UtilMisc.toMap("productPriceRuleId", productPriceRuleId), null, true);
+ List<GenericValue> productPriceActions = EntityQuery.use(delegator).from("ProductPriceAction").where("productPriceRuleId", productPriceRuleId).cache(true).queryList();
for (GenericValue productPriceAction: productPriceActions) {
totalActions++;
@@ -1052,10 +1051,12 @@ public class PriceServices {
} else if ("PRIP_PROD_CAT_ID".equals(productPriceCond.getString("inputParamEnumId"))) {
// if a ProductCategoryMember exists for this productId and the specified productCategoryId
String productCategoryId = productPriceCond.getString("condValue");
- List<GenericValue> productCategoryMembers = delegator.findByAnd("ProductCategoryMember",
- UtilMisc.toMap("productId", productId, "productCategoryId", productCategoryId), null, true);
// and from/thru date within range
- productCategoryMembers = EntityUtil.filterByDate(productCategoryMembers, nowTimestamp, null, null, true);
+ List<GenericValue> productCategoryMembers = EntityQuery.use(delegator).from("ProductCategoryMember")
+ .where("productId", productId, "productCategoryId", productCategoryId)
+ .cache(true)
+ .filterByDate(nowTimestamp)
+ .queryList();
// then 0 (equals), otherwise 1 (not equals)
if (UtilValidate.isNotEmpty(productCategoryMembers)) {
compare = 0;
@@ -1067,10 +1068,8 @@ public class PriceServices {
// NOTE: this is important becuase of the common scenario where a virtual product is a member of a category but the variants will typically NOT be
// NOTE: we may want to parameterize this in the future, ie with an indicator on the ProductPriceCond entity
if (compare == 1 && UtilValidate.isNotEmpty(virtualProductId)) {
- List<GenericValue> virtualProductCategoryMembers = delegator.findByAnd("ProductCategoryMember",
- UtilMisc.toMap("productId", virtualProductId, "productCategoryId", productCategoryId), null, true);
// and from/thru date within range
- virtualProductCategoryMembers = EntityUtil.filterByDate(virtualProductCategoryMembers, nowTimestamp, null, null, true);
+ List<GenericValue> virtualProductCategoryMembers = EntityQuery.use(delegator).from("ProductCategoryMember").where("productId", virtualProductId, "productCategoryId", productCategoryId).cache(true).filterByDate(nowTimestamp).queryList();
if (UtilValidate.isNotEmpty(virtualProductCategoryMembers)) {
// we found a member record? great, then this condition is satisfied
compare = 0;
@@ -1081,10 +1080,8 @@ public class PriceServices {
// if a ProductFeatureAppl exists for this productId and the specified productFeatureId
String productFeatureId = productPriceCond.getString("condValue");
- List<GenericValue> productFeatureAppls = delegator.findByAnd("ProductFeatureAppl",
- UtilMisc.toMap("productId", productId, "productFeatureId", productFeatureId), null, true);
// and from/thru date within range
- productFeatureAppls = EntityUtil.filterByDate(productFeatureAppls, nowTimestamp, null, null, true);
+ List<GenericValue> productFeatureAppls = EntityQuery.use(delegator).from("ProductFeatureAppl").where("productId", productId, "productFeatureId", productFeatureId).cache(true).filterByDate(nowTimestamp).queryList();
// then 0 (equals), otherwise 1 (not equals)
if (UtilValidate.isNotEmpty(productFeatureAppls)) {
compare = 0;
@@ -1135,9 +1132,8 @@ public class PriceServices {
// look for PartyRelationship with
// partyRelationshipTypeId=GROUP_ROLLUP, the partyIdTo is
// the group member, so the partyIdFrom is the groupPartyId
- List<GenericValue> partyRelationshipList = delegator.findByAnd("PartyRelationship", UtilMisc.toMap("partyIdFrom", groupPartyId, "partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP"), null, true);
// and from/thru date within range
- partyRelationshipList = EntityUtil.filterByDate(partyRelationshipList, nowTimestamp, null, null, true);
+ List<GenericValue> partyRelationshipList = EntityQuery.use(delegator).from("PartyRelationship").where("partyIdFrom", groupPartyId, "partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP").cache(true).filterByDate(nowTimestamp).queryList();
// then 0 (equals), otherwise 1 (not equals)
if (UtilValidate.isNotEmpty(partyRelationshipList)) {
compare = 0;
@@ -1152,9 +1148,8 @@ public class PriceServices {
} else {
String partyClassificationGroupId = productPriceCond.getString("condValue");
// find any PartyClassification
- List<GenericValue> partyClassificationList = delegator.findByAnd("PartyClassification", UtilMisc.toMap("partyId", partyId, "partyClassificationGroupId", partyClassificationGroupId), null, true);
// and from/thru date within range
- partyClassificationList = EntityUtil.filterByDate(partyClassificationList, nowTimestamp, null, null, true);
+ List<GenericValue> partyClassificationList = EntityQuery.use(delegator).from("PartyClassification").where("partyId", partyId, "partyClassificationGroupId", partyClassificationGroupId).cache(true).filterByDate(nowTimestamp).queryList();
// then 0 (equals), otherwise 1 (not equals)
if (UtilValidate.isNotEmpty(partyClassificationList)) {
compare = 0;
@@ -1165,8 +1160,7 @@ public class PriceServices {
} else if ("PRIP_ROLE_TYPE".equals(productPriceCond.getString("inputParamEnumId"))) {
if (partyId != null) {
// if a PartyRole exists for this partyId and the specified roleTypeId
- GenericValue partyRole = delegator.findOne("PartyRole",
- UtilMisc.toMap("partyId", partyId, "roleTypeId", productPriceCond.getString("condValue")), true);
+ GenericValue partyRole = EntityQuery.use(delegator).from("PartyRole").where("partyId", partyId, "roleTypeId", productPriceCond.getString("condValue")).cache(true).queryOne();
// then 0 (equals), otherwise 1 (not equals)
if (partyRole != null) {
@@ -1210,8 +1204,7 @@ public class PriceServices {
}
private static int checkConditionPartyHierarchy(Delegator delegator, Timestamp nowTimestamp, String groupPartyId, String partyId) throws GenericEntityException{
- List<GenericValue> partyRelationshipList = delegator.findByAnd("PartyRelationship", UtilMisc.toMap("partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP"), null, true);
- partyRelationshipList = EntityUtil.filterByDate(partyRelationshipList, nowTimestamp, null, null, true);
+ List<GenericValue> partyRelationshipList = EntityQuery.use(delegator).from("PartyRelationship").where("partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP").cache(true).filterByDate(nowTimestamp).queryList();
for (GenericValue genericValue : partyRelationshipList) {
String partyIdFrom = (String)genericValue.get("partyIdFrom");
if (partyIdFrom.equals(groupPartyId)) {
@@ -1297,16 +1290,14 @@ public class PriceServices {
if (!validPriceFound) {
List<GenericValue> prices = null;
try {
- prices = delegator.findByAnd("ProductPrice", UtilMisc.toMap("productId", productId,
- "productPricePurposeId", "PURCHASE"), UtilMisc.toList("-fromDate"), false);
+ prices = EntityQuery.use(delegator).from("ProductPrice").where("productId", productId, "productPricePurposeId", "PURCHASE").orderBy("-fromDate").queryList();
// if no prices are found; find the prices of the parent product
if (UtilValidate.isEmpty(prices)) {
GenericValue parentProduct = ProductWorker.getParentProduct(productId, delegator);
if (parentProduct != null) {
String parentProductId = parentProduct.getString("productId");
- prices = delegator.findByAnd("ProductPrice", UtilMisc.toMap("productId", parentProductId,
- "productPricePurposeId", "PURCHASE"), UtilMisc.toList("-fromDate"), false);
+ prices = EntityQuery.use(delegator).from("ProductPrice").where("productId", parentProductId, "productPricePurposeId", "PURCHASE").orderBy("-fromDate").queryList();
}
}
} catch (GenericEntityException e) {
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/KeywordIndex.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/KeywordIndex.java?rev=1641044&r1=1641043&r2=1641044&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/KeywordIndex.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/KeywordIndex.java Sat Nov 22 11:26:20 2014
@@ -38,6 +38,7 @@ import org.ofbiz.content.data.DataResour
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityQuery;
import org.ofbiz.entity.util.EntityUtil;
/**
@@ -117,7 +118,7 @@ public class KeywordIndex {
!"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.ProductFeatureAndAppl.abbrev", "0")) ||
!"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.ProductFeatureAndAppl.idCode", "0"))) {
// get strings from attributes and features
- List<GenericValue> productFeatureAndAppls = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId), null, false);
+ List<GenericValue> productFeatureAndAppls = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId).queryList();
for (GenericValue productFeatureAndAppl: productFeatureAndAppls) {
addWeightedKeywordSourceString(productFeatureAndAppl, "description", strings);
addWeightedKeywordSourceString(productFeatureAndAppl, "abbrev", strings);
@@ -128,7 +129,7 @@ public class KeywordIndex {
// ProductAttribute
if (!"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.ProductAttribute.attrName", "0")) ||
!"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.ProductAttribute.attrValue", "0"))) {
- List<GenericValue> productAttributes = delegator.findByAnd("ProductAttribute", UtilMisc.toMap("productId", productId), null, false);
+ List<GenericValue> productAttributes = EntityQuery.use(delegator).from("ProductAttribute").where("productId", productId).queryList();
for (GenericValue productAttribute: productAttributes) {
addWeightedKeywordSourceString(productAttribute, "attrName", strings);
addWeightedKeywordSourceString(productAttribute, "attrValue", strings);
@@ -137,7 +138,7 @@ public class KeywordIndex {
// GoodIdentification
if (!"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.GoodIdentification.idValue", "0"))) {
- List<GenericValue> goodIdentifications = delegator.findByAnd("GoodIdentification", UtilMisc.toMap("productId", productId), null, false);
+ List<GenericValue> goodIdentifications = EntityQuery.use(delegator).from("GoodIdentification").where("productId", productId).queryList();
for (GenericValue goodIdentification: goodIdentifications) {
addWeightedKeywordSourceString(goodIdentification, "idValue", strings);
}
@@ -146,8 +147,7 @@ public class KeywordIndex {
// Variant Product IDs
if ("Y".equals(product.getString("isVirtual"))) {
if (!"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.Variant.Product.productId", "0"))) {
- List<GenericValue> variantProductAssocs = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT"), null, false);
- variantProductAssocs = EntityUtil.filterByDate(variantProductAssocs);
+ List<GenericValue> variantProductAssocs = EntityQuery.use(delegator).from("ProductAssoc").where("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT").filterByDate().queryList();
for (GenericValue variantProductAssoc: variantProductAssocs) {
int weight = 1;
try {
@@ -172,7 +172,7 @@ public class KeywordIndex {
Debug.logWarning("Could not parse weight number: " + e.toString(), module);
}
- List<GenericValue> productContentAndInfos = delegator.findByAnd("ProductContentAndInfo", UtilMisc.toMap("productId", productId, "productContentTypeId", productContentTypeId), null, false);
+ List<GenericValue> productContentAndInfos = EntityQuery.use(delegator).from("ProductContentAndInfo").where("productId", productId, "productContentTypeId", productContentTypeId).queryList();
for (GenericValue productContentAndInfo: productContentAndInfos) {
addWeightedDataResourceString(productContentAndInfo, weight, strings, delegator, product);
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java?rev=1641044&r1=1641043&r2=1641044&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java Sat Nov 22 11:26:20 2014
@@ -33,7 +33,6 @@ import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilHttp;
-import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.GeneralRuntimeException;
import org.ofbiz.base.util.cache.UtilCache;
@@ -178,13 +177,11 @@ public class ProductContentWrapper imple
}
}
- List<GenericValue> productContentList = delegator.findByAnd("ProductContent", UtilMisc.toMap("productId", productId, "productContentTypeId", productContentTypeId), UtilMisc.toList("-fromDate"), true);
- productContentList = EntityUtil.filterByDate(productContentList);
+ List<GenericValue> productContentList = EntityQuery.use(delegator).from("ProductContent").where("productId", productId, "productContentTypeId", productContentTypeId).orderBy("-fromDate").cache(true).filterByDate().queryList();
if (UtilValidate.isEmpty(productContentList) && ("Y".equals(product.getString("isVariant")))) {
GenericValue parent = ProductWorker.getParentProduct(productId, delegator);
if (UtilValidate.isNotEmpty(parent)) {
- productContentList = delegator.findByAnd("ProductContent", UtilMisc.toMap("productId", parent.get("productId"), "productContentTypeId", productContentTypeId), UtilMisc.toList("-fromDate"), true);
- productContentList = EntityUtil.filterByDate(productContentList);
+ productContentList = EntityQuery.use(delegator).from("ProductContent").where("productId", parent.get("productId"), "productContentTypeId", productContentTypeId).orderBy("-fromDate").cache(true).filterByDate().queryList();
}
}
GenericValue productContent = EntityUtil.getFirst(productContentList);
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java?rev=1641044&r1=1641043&r2=1641044&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java Sat Nov 22 11:26:20 2014
@@ -120,10 +120,10 @@ public class ProductEvents {
beganTx = TransactionUtil.begin(7200);
try {
if (Debug.infoOn()) {
- long count = delegator.findCountByCondition("Product", condition, null, null);
+ long count = EntityQuery.use(delegator).from("Product").where(condition).queryCount();
Debug.logInfo("========== Found " + count + " products to index ==========", module);
}
- entityListIterator = delegator.find("Product", condition, null, null, null, null);
+ entityListIterator = EntityQuery.use(delegator).from("Product").where(condition).queryIterator();
} catch (GenericEntityException gee) {
Debug.logWarning(gee, gee.getMessage(), module);
Map<String, String> messageMap = UtilMisc.toMap("gee", gee.toString());
@@ -281,7 +281,7 @@ public class ProductEvents {
GenericValue productAssoc = null;
try {
- productAssoc = delegator.findOne(tempProductAssoc.getEntityName(), tempProductAssoc.getPrimaryKey(), false);
+ productAssoc = EntityQuery.use(delegator).from(tempProductAssoc.getEntityName()).where(tempProductAssoc.getPrimaryKey()).queryOne();
} catch (GenericEntityException e) {
Debug.logWarning(e.getMessage(), module);
productAssoc = null;
@@ -354,7 +354,7 @@ public class ProductEvents {
GenericValue productAssoc = null;
try {
- productAssoc = delegator.findOne(tempProductAssoc.getEntityName(), tempProductAssoc.getPrimaryKey(), false);
+ productAssoc = EntityQuery.use(delegator).from(tempProductAssoc.getEntityName()).where(tempProductAssoc.getPrimaryKey()).queryOne();
} catch (GenericEntityException e) {
Debug.logWarning(e.getMessage(), module);
productAssoc = null;
@@ -454,7 +454,7 @@ public class ProductEvents {
BigDecimal ntwt = parseBigDecimalForEntity(request.getParameter("~ntwt"));
BigDecimal grams = parseBigDecimalForEntity(request.getParameter("~grams"));
- List<GenericValue> currentProductFeatureAndAppls = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE"), null, false), true);
+ List<GenericValue> currentProductFeatureAndAppls = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE").filterByDate().queryList();
setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ozUS", "AMOUNT", floz);
setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ml", "AMOUNT", ml);
setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "WT_g", "AMOUNT", grams);
@@ -484,7 +484,7 @@ public class ProductEvents {
BigDecimal ntwt = parseBigDecimalForEntity(request.getParameter("~ntwt" + attribIdx));
BigDecimal grams = parseBigDecimalForEntity(request.getParameter("~grams" + attribIdx));
- List<GenericValue> currentProductFeatureAndAppls = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE"), null, false), true);
+ List<GenericValue> currentProductFeatureAndAppls = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE").filterByDate().queryList();
setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ozUS", "AMOUNT", floz);
setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ml", "AMOUNT", ml);
setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "WT_g", "AMOUNT", grams);
@@ -557,7 +557,7 @@ public class ProductEvents {
// NOTE: if numberSpecified is null then foundOneEqual will always be false, so need to check both
if (numberSpecified != null && !foundOneEqual) {
String productFeatureId = null;
- List<GenericValue> existingProductFeatureList = delegator.findByAnd("ProductFeature", UtilMisc.toMap("productFeatureTypeId", productFeatureTypeId, "numberSpecified", numberSpecified, "uomId", uomId), null, false);
+ List<GenericValue> existingProductFeatureList = EntityQuery.use(delegator).from("ProductFeature").where("productFeatureTypeId", productFeatureTypeId, "numberSpecified", numberSpecified, "uomId", uomId).queryList();
if (existingProductFeatureList.size() > 0) {
GenericValue existingProductFeature = existingProductFeatureList.get(0);
productFeatureId = existingProductFeature.getString("productFeatureId");
@@ -670,8 +670,7 @@ public class ProductEvents {
GenericValue productFeatureAndAppl = null;
Set<String> descriptionsForThisType = FastSet.newInstance();
- List<GenericValue> productFeatureAndApplList = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId,
- "productFeatureApplTypeId", productFeatureApplTypeId, "productFeatureTypeId", productFeatureTypeId), null, false), true);
+ List<GenericValue> productFeatureAndApplList = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId, "productFeatureTypeId", productFeatureTypeId).filterByDate().queryList();
if (productFeatureAndApplList.size() > 0) {
Iterator<GenericValue> productFeatureAndApplIter = productFeatureAndApplList.iterator();
while (productFeatureAndApplIter.hasNext()) {
@@ -723,7 +722,7 @@ public class ProductEvents {
// see if a feature exists with the type and description specified (if doesn't exist will create later)
String productFeatureId = null;
- List<GenericValue> existingProductFeatureList = delegator.findByAnd("ProductFeature", UtilMisc.toMap("productFeatureTypeId", productFeatureTypeId, "description", description), null, false);
+ List<GenericValue> existingProductFeatureList = EntityQuery.use(delegator).from("ProductFeature").where("productFeatureTypeId", productFeatureTypeId, "description", description).queryList();
if (existingProductFeatureList.size() > 0) {
GenericValue existingProductFeature = existingProductFeatureList.get(0);
productFeatureId = existingProductFeature.getString("productFeatureId");
@@ -748,8 +747,7 @@ public class ProductEvents {
}
// check to see if the productFeatureId is already attached to the virtual or variant, if not attach them...
- List<GenericValue> specificProductFeatureApplList = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", productId,
- "productFeatureApplTypeId", productFeatureApplTypeId, "productFeatureId", productFeatureId), null, false), true);
+ List<GenericValue> specificProductFeatureApplList = EntityQuery.use(delegator).from("ProductFeatureAppl").where("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId, "productFeatureId", productFeatureId).filterByDate().queryList();
if (specificProductFeatureApplList.size() == 0) {
delegator.create("ProductFeatureAppl",
@@ -831,10 +829,7 @@ public class ProductEvents {
if (categoryIds != null) {
for (String categoryId: categoryIds) {
try {
- List<GenericValue> catMembs = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap(
- "productCategoryId", categoryId,
- "productId", productId), null, false);
- catMembs = EntityUtil.filterByDate(catMembs);
+ List<GenericValue> catMembs = EntityQuery.use(delegator).from("ProductCategoryMember").where("productCategoryId", categoryId, "productId", productId).filterByDate().queryList();
if (catMembs.size() == 0) {
delegator.create("ProductCategoryMember",
UtilMisc.toMap("productCategoryId", categoryId, "productId", productId, "fromDate", fromDate));
@@ -859,9 +854,7 @@ public class ProductEvents {
thruDate = UtilDateTime.nowTimestamp().toString();
}
try {
- List<GenericValue> prodCatMembs = delegator.findByAnd("ProductCategoryMember",
- UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId), null, false);
- prodCatMembs = EntityUtil.filterByDate(prodCatMembs);
+ List<GenericValue> prodCatMembs = EntityQuery.use(delegator).from("ProductCategoryMember").where("productCategoryId", productCategoryId, "productId", productId).filterByDate().queryList();
if (prodCatMembs.size() > 0) {
// there is one to modify
GenericValue prodCatMemb = prodCatMembs.get(0);
@@ -890,10 +883,7 @@ public class ProductEvents {
try {
for (String productFeatureId: productFeatureIdArray) {
if (!productFeatureId.equals("~~any~~")) {
- List<GenericValue> featureAppls = delegator.findByAnd("ProductFeatureAppl",
- UtilMisc.toMap("productId", productId,
- "productFeatureId", productFeatureId,
- "productFeatureApplTypeId", productFeatureApplTypeId), null, false);
+ List<GenericValue> featureAppls = EntityQuery.use(delegator).from("ProductFeatureAppl").where("productId", productId, "productFeatureId", productFeatureId, "productFeatureApplTypeId", productFeatureApplTypeId).queryList();
if (featureAppls.size() == 0) {
// no existing application for this
delegator.create("ProductFeatureAppl",
@@ -963,9 +953,7 @@ public class ProductEvents {
if ("Y".equals(productStore.getString("requireCustomerRole"))) {
List<GenericValue> productStoreRoleList = null;
try {
- productStoreRoleList = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("productStoreId", productStore.get("productStoreId"),
- "partyId", userLogin.get("partyId"), "roleTypeId", "CUSTOMER"), null, false);
- productStoreRoleList = EntityUtil.filterByDate(productStoreRoleList, true);
+ productStoreRoleList = EntityQuery.use(delegator).from("ProductStoreRole").where("productStoreId", productStore.get("productStoreId"), "partyId", userLogin.get("partyId"), "roleTypeId", "CUSTOMER").filterByDate().queryList();
} catch (GenericEntityException e) {
Debug.logError(e, "Database error finding CUSTOMER ProductStoreRole records, required by the ProductStore with ID [" + productStore.getString("productStoreId") + "]", module);
}
@@ -1000,8 +988,7 @@ public class ProductEvents {
GenericValue productStoreEmail = null;
try {
- productStoreEmail = delegator.findOne("ProductStoreEmailSetting",
- UtilMisc.toMap("productStoreId", productStoreId, "emailType", emailType), false);
+ productStoreEmail = EntityQuery.use(delegator).from("ProductStoreEmailSetting").where("productStoreId", productStoreId, "emailType", emailType).queryOne();
} catch (GenericEntityException e) {
String errMsg = "Unable to get product store email setting for tell-a-friend: " + e.toString();
Debug.logError(e, errMsg, module);
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductPromoContentWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductPromoContentWrapper.java?rev=1641044&r1=1641043&r2=1641044&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductPromoContentWrapper.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductPromoContentWrapper.java Sat Nov 22 11:26:20 2014
@@ -172,9 +172,8 @@ public class ProductPromoContentWrapper
List<EntityExpr> exprs = new ArrayList<EntityExpr>();
exprs.add(EntityCondition.makeCondition("productPromoId", EntityOperator.EQUALS, productPromoId));
exprs.add(EntityCondition.makeCondition("productPromoContentTypeId", EntityOperator.EQUALS, productPromoContentTypeId));
- List<String> orderBy = UtilMisc.toList("-fromDate");
- List<GenericValue> productPromoContentList = delegator.findList("ProductPromoContent", EntityCondition.makeCondition(exprs, EntityOperator.AND), null, orderBy, null, true);
+ List<GenericValue> productPromoContentList = EntityQuery.use(delegator).from("ProductPromoContent").where(EntityCondition.makeCondition(exprs, EntityOperator.AND)).orderBy("-fromDate").cache(true).queryList();
GenericValue productPromoContent = null;
if (UtilValidate.isNotEmpty(productPromoContentList)) {
productPromoContent = EntityUtil.getFirst(EntityUtil.filterByDate(productPromoContentList));
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java?rev=1641044&r1=1641043&r2=1641044&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java Sat Nov 22 11:26:20 2014
@@ -122,7 +122,7 @@ public class ProductSearch {
// now find all sub-categories, filtered by effective dates, and call this routine for them
try {
- List<GenericValue> productCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId", productCategoryId), null, true);
+ List<GenericValue> productCategoryRollupList = EntityQuery.use(delegator).from("ProductCategoryRollup").where("parentProductCategoryId", productCategoryId).cache(true).queryList();
for (GenericValue productCategoryRollup: productCategoryRollupList) {
String subProductCategoryId = productCategoryRollup.getString("productCategoryId");
if (productCategoryIdSet.contains(subProductCategoryId)) {
@@ -662,21 +662,23 @@ public class ProductSearch {
}
dynamicViewEntity.addAlias("PROD", "mainProductId", "productId", null, null, Boolean.valueOf(productIdGroupBy), null);
- EntityCondition whereCondition = EntityCondition.makeCondition(entityConditionList, EntityOperator.AND);
- EntityFindOptions efo = new EntityFindOptions();
- efo.setDistinct(true);
- efo.setResultSetType(EntityFindOptions.TYPE_SCROLL_INSENSITIVE);
- if (maxResults != null) {
- int queryMaxResults = maxResults;
- if (resultOffset != null) {
- queryMaxResults += resultOffset - 1;
- }
- efo.setMaxRows(queryMaxResults);
- }
EntityListIterator eli = null;
try {
- eli = delegator.findListIteratorByCondition(dynamicViewEntity, whereCondition, null, fieldsToSelect, orderByList, efo);
+ int queryMaxResults = 0;
+ if (maxResults != null) {
+ queryMaxResults = maxResults;
+ if (resultOffset != null) {
+ queryMaxResults += resultOffset - 1;
+ }
+ }
+ eli = EntityQuery.use(delegator).select(UtilMisc.toSet(fieldsToSelect))
+ .from(dynamicViewEntity).where(entityConditionList)
+ .orderBy(orderByList)
+ .distinct(true)
+ .maxRows(queryMaxResults)
+ .cursorScrollInsensitive()
+ .queryIterator();
} catch (GenericEntityException e) {
Debug.logError(e, "Error in product search", module);
return null;
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java?rev=1641044&r1=1641043&r2=1641044&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java Sat Nov 22 11:26:20 2014
@@ -43,6 +43,7 @@ import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.transaction.GenericTransactionException;
import org.ofbiz.entity.transaction.TransactionUtil;
import org.ofbiz.entity.util.EntityListIterator;
+import org.ofbiz.entity.util.EntityQuery;
import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.product.product.ProductSearch.ProductSearchContext;
import org.ofbiz.product.product.ProductSearch.ResultSortOrder;
@@ -143,7 +144,7 @@ public class ProductSearchEvents {
while ((searchResultView = eli.next()) != null) {
String productId = searchResultView.getString("mainProductId");
//get all tuples that match product and category
- List<GenericValue> pcmList = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId), null, false);
+ List<GenericValue> pcmList = EntityQuery.use(delegator).from("ProductCategoryMember").where("productCategoryId", productCategoryId, "productId", productId).queryList();
//set those thrudate to that specificed maybe remove then add new one
for (GenericValue pcm: pcmList) {
@@ -413,15 +414,11 @@ public class ProductSearchEvents {
String productId = searchResultView.getString("mainProductId");
productMap.put("productId", productId);
- List<GenericValue> productFeaturesCustomRaw = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureTypeId", "HAZMAT"), null, false);
- List<GenericValue> productFeaturesCustom = EntityUtil.filterByDate(productFeaturesCustomRaw);
- productMap.put("productFeatureCustom", EntityUtil.getFirst(productFeaturesCustom));
+ productMap.put("productFeatureCustom", EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureTypeId", "HAZMAT").filterByDate().queryFirst());
- List<GenericValue> productCategoriesRaw = delegator.findByAnd("ProductCategoryAndMember", UtilMisc.toMap("productId", productId), null, false);
- List<GenericValue> productCategories = EntityUtil.filterByDate(productCategoriesRaw);
+ List<GenericValue> productCategories = EntityQuery.use(delegator).from("ProductCategoryAndMember").where("productId", productId).filterByDate().queryList();
productMap.put("productCategories", productCategories);
- List<GenericValue> productFeaturesRaw = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId), null, false);
- List<GenericValue> productFeatures = EntityUtil.filterByDate(productFeaturesRaw);
+ List<GenericValue> productFeatures = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId).filterByDate().queryList();
productMap.put("productFeatures", productFeatures);
productExportList.add(productMap);
}
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java?rev=1641044&r1=1641043&r2=1641044&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java Sat Nov 22 11:26:20 2014
@@ -53,6 +53,7 @@ import org.ofbiz.entity.model.DynamicVie
import org.ofbiz.entity.model.ModelKeyMap;
import org.ofbiz.entity.util.EntityFindOptions;
import org.ofbiz.entity.util.EntityListIterator;
+import org.ofbiz.entity.util.EntityQuery;
import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.product.catalog.CatalogWorker;
import org.ofbiz.product.category.CategoryWorker;
@@ -400,8 +401,7 @@ public class ProductSearchSession {
if (keywords.size() > 0) {
List<GenericValue> productStoreKeywordOvrdList = null;
try {
- productStoreKeywordOvrdList = delegator.findByAnd("ProductStoreKeywordOvrd", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("-fromDate"), true);
- productStoreKeywordOvrdList = EntityUtil.filterByDate(productStoreKeywordOvrdList, true);
+ productStoreKeywordOvrdList = EntityQuery.use(delegator).from("ProductStoreKeywordOvrd").where("productStoreId", productStoreId).orderBy("-fromDate").cache(true).filterByDate().queryList();
} catch (GenericEntityException e) {
Debug.logError(e, "Error reading ProductStoreKeywordOvrd list, not doing keyword override", module);
}
@@ -930,11 +930,16 @@ public class ProductSearchSession {
addOnTopProdCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, now)));
addOnTopProdCondList.add(EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN, now));
addOnTopProdCondList.add(EntityCondition.makeCondition("productCategoryId", EntityOperator.EQUALS, addOnTopProdCategoryId));
- EntityFindOptions findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true);
- findOpts.setMaxRows(highIndex);
EntityListIterator pli = null;
try {
- pli = delegator.find("ProductCategoryMember", EntityCondition.makeCondition(addOnTopProdCondList, EntityOperator.AND), null, UtilMisc.toSet("productId", "sequenceNum"), UtilMisc.toList("sequenceNum"), findOpts);
+ pli = EntityQuery.use(delegator).select(UtilMisc.toSet("productId", "sequenceNum"))
+ .from("ProductCategoryMember")
+ .where(addOnTopProdCondList)
+ .orderBy("sequenceNum")
+ .cursorScrollInsensitive()
+ .distinct()
+ .maxRows(highIndex)
+ .queryIterator();
addOnTopProductCategoryMembers = pli.getPartialList(lowIndex, viewSize);
addOnTopListSize = addOnTopProductCategoryMembers.size();
for (GenericValue alwaysAddProductCategoryMember: addOnTopProductCategoryMembers) {
@@ -1219,7 +1224,6 @@ public class ProductSearchSession {
DynamicViewEntity dynamicViewEntity = productSearchContext.dynamicViewEntity;
List<EntityCondition> entityConditionList = productSearchContext.entityConditionList;
- List<String> fieldsToSelect = FastList.newInstance();
dynamicViewEntity.addMemberEntity("PFAC", "ProductFeatureAppl");
dynamicViewEntity.addAlias("PFAC", "pfacProductFeatureId", "productFeatureId", null, null, Boolean.TRUE, null);
@@ -1227,8 +1231,6 @@ public class ProductSearchSession {
dynamicViewEntity.addAlias("PFAC", "pfacThruDate", "thruDate", null, null, null, null);
dynamicViewEntity.addAlias("PFAC", "featureCount", "productId", null, null, null, "count-distinct");
dynamicViewEntity.addViewLink("PROD", "PFAC", Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId"));
- fieldsToSelect.add("pfacProductFeatureId");
- fieldsToSelect.add("featureCount");
entityConditionList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("pfacThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("pfacThruDate", EntityOperator.GREATER_THAN, UtilDateTime.nowTimestamp())));
entityConditionList.add(EntityCondition.makeCondition("pfacFromDate", EntityOperator.LESS_THAN, UtilDateTime.nowTimestamp()));
@@ -1236,18 +1238,17 @@ public class ProductSearchSession {
dynamicViewEntity.addAlias("PFC", "pfcProductFeatureTypeId", "productFeatureTypeId", null, null, Boolean.TRUE, null);
dynamicViewEntity.addAlias("PFC", "pfcDescription", "description", null, null, Boolean.TRUE, null);
dynamicViewEntity.addViewLink("PFAC", "PFC", Boolean.FALSE, ModelKeyMap.makeKeyMapList("productFeatureId"));
- fieldsToSelect.add("pfcDescription");
- fieldsToSelect.add("pfcProductFeatureTypeId");
entityConditionList.add(EntityCondition.makeCondition("pfcProductFeatureTypeId", EntityOperator.EQUALS, productFeatureTypeId));
- EntityCondition whereCondition = EntityCondition.makeCondition(entityConditionList, EntityOperator.AND);
-
- EntityFindOptions efo = new EntityFindOptions();
- efo.setResultSetType(EntityFindOptions.TYPE_SCROLL_INSENSITIVE);
-
EntityListIterator eli = null;
try {
- eli = delegator.findListIteratorByCondition(dynamicViewEntity, whereCondition, null, fieldsToSelect, productSearchContext.orderByList, efo);
+ eli = EntityQuery.use(delegator)
+ .select(UtilMisc.toSet("pfacProductFeatureId", "featureCount", "pfcDescription", "pfcProductFeatureTypeId"))
+ .from(dynamicViewEntity)
+ .where(entityConditionList)
+ .orderBy(productSearchContext.orderByList)
+ .cursorScrollInsensitive()
+ .queryIterator();
} catch (GenericEntityException e) {
Debug.logError(e, "Error in product search", module);
return null;
@@ -1318,14 +1319,14 @@ public class ProductSearchSession {
entityConditionList.add(EntityCondition.makeCondition("ppcPrice", EntityOperator.LESS_THAN_EQUAL_TO, priceHigh));
entityConditionList.add(EntityCondition.makeCondition("ppcProductPriceTypeId", EntityOperator.EQUALS, "LIST_PRICE"));
- EntityCondition whereCondition = EntityCondition.makeCondition(entityConditionList, EntityOperator.AND);
-
- EntityFindOptions efo = new EntityFindOptions();
- efo.setResultSetType(EntityFindOptions.TYPE_SCROLL_INSENSITIVE);
-
EntityListIterator eli = null;
try {
- eli = delegator.findListIteratorByCondition(dynamicViewEntity, whereCondition, null, fieldsToSelect, productSearchContext.orderByList, efo);
+ eli = EntityQuery.use(delegator).select(UtilMisc.toSet(fieldsToSelect))
+ .from(dynamicViewEntity)
+ .where(entityConditionList)
+ .orderBy(productSearchContext.orderByList)
+ .cursorScrollInsensitive()
+ .queryIterator();
} catch (GenericEntityException e) {
Debug.logError(e, "Error in product search", module);
return 0;
@@ -1384,14 +1385,14 @@ public class ProductSearchSession {
ProductSearch.getAllSubCategoryIds(productCategoryId, productCategoryIdSet, delegator, productSearchContext.nowTimestamp);
entityConditionList.add(EntityCondition.makeCondition("pcmcProductCategoryId", EntityOperator.IN, productCategoryIdSet));
- EntityCondition whereCondition = EntityCondition.makeCondition(entityConditionList, EntityOperator.AND);
-
- EntityFindOptions efo = new EntityFindOptions();
- efo.setResultSetType(EntityFindOptions.TYPE_SCROLL_INSENSITIVE);
-
EntityListIterator eli = null;
try {
- eli = delegator.findListIteratorByCondition(dynamicViewEntity, whereCondition, null, fieldsToSelect, productSearchContext.orderByList, efo);
+ eli = EntityQuery.use(delegator).select(UtilMisc.toSet(fieldsToSelect))
+ .from(dynamicViewEntity)
+ .where(entityConditionList)
+ .orderBy(productSearchContext.orderByList)
+ .cursorScrollInsensitive()
+ .queryIterator();
} catch (GenericEntityException e) {
Debug.logError(e, "Error in product search", module);
return 0;
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java?rev=1641044&r1=1641043&r2=1641044&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java Sat Nov 22 11:26:20 2014
@@ -165,9 +165,7 @@ public class ProductServices {
Set<String> featureSet = new LinkedHashSet<String>();
try {
- Map<String, String> fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId);
- List<String> order = UtilMisc.toList("sequenceNum", "productFeatureTypeId");
- List<GenericValue> features = delegator.findByAnd("ProductFeatureAndAppl", fields, order, true);
+ List<GenericValue> features = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId).orderBy("sequenceNum", "productFeatureTypeId").cache(true).queryList();
for (GenericValue v: features) {
featureSet.add(v.getString("productFeatureTypeId"));
}
@@ -297,11 +295,7 @@ public class ProductServices {
// Make the selectable feature list
List<GenericValue> selectableFeatures = null;
try {
- Map<String, String> fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE");
- List<String> sort = UtilMisc.toList("sequenceNum");
-
- selectableFeatures = delegator.findByAnd("ProductFeatureAndAppl", fields, sort, true);
- selectableFeatures = EntityUtil.filterByDate(selectableFeatures, true);
+ selectableFeatures = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE").orderBy("sequenceNum").cache(true).filterByDate().queryList();
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
@@ -374,11 +368,10 @@ public class ProductServices {
try {
Map<String, String> fields = UtilMisc.toMap("productId", productId);
- List<String> order = UtilMisc.toList("sequenceNum", "productFeatureTypeId");
if (distinct != null) fields.put("productFeatureTypeId", distinct);
if (type != null) fields.put("productFeatureApplTypeId", type);
- features = delegator.findByAnd("ProductFeatureAndAppl", fields, order, true);
+ features = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where(fields).orderBy("sequenceNum", "productFeatureTypeId").cache(true).queryList();
result.put("productFeatures", features);
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
} catch (GenericEntityException e) {
@@ -517,8 +510,7 @@ public class ProductServices {
EntityCondition.makeCondition("productId", productId),
EntityCondition.makeCondition("productIdTo", productId)
), EntityJoinOperator.OR);
- cond = EntityCondition.makeCondition(cond, EntityCondition.makeCondition("productAssocTypeId", type));
- productAssocs = delegator.findList("ProductAssoc", cond, null, orderBy, null, true);
+ productAssocs = EntityQuery.use(delegator).from("ProductAssoc").where(EntityCondition.makeCondition(cond, EntityCondition.makeCondition("productAssocTypeId", type))).orderBy(orderBy).cache(true).queryList();
} else {
if (productIdTo == null) {
productAssocs = product.getRelated("MainProductAssoc", UtilMisc.toMap("productAssocTypeId", type), orderBy, true);
@@ -584,13 +576,13 @@ public class ProductServices {
List<GenericValue> features = null;
try {
- Map<String, String> fields = UtilMisc.toMap("productId", thisItem, "productFeatureTypeId", orderKey,
- "productFeatureApplTypeId", "STANDARD_FEATURE");
- List<String> sort = UtilMisc.toList("sequenceNum");
-
// get the features and filter out expired dates
- features = delegator.findByAnd("ProductFeatureAndAppl", fields, sort, true);
- features = EntityUtil.filterByDate(features, true);
+ features = EntityQuery.use(delegator).from("ProductFeatureAndAppl")
+ .where("productId", thisItem, "productFeatureTypeId", orderKey, "productFeatureApplTypeId", "STANDARD_FEATURE")
+ .orderBy("sequenceNum")
+ .cache(true)
+ .filterByDate()
+ .queryList();
} catch (GenericEntityException e) {
throw new IllegalStateException("Problem reading relation: " + e.getMessage());
}
@@ -661,20 +653,19 @@ public class ProductServices {
List<GenericValue> features = null;
try {
- Map<String, String> fields = UtilMisc.toMap("productId", productId, "productFeatureTypeId", feature,
- "productFeatureApplTypeId", "STANDARD_FEATURE");
- List<String> sort = UtilMisc.toList("sequenceNum", "description");
-
// get the features and filter out expired dates
- features = delegator.findByAnd("ProductFeatureAndAppl", fields, sort, true);
- features = EntityUtil.filterByDate(features, true);
+ features = EntityQuery.use(delegator).from("ProductFeatureAndAppl")
+ .where("productId", productId, "productFeatureTypeId", feature, "productFeatureApplTypeId", "STANDARD_FEATURE")
+ .orderBy("sequenceNum", "description")
+ .cache(true)
+ .filterByDate()
+ .queryList();
} catch (GenericEntityException e) {
throw new IllegalStateException("Problem reading relation: " + e.getMessage());
}
for (GenericValue featureAppl: features) {
try {
- GenericValue product = delegator.findOne("Product",
- UtilMisc.toMap("productId", productId), true);
+ GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).cache(true).queryOne();
tempSample.put(featureAppl.getString("description"), product);
} catch (GenericEntityException e) {
@@ -715,7 +706,7 @@ public class ProductServices {
return result;
}
// check if product exists
- GenericValue variantProduct = delegator.findOne("Product",UtilMisc.toMap("productId", variantProductId), false);
+ GenericValue variantProduct = EntityQuery.use(delegator).from("Product").where("productId", variantProductId).queryOne();
boolean variantProductExists = (variantProduct != null);
if (variantProduct == null) {
//if product does not exist
@@ -847,7 +838,7 @@ public class ProductServices {
variantProductsById.put(variantProductId, variantProduct);
} else {
// is a GoodIdentification.idValue?
- List<GenericValue> goodIdentificationList = delegator.findByAnd("GoodIdentification", UtilMisc.toMap("idValue", variantProductId), null, false);
+ List<GenericValue> goodIdentificationList = EntityQuery.use(delegator).from("GoodIdentification").where("idValue", variantProductId).queryList();
if (UtilValidate.isEmpty(goodIdentificationList)) {
// whoops, nothing found... return error
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
@@ -950,7 +941,7 @@ public class ProductServices {
// refresh the product so we can update it
GenericValue productToUpdate = null;
try {
- productToUpdate = delegator.findOne("Product", product.getPrimaryKey(), false);
+ productToUpdate = EntityQuery.use(delegator).from("Product").where(product.getPrimaryKey()).queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -1006,7 +997,7 @@ public class ProductServices {
List<GenericValue> fileExtension = FastList.newInstance();
try {
- fileExtension = delegator.findByAnd("FileExtension", UtilMisc.toMap("mimeTypeId", (String) context.get("_uploadedFile_contentType")), null, false);
+ fileExtension = EntityQuery.use(delegator).from("FileExtension").where("mimeTypeId", (String) context.get("_uploadedFile_contentType")).queryList();
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -1294,7 +1285,7 @@ public class ProductServices {
List<GenericValue> fileExtension = FastList.newInstance();
try {
- fileExtension = delegator.findList("FileExtension", EntityCondition.makeCondition("mimeTypeId", EntityOperator.EQUALS, (String) context.get("_uploadedFile_contentType")), null, null, null, false);
+ fileExtension = EntityQuery.use(delegator).from("FileExtension").where("mimeTypeId", EntityOperator.EQUALS, (String) context.get("_uploadedFile_contentType")).queryList();
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());