Author: lektran
Date: Thu Oct 30 04:16:45 2014
New Revision: 1635382

URL: http://svn.apache.org/r1635382
Log:
Partially convert ordermgr component's java files to EntityQuery

Modified:
    ofbiz/trunk/applications/order/src/org/ofbiz/order/OrderManagerEvents.java
    
ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java
    
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java
    
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderContentWrapper.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderEvents.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderListState.java
    
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java
    
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/OrderManagerEvents.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/OrderManagerEvents.java?rev=1635382&r1=1635381&r2=1635382&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/OrderManagerEvents.java 
(original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/OrderManagerEvents.java 
Thu Oct 30 04:16:45 2014
@@ -44,6 +44,7 @@ import org.ofbiz.entity.condition.Entity
 import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.util.EntityQuery;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.order.order.OrderChangeHelper;
 import org.ofbiz.service.GenericServiceException;
@@ -137,7 +138,7 @@ public class OrderManagerEvents {
         GenericValue orderHeader = null;
         List<GenericValue> orderRoles = null;
         try {
-            orderHeader = delegator.findOne("OrderHeader", 
UtilMisc.toMap("orderId", orderId), false);
+            orderHeader = 
EntityQuery.use(delegator).from("OrderHeader").where("orderId", 
orderId).queryOne();
             orderRoles = delegator.findList("OrderRole", 
EntityCondition.makeCondition("orderId", EntityOperator.EQUALS, orderId), null, 
null, null, false);
         } catch (GenericEntityException e) {
             Debug.logError(e, "Problems reading order header from 
datasource.", module);

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java?rev=1635382&r1=1635381&r2=1635382&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java
 (original)
+++ 
ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java
 Thu Oct 30 04:16:45 2014
@@ -33,10 +33,8 @@ import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.condition.EntityCondition;
-import org.ofbiz.entity.condition.EntityConditionList;
-import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.entity.util.EntityQuery;
 
 /**
  * A package of methods for improving efficiency of financial accounts services
@@ -113,8 +111,9 @@ public class FinAccountHelper {
                  newAccountCode.append(char_pool[r.nextInt(char_pool.length)]);
              }
 
-             List<GenericValue> existingAccountsWithCode = 
delegator.findByAnd("FinAccount", UtilMisc.toMap("finAccountCode", 
newAccountCode.toString()), null, false);
-             if (existingAccountsWithCode.size() == 0) {
+             GenericValue existingAccountWithCode = 
EntityQuery.use(delegator).from("FinAccount")
+                     .where("finAccountCode", 
newAccountCode.toString()).queryFirst();
+             if (existingAccountWithCode == null) {
                  foundUniqueNewCode = true;
              }
 
@@ -141,9 +140,9 @@ public class FinAccountHelper {
          finAccountCode = finAccountCode.toUpperCase().replaceAll("[^0-9A-Z]", 
"");
 
          // now look for the account
-         List<GenericValue> accounts = delegator.findByAnd("FinAccount", 
UtilMisc.toMap("finAccountCode", finAccountCode), null, false);
-         accounts = EntityUtil.filterByDate(accounts);
-
+         List<GenericValue> accounts = 
EntityQuery.use(delegator).from("FinAccount")
+                 .where("finAccountCode", finAccountCode)
+                 .filterByDate().queryList();
          if (UtilValidate.isEmpty(accounts)) {
              // OK to display - not a code anyway
              Debug.logWarning("No fin account found for account code ["  + 
finAccountCode + "]", module);
@@ -173,24 +172,26 @@ public class FinAccountHelper {
         BigDecimal decrementTotal = ZERO;  // decrease balance
 
         // find the sum of all transactions which increase the value
-        EntityConditionList<EntityCondition> incrementConditions = 
EntityCondition.makeCondition(UtilMisc.toList(
-                EntityCondition.makeCondition("finAccountId", 
EntityOperator.EQUALS, finAccountId),
-                EntityCondition.makeCondition("transactionDate", 
EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime),
-                EntityCondition.makeCondition(UtilMisc.toList(
-                        EntityCondition.makeCondition("finAccountTransTypeId", 
EntityOperator.EQUALS, "DEPOSIT"),
-                        EntityCondition.makeCondition("finAccountTransTypeId", 
EntityOperator.EQUALS, "ADJUSTMENT")),
-                    EntityOperator.OR)),
-                EntityOperator.AND);
-        List<GenericValue> transSums = 
delegator.findList("FinAccountTransSum", incrementConditions, 
UtilMisc.toSet("amount"), null, null, false);
+        List<GenericValue> transSums = EntityQuery.use(delegator)
+                .select("amount")
+                .from("FinAccountTransSum")
+                .where(EntityCondition.makeCondition("finAccountId", 
EntityOperator.EQUALS, finAccountId),
+                        EntityCondition.makeCondition("transactionDate", 
EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime),
+                        EntityCondition.makeCondition(UtilMisc.toList(
+                                
EntityCondition.makeCondition("finAccountTransTypeId", EntityOperator.EQUALS, 
"DEPOSIT"),
+                                
EntityCondition.makeCondition("finAccountTransTypeId", EntityOperator.EQUALS, 
"ADJUSTMENT")),
+                            EntityOperator.OR))
+                .queryList();
         incrementTotal = addFirstEntryAmount(incrementTotal, transSums, 
"amount", (decimals+1), rounding);
 
         // now find sum of all transactions with decrease the value
-        EntityConditionList<EntityExpr> decrementConditions = 
EntityCondition.makeCondition(UtilMisc.toList(
-                EntityCondition.makeCondition("finAccountId", 
EntityOperator.EQUALS, finAccountId),
-                EntityCondition.makeCondition("transactionDate", 
EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime),
-                EntityCondition.makeCondition("finAccountTransTypeId", 
EntityOperator.EQUALS, "WITHDRAWAL")),
-            EntityOperator.AND);
-        transSums = delegator.findList("FinAccountTransSum", 
decrementConditions, UtilMisc.toSet("amount"), null, null, false);
+        transSums = EntityQuery.use(delegator)
+                .select("amount")
+                .from("FinAccountTransSum")
+                .where(EntityCondition.makeCondition("finAccountId", 
EntityOperator.EQUALS, finAccountId),
+                        EntityCondition.makeCondition("transactionDate", 
EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime),
+                        EntityCondition.makeCondition("finAccountTransTypeId", 
EntityOperator.EQUALS, "WITHDRAWAL"))
+                .queryList();
         decrementTotal = addFirstEntryAmount(decrementTotal, transSums, 
"amount", (decimals+1), rounding);
 
         // the net balance is just the incrementTotal minus the decrementTotal
@@ -211,13 +212,12 @@ public class FinAccountHelper {
         BigDecimal netBalance = getBalance(finAccountId, asOfDateTime, 
delegator);
 
         // find sum of all authorizations which are not expired and which were 
authorized before as of time
-        EntityConditionList<EntityCondition> authorizationConditions = 
EntityCondition.makeCondition(UtilMisc.toList(
-                EntityCondition.makeCondition("finAccountId", 
EntityOperator.EQUALS, finAccountId),
-                EntityCondition.makeCondition("authorizationDate", 
EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime),
-                EntityUtil.getFilterByDateExpr(asOfDateTime)),
-            EntityOperator.AND);
-
-        List<GenericValue> authSums = delegator.findList("FinAccountAuthSum", 
authorizationConditions, UtilMisc.toSet("amount"), null, null, false);
+        List<GenericValue> authSums = EntityQuery.use(delegator)
+                .select("amount")
+                .from("FinAccountAuthSum")
+                .where(EntityCondition.makeCondition("finAccountId", 
EntityOperator.EQUALS, finAccountId),
+                        EntityCondition.makeCondition("authorizationDate", 
EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime))
+                .queryList();
 
         BigDecimal authorizationsTotal = addFirstEntryAmount(ZERO, authSums, 
"amount", (decimals+1), rounding);
 
@@ -239,7 +239,7 @@ public class FinAccountHelper {
     public static boolean validatePin(Delegator delegator, String 
finAccountId, String pinNumber) {
         GenericValue finAccount = null;
         try {
-            finAccount = delegator.findOne("FinAccount", 
UtilMisc.toMap("finAccountId", finAccountId), false);
+            finAccount = 
EntityQuery.use(delegator).from("FinAccount").where("finAccountId", 
finAccountId).queryOne();
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
         }
@@ -296,7 +296,7 @@ public class FinAccountHelper {
     }
 
     private static boolean checkIsNumberInDatabase(Delegator delegator, String 
number) throws GenericEntityException {
-        GenericValue finAccount = delegator.findOne("FinAccount", 
UtilMisc.toMap("finAccountId", number), false);
+        GenericValue finAccount = 
EntityQuery.use(delegator).from("FinAccount").where("finAccountId", 
number).queryOne();
         return finAccount == null;
     }
 

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java?rev=1635382&r1=1635381&r2=1635382&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java 
(original)
+++ 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java 
Thu Oct 30 04:16:45 2014
@@ -28,6 +28,7 @@ import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityQuery;
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ModelService;
@@ -172,7 +173,7 @@ public class OrderChangeHelper {
             Delegator delegator = dispatcher.getDelegator();
             GenericValue orderHeader = null;
             try {
-                orderHeader = delegator.findOne("OrderHeader", 
UtilMisc.toMap("orderId", orderId), false);
+                orderHeader = 
EntityQuery.use(delegator).from("OrderHeader").where("orderId", 
orderId).queryOne();
             } catch (GenericEntityException e) {
                 Debug.logError(e, "ERROR: Unable to get OrderHeader for 
OrderID : " + orderId, module);
             }
@@ -306,7 +307,7 @@ public class OrderChangeHelper {
         // find the workEffortId for this order
         List workEfforts = null;
         try {
-            workEfforts = delegator.findByAnd("WorkEffort", 
UtilMisc.toMap("currentStatusId", "WF_SUSPENDED", "sourceReferenceId", 
orderId));
+            workEfforts = 
EntityQuery.use(delegator).from("WorkEffort").where("currentStatusId", 
"WF_SUSPENDED", sourceReferenceId", orderId).queryList();
         } catch (GenericEntityException e) {
             Debug.logError(e, "Problems getting WorkEffort with order ref 
number: " + orderId, module);
             return false;
@@ -348,7 +349,7 @@ public class OrderChangeHelper {
         // find the workEffortId for this order
         GenericValue workEffort = null;
         try {
-            List workEfforts = delegator.findByAnd("WorkEffort", 
UtilMisc.toMap("workEffortTypeId", "WORK_FLOW", "sourceReferenceId", orderId));
+            List workEfforts = 
EntityQuery.use(delegator).from("WorkEffort").where("workEffortTypeId", 
"WORK_FLOW", "sourceReferenceId", orderId).queryList();
             if (workEfforts != null && workEfforts.size() > 1) {
                 Debug.logWarning("More then one workflow found for defined 
order: " + orderId, module);
             }

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderContentWrapper.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderContentWrapper.java?rev=1635382&r1=1635381&r2=1635382&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderContentWrapper.java
 (original)
+++ 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderContentWrapper.java
 Thu Oct 30 04:16:45 2014
@@ -21,7 +21,6 @@ package org.ofbiz.order.order;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
-import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
@@ -32,13 +31,12 @@ import javolution.util.FastMap;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.UtilHttp;
-import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.cache.UtilCache;
 import org.ofbiz.content.content.ContentWorker;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericValue;
-import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.entity.util.EntityQuery;
 import org.ofbiz.service.LocalDispatcher;
 
 /**
@@ -134,9 +132,12 @@ public class OrderContentWrapper {
             mimeTypeId = "text/html";
         }
 
-        List<GenericValue> orderContentList = 
delegator.findByAnd("OrderContent", UtilMisc.toMap("orderId", orderId, 
"orderItemSeqId", orderItemSeqId, "orderContentTypeId", orderContentTypeId), 
UtilMisc.toList("-fromDate"), true);
-        orderContentList = EntityUtil.filterByDate(orderContentList);
-        GenericValue orderContent = EntityUtil.getFirst(orderContentList);
+        GenericValue orderContent = 
EntityQuery.use(delegator).from("OrderContent")
+                .where("orderId", orderId,
+                        "orderItemSeqId", orderItemSeqId,
+                        "orderContentTypeId", orderContentTypeId)
+                .orderBy("-fromDate")
+                .cache().filterByDate().queryFirst();
         if (orderContent != null) {
             // when rendering the order content, always include the 
OrderHeader/OrderItem and OrderContent records that this comes from
             Map<String, Object> inContext = FastMap.newInstance();

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderEvents.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderEvents.java?rev=1635382&r1=1635381&r2=1635382&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderEvents.java 
(original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderEvents.java 
Thu Oct 30 04:16:45 2014
@@ -32,11 +32,11 @@ import javax.servlet.http.HttpSession;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.UtilHttp;
-import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.content.data.DataResourceWorker;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityQuery;
 
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.LocalDispatcher;
@@ -61,15 +61,18 @@ public class OrderEvents {
 
         try {
             // has the userLogin.partyId ordered a product with 
DIGITAL_DOWNLOAD content associated for the given dataResourceId?
-            List<GenericValue> orderRoleAndProductContentInfoList = 
delegator.findByAnd("OrderRoleAndProductContentInfo",
-                    UtilMisc.toMap("partyId", userLogin.get("partyId"), 
"dataResourceId", dataResourceId, "productContentTypeId", "DIGITAL_DOWNLOAD", 
"statusId", "ITEM_COMPLETED"), null, false);
+            GenericValue orderRoleAndProductContentInfo = 
EntityQuery.use(delegator).from("OrderRoleAndProductContentInfo")
+                    .where("partyId", userLogin.get("partyId"),
+                            "dataResourceId", dataResourceId,
+                            "productContentTypeId", "DIGITAL_DOWNLOAD",
+                            "statusId", "ITEM_COMPLETED")
+                    .queryFirst();
 
-            if (orderRoleAndProductContentInfoList.size() == 0) {
+            if (orderRoleAndProductContentInfo == null) {
                 request.setAttribute("_ERROR_MESSAGE_", "No record of purchase 
for digital download found (dataResourceId=[" + dataResourceId + "]).");
                 return "error";
             }
 
-            GenericValue orderRoleAndProductContentInfo = 
orderRoleAndProductContentInfoList.get(0);
 
             // TODO: check validity based on ProductContent fields: 
useCountLimit, useTime/useTimeUomId
 
@@ -113,7 +116,7 @@ public class OrderEvents {
         if (orderItemSeqIds != null) {
             for (String orderItemSeqId : orderItemSeqIds) {
                 try {
-                    GenericValue orderItem = delegator.findOne("OrderItem", 
UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId), false);
+                    GenericValue orderItem = 
EntityQuery.use(delegator).from("OrderItem").where("orderId", orderId, 
"orderItemSeqId", orderItemSeqId).queryOne();
                     List<GenericValue> orderItemShipGroupAssocs = 
orderItem.getRelated("OrderItemShipGroupAssoc", null, null, false);
                     for (GenericValue orderItemShipGroupAssoc : 
orderItemShipGroupAssocs) {
                         GenericValue orderItemShipGroup = 
orderItemShipGroupAssoc.getRelatedOne("OrderItemShipGroup", false);

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderListState.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderListState.java?rev=1635382&r1=1635381&r2=1635382&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderListState.java 
(original)
+++ 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderListState.java 
Thu Oct 30 04:16:45 2014
@@ -32,15 +32,14 @@ import javolution.util.FastMap;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilDateTime;
-import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.condition.EntityCondition;
 import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.util.EntityFindOptions;
 import org.ofbiz.entity.util.EntityListIterator;
+import org.ofbiz.entity.util.EntityQuery;
 
 /**
  * Session object for keeping track of the list of orders.
@@ -260,10 +259,12 @@ public class OrderListState implements S
             allConditions.add(typeConditionsList);
         }
 
-        EntityCondition queryConditionsList = 
EntityCondition.makeCondition(allConditions, EntityOperator.AND);
-        EntityFindOptions options = new EntityFindOptions(true, 
EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, 
true);
-        options.setMaxRows(viewSize * (viewIndex + 1));
-        EntityListIterator iterator = delegator.find("OrderHeader", 
queryConditionsList, null, null, UtilMisc.toList("orderDate DESC"), options);
+        EntityListIterator iterator = 
EntityQuery.use(delegator).from("OrderHeader")
+                .where(allConditions)
+                .orderBy("orderDate DESC")
+                .maxRows(viewSize * (viewIndex + 1))
+                .cursorScrollInsensitive()
+                .queryIterator();
 
         // get subset corresponding to pagination state
         List<GenericValue> orders = iterator.getPartialList(viewSize * 
viewIndex, viewSize);

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java?rev=1635382&r1=1635381&r2=1635382&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java
 (original)
+++ 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java
 Thu Oct 30 04:16:45 2014
@@ -23,8 +23,10 @@ import java.math.BigDecimal;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 
 import javolution.util.FastList;
+import javolution.util.FastSet;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
@@ -44,8 +46,8 @@ import org.ofbiz.entity.condition.Entity
 import org.ofbiz.entity.condition.EntityOperator;
 import org.ofbiz.entity.model.DynamicViewEntity;
 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.security.Security;
 import org.ofbiz.service.DispatchContext;
 import org.ofbiz.service.GenericServiceException;
@@ -75,7 +77,7 @@ public class OrderLookupServices {
         }
 
         // list of fields to select (initial list)
-        List<String> fieldsToSelect = FastList.newInstance();
+        Set<String> fieldsToSelect = FastSet.newInstance();
         fieldsToSelect.add("orderId");
         fieldsToSelect.add("orderName");
         fieldsToSelect.add("statusId");
@@ -253,7 +255,7 @@ public class OrderLookupServices {
         if (UtilValidate.isNotEmpty(userLoginId) && 
UtilValidate.isEmpty(partyId)) {
             GenericValue ul = null;
             try {
-                ul = delegator.findOne("UserLogin", 
UtilMisc.toMap("userLoginId", userLoginId), true);
+                ul = 
EntityQuery.use(delegator).from("UserLogin").where("userLoginId", 
userLoginId).cache().queryOne();
             } catch (GenericEntityException e) {
                 Debug.logWarning(e.getMessage(), module);
             }
@@ -384,7 +386,7 @@ public class OrderLookupServices {
             } else {
                 GenericValue product = null;
                 try {
-                    product = delegator.findOne("Product", 
UtilMisc.toMap("productId", productId), false);
+                    product = 
EntityQuery.use(delegator).from("Product").where("productId", 
productId).queryOne();
                 } catch (GenericEntityException e) {
                     Debug.logWarning(e.getMessage(), module);
                 }
@@ -565,9 +567,6 @@ public class OrderLookupServices {
             conditions.add(exprs);
         }
 
-        // set distinct on so we only get one row per order
-        EntityFindOptions findOpts = new EntityFindOptions(true, 
EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, 
true);
-
         // create the main condition
         EntityCondition cond = null;
         if (conditions.size() > 0 || showAll.equalsIgnoreCase("Y")) {
@@ -584,13 +583,19 @@ public class OrderLookupServices {
         // get the index for the partial list
         int lowIndex = (((viewIndex.intValue() - 1) * viewSize.intValue()) + 
1);
         int highIndex = viewIndex.intValue() * viewSize.intValue();
-        findOpts.setMaxRows(highIndex);
 
         if (cond != null) {
             EntityListIterator eli = null;
             try {
                 // do the lookup
-                eli = delegator.findListIteratorByCondition(dve, cond, null, 
fieldsToSelect, orderBy, findOpts);
+                eli = EntityQuery.use(delegator)
+                        .select(fieldsToSelect)
+                        .from(dve)
+                        .orderBy(orderBy)
+                        .distinct() // set distinct on so we only get one row 
per order
+                        .maxRows(highIndex)
+                        .cursorScrollInsensitive()
+                        .queryIterator();
 
                 orderCount = eli.getResultsSizeAfterPartialList();
 

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java?rev=1635382&r1=1635381&r2=1635382&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java 
(original)
+++ 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java 
Thu Oct 30 04:16:45 2014
@@ -50,6 +50,7 @@ import org.ofbiz.entity.condition.Entity
 import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.util.EntityQuery;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.product.product.ProductWorker;
 import org.ofbiz.security.Security;
@@ -129,7 +130,7 @@ public class OrderReadHelper {
 
     public OrderReadHelper(Delegator delegator, String orderId) {
         try {
-            this.orderHeader = delegator.findOne("OrderHeader", 
UtilMisc.toMap("orderId", orderId), false);
+            this.orderHeader = 
EntityQuery.use(delegator).from("OrderHeader").where("orderId", 
orderId).queryOne();
         } catch (GenericEntityException e) {
             String errMsg = "Error finding order with ID [" + orderId + "]: " 
+ e.toString();
             Debug.logError(e, errMsg, module);
@@ -163,7 +164,7 @@ public class OrderReadHelper {
         String productStoreId = orderHeader.getString("productStoreId");
         try {
             Delegator delegator = orderHeader.getDelegator();
-            GenericValue productStore = delegator.findOne("ProductStore", 
UtilMisc.toMap("productStoreId", productStoreId), true);
+            GenericValue productStore = 
EntityQuery.use(delegator).from("ProductStore").where("productStoreId", 
productStoreId).cache().queryOne();
             return productStore;
         } catch (GenericEntityException ex) {
             Debug.logError(ex, "Failed to get product store for order header 
[" + orderHeader + "] due to exception "+ ex.getMessage(), module);
@@ -665,7 +666,8 @@ public class OrderReadHelper {
             List<GenericValue> paymentPreferences = null;
             try {
                 Delegator delegator = orderHeader.getDelegator();
-                paymentPreferences = 
delegator.findByAnd("OrderPurchasePaymentSummary", UtilMisc.toMap("orderId", 
orderHeader.getString("orderId")), null, false);
+                paymentPreferences = 
EntityQuery.use(delegator).from("OrderPurchasePaymentSummary")
+                        .where("orderId", 
orderHeader.get("orderId")).queryList();
             } catch (GenericEntityException e) {
                 Debug.logWarning(e, module);
             }
@@ -730,10 +732,10 @@ public class OrderReadHelper {
             GenericValue orderRole = 
EntityUtil.getFirst(orderHeader.getRelated("OrderRole", 
UtilMisc.toMap("roleTypeId", roleTypeId), null, false));
 
             if (orderRole != null) {
-                partyObject = delegator.findOne("Person", 
UtilMisc.toMap("partyId", orderRole.getString("partyId")), false);
+                partyObject = 
EntityQuery.use(delegator).from("Person").where("partyId", 
orderRole.getString("partyId")).queryOne();
 
                 if (partyObject == null) {
-                    partyObject = delegator.findOne("PartyGroup", 
UtilMisc.toMap("partyId", orderRole.getString("partyId")), false);
+                    partyObject = 
EntityQuery.use(delegator).from("PartyGroup").where("partyId", 
orderRole.getString("partyId")).queryOne();
                 }
             }
         } catch (GenericEntityException e) {
@@ -998,7 +1000,7 @@ public class OrderReadHelper {
                     try {
                         String virtualId = 
ProductWorker.getVariantVirtualId(product);
                         if (UtilValidate.isNotEmpty(virtualId)) {
-                            GenericValue virtual = 
delegator.findOne("Product", UtilMisc.toMap("productId", virtualId), true);
+                            GenericValue virtual = 
EntityQuery.use(delegator).from("Product").where("productId", 
virtualId).cache().queryOne();
                             if (virtual != null) {
                                 weight = virtual.getBigDecimal("weight");
                             }
@@ -1114,7 +1116,7 @@ public class OrderReadHelper {
                     try {
                         String virtualId = 
ProductWorker.getVariantVirtualId(product);
                         if (UtilValidate.isNotEmpty(virtualId)) {
-                            GenericValue virtual = 
delegator.findOne("Product", UtilMisc.toMap("productId", virtualId), true);
+                            GenericValue virtual = 
EntityQuery.use(delegator).from("Product").where("productId", 
virtualId).cache().queryOne();
                             if (virtual != null) {
                                 if (height == null) height = 
virtual.getBigDecimal("shippingHeight");
                                 if (width == null) width = 
virtual.getBigDecimal("shippingWidth");
@@ -1160,9 +1162,11 @@ public class OrderReadHelper {
                     // get the virtual product and check its weight
                     GenericValue virtual = null;
                     try {
-                        List<GenericValue> virtuals = 
delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productIdTo", 
product.getString("productId"), "productAssocTypeId", "PRODUCT_VARIANT"), 
UtilMisc.toList("-fromDate"), false);
-                        virtuals = EntityUtil.filterByDate(virtuals);
-                        virtual = EntityUtil.getFirst(virtuals);
+                        virtual = 
EntityQuery.use(delegator).from("ProductAssoc")
+                                .where("productIdTo", product.get("productId"),
+                                        "productAssocTypeId", 
"PRODUCT_VARIANT")
+                                .orderBy("-fromDate")
+                                .filterByDate().queryFirst();
                     } catch (GenericEntityException e) {
                         Debug.logError(e, "Problem getting virtual product");
                     }
@@ -1214,8 +1218,10 @@ public class OrderReadHelper {
         // get the email addresses from the order contact mech(s)
         List<GenericValue> orderContactMechs = null;
         try {
-            Map<String, Object> ocFields = UtilMisc.toMap("orderId", 
orderHeader.get("orderId"), "contactMechPurposeTypeId", "ORDER_EMAIL");
-            orderContactMechs = delegator.findByAnd("OrderContactMech", 
ocFields, null, false);
+            orderContactMechs = 
EntityQuery.use(delegator).from("OrderContactMech")
+                    .where("orderId", orderHeader.get("orderId"),
+                            "contactMechPurposeTypeId", "ORDER_EMAIL")
+                    .queryList();
         } catch (GenericEntityException e) {
             Debug.logWarning(e, "Problems getting order contact mechs", 
module);
         }
@@ -1315,7 +1321,8 @@ public class OrderReadHelper {
         Delegator delegator = orderHeader.getDelegator();
         List<GenericValue> surveys = null;
         try {
-            surveys = delegator.findByAnd("SurveyResponse", 
UtilMisc.toMap("orderId", orderHeader.getString("orderId")), null, false);
+            surveys = EntityQuery.use(delegator).from("SurveyResponse")
+                    .where("orderId", orderHeader.get("orderId")).queryList();
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
         }
@@ -1382,7 +1389,7 @@ public class OrderReadHelper {
         Delegator delegator = orderHeader.getDelegator();
         GenericValue orderDeliverySchedule = null;
         try {
-            orderDeliverySchedule = delegator.findOne("OrderDeliverySchedule", 
UtilMisc.toMap("orderId", orderId, "orderItemSeqId", "_NA_"), false);
+            orderDeliverySchedule = 
EntityQuery.use(delegator).from("OrderDeliverySchedule").where("orderId", 
orderId, "orderItemSeqId", "_NA_").queryOne();
         } catch (GenericEntityException e) {
         }
         Timestamp estimatedShipDate = null;
@@ -1549,9 +1556,10 @@ public class OrderReadHelper {
         GenericValue workOrderItemFulFillment = null;
         GenericValue workEffort = null;
         try {
-            List<GenericValue> workOrderItemFulFillments = 
delegator.findByAnd("WorkOrderItemFulfillment", UtilMisc.toMap("orderId", 
orderId, "orderItemSeqId", orderItemSeqId), null, true);
-            if (!UtilValidate.isEmpty(workOrderItemFulFillments)) {
-                workOrderItemFulFillment = 
EntityUtil.getFirst(workOrderItemFulFillments);
+            workOrderItemFulFillment = 
EntityQuery.use(delegator).from("WorkOrderItemFulfillment")
+                    .where("orderId", orderId, "orderItemSeqId", 
orderItemSeqId)
+                    .cache().queryFirst();
+            if (workOrderItemFulFillment != null) {
                 workEffort = 
workOrderItemFulFillment.getRelatedOne("WorkEffort", false);
             }
         } catch (GenericEntityException e) {
@@ -1584,7 +1592,8 @@ public class OrderReadHelper {
             Delegator delegator = orderHeader.getDelegator();
 
             try {
-                orderItemPriceInfos = 
delegator.findByAnd("OrderItemPriceInfo", UtilMisc.toMap("orderId", 
orderHeader.get("orderId")), null, false);
+                orderItemPriceInfos = 
EntityQuery.use(delegator).from("OrderItemPriceInfo")
+                        .where("orderId", 
orderHeader.get("orderId")).queryList();
             } catch (GenericEntityException e) {
                 Debug.logWarning(e, module);
             }
@@ -1610,7 +1619,8 @@ public class OrderReadHelper {
         if (this.orderItemShipGrpInvResList == null) {
             Delegator delegator = orderItem.getDelegator();
             try {
-                orderItemShipGrpInvResList = 
delegator.findByAnd("OrderItemShipGrpInvRes", UtilMisc.toMap("orderId", 
orderItem.get("orderId")), null, false);
+                orderItemShipGrpInvResList = 
EntityQuery.use(delegator).from("OrderItemShipGrpInvRes")
+                        .where("orderId", 
orderItem.get("orderId")).queryList();
             } catch (GenericEntityException e) {
                 Debug.logWarning(e, "Trouble getting OrderItemShipGrpInvRes 
List", module);
             }
@@ -1628,7 +1638,8 @@ public class OrderReadHelper {
             Delegator delegator = orderItem.getDelegator();
 
             try {
-                orderItemIssuances = delegator.findByAnd("ItemIssuance", 
UtilMisc.toMap("orderId", orderItem.get("orderId")), null, false);
+                orderItemIssuances = 
EntityQuery.use(delegator).from("ItemIssuance")
+                        .where("orderId", 
orderItem.get("orderId")).queryList();
             } catch (GenericEntityException e) {
                 Debug.logWarning(e, "Trouble getting ItemIssuance(s)", module);
             }
@@ -1657,7 +1668,7 @@ public class OrderReadHelper {
         Delegator delegator = orderHeader.getDelegator();
         if (this.orderReturnItems == null) {
             try {
-                this.orderReturnItems = delegator.findByAnd("ReturnItem", 
UtilMisc.toMap("orderId", orderHeader.getString("orderId")), null, false);
+                this.orderReturnItems = 
EntityQuery.use(delegator).from("ReturnItem").where("orderId", 
orderHeader.get("orderId")).queryList();
             } catch (GenericEntityException e) {
                 Debug.logError(e, "Problem getting ReturnItem from order", 
module);
                 return null;
@@ -2137,7 +2148,7 @@ public class OrderReadHelper {
         Delegator delegator = orderHeader.getDelegator();
         Set<String> productPromoCodesEntered = FastSet.newInstance();
         try {
-            for (GenericValue orderProductPromoCode: 
delegator.findByAnd("OrderProductPromoCode", UtilMisc.toMap("orderId", 
orderHeader.get("orderId")), null, true)) {
+            for (GenericValue orderProductPromoCode: 
EntityQuery.use(delegator).from("OrderProductPromoCode").where("orderId", 
orderHeader.get("orderId")).cache().queryList()) {
                 
productPromoCodesEntered.add(orderProductPromoCode.getString("productPromoCodeId"));
             }
         } catch (GenericEntityException e) {
@@ -2149,7 +2160,7 @@ public class OrderReadHelper {
     public List<GenericValue> getProductPromoUse() {
         Delegator delegator = orderHeader.getDelegator();
         try {
-            return delegator.findByAnd("ProductPromoUse", 
UtilMisc.toMap("orderId", orderHeader.get("orderId")), null, true);
+            return 
EntityQuery.use(delegator).from("ProductPromoUse").where("orderId", 
orderHeader.get("orderId")).cache().queryList();
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
         }
@@ -2181,7 +2192,7 @@ public class OrderReadHelper {
         GenericValue orderHeader = null;
         if (orderId != null && delegator != null) {
             try {
-                orderHeader = delegator.findOne("OrderHeader", 
UtilMisc.toMap("orderId", orderId), false);
+                orderHeader = 
EntityQuery.use(delegator).from("OrderHeader").where("orderId", 
orderId).queryOne();
             } catch (GenericEntityException e) {
                 Debug.logError(e, "Cannot get order header", module);
             }
@@ -2226,7 +2237,7 @@ public class OrderReadHelper {
         GenericValue productStore = null;
         if (orderHeader.get("productStoreId") != null) {
             try {
-                productStore = delegator.findOne("ProductStore", 
UtilMisc.toMap("productStoreId", orderHeader.getString("productStoreId")), 
true);
+                productStore = 
EntityQuery.use(delegator).from("ProductStore").where("productStoreId", 
orderHeader.getString("productStoreId")).cache().queryOne();
             } catch (GenericEntityException e) {
                 Debug.logError(e, "Cannot locate ProductStore from 
OrderHeader", module);
             }
@@ -2292,7 +2303,7 @@ public class OrderReadHelper {
         String orderId = orderHeader.getString("orderId");
         List<GenericValue> responses = null;
         try {
-            responses = delegator.findByAnd("SurveyResponse", 
UtilMisc.toMap("orderId", orderId, "orderItemSeqId", "_NA_"), null, false);
+            responses = 
EntityQuery.use(delegator).from("SurveyResponse").where("orderId", orderId, 
"orderItemSeqId", "_NA_").queryList();
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
         }
@@ -2309,7 +2320,7 @@ public class OrderReadHelper {
         String orderId = orderItem.getString("orderId");
         List<GenericValue> responses = null;
         try {
-            responses = delegator.findByAnd("SurveyResponse", 
UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId), null, 
false);
+            responses = 
EntityQuery.use(delegator).from("SurveyResponse").where("orderId", orderId, 
"orderItemSeqId", orderItemSeqId).queryList();
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
         }
@@ -2629,15 +2640,15 @@ public class OrderReadHelper {
         BigDecimal quantity = BigDecimal.ZERO;
 
         // first find all open purchase orders
-        List<EntityExpr> openOrdersExprs = 
UtilMisc.toList(EntityCondition.makeCondition("orderTypeId", 
EntityOperator.EQUALS, "PURCHASE_ORDER"));
-        openOrdersExprs.add(EntityCondition.makeCondition("itemStatusId", 
EntityOperator.NOT_EQUAL, "ITEM_CANCELLED"));
-        openOrdersExprs.add(EntityCondition.makeCondition("itemStatusId", 
EntityOperator.NOT_EQUAL, "ITEM_REJECTED"));
-        openOrdersExprs.add(EntityCondition.makeCondition("itemStatusId", 
EntityOperator.NOT_EQUAL, "ITEM_COMPLETED"));
-        openOrdersExprs.add(EntityCondition.makeCondition("productId", 
EntityOperator.EQUALS, productId));
-        EntityCondition openOrdersCond = 
EntityCondition.makeCondition(openOrdersExprs, EntityOperator.AND);
         List<GenericValue> openOrders = null;
         try {
-            openOrders = delegator.findList("OrderHeaderAndItems", 
openOrdersCond, null, null, null, false);
+            openOrders = EntityQuery.use(delegator).from("OrderHeaderAndItems")
+                    .where(EntityCondition.makeCondition("orderTypeId", 
EntityOperator.EQUALS, "PURCHASE_ORDER"),
+                            EntityCondition.makeCondition("itemStatusId", 
EntityOperator.NOT_EQUAL, "ITEM_CANCELLED"),
+                            EntityCondition.makeCondition("itemStatusId", 
EntityOperator.NOT_EQUAL, "ITEM_REJECTED"),
+                            EntityCondition.makeCondition("itemStatusId", 
EntityOperator.NOT_EQUAL, "ITEM_COMPLETED"),
+                            EntityCondition.makeCondition("productId", 
EntityOperator.EQUALS, productId))
+                    .queryList();
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
         }
@@ -2722,7 +2733,7 @@ public class OrderReadHelper {
         List<GenericValue> adjustments;
         try {
             // TODO: find on a view-entity with a sum is probably more 
efficient
-            adjustments = delegator.findByAnd("ReturnAdjustment", condition, 
null, false);
+            adjustments = 
EntityQuery.use(delegator).from("ReturnAdjustment").where(condition).queryList();
             if (adjustments != null) {
                 for (GenericValue returnAdjustment : adjustments) {
                     total = 
total.add(setScaleByType("RET_SALES_TAX_ADJ".equals(returnAdjustment.get("returnAdjustmentTypeId")),returnAdjustment.getBigDecimal("amount")));
@@ -2933,20 +2944,21 @@ public class OrderReadHelper {
         BigDecimal accountLimit = getAccountLimit(billingAccount);
         balance = balance.add(accountLimit);
         // pending (not cancelled, rejected, or received) order payments
-        EntityConditionList<EntityExpr> whereConditions = 
EntityCondition.makeCondition(UtilMisc.toList(
-                EntityCondition.makeCondition("billingAccountId", 
EntityOperator.EQUALS, billingAccountId),
-                EntityCondition.makeCondition("paymentMethodTypeId", 
EntityOperator.EQUALS, "EXT_BILLACT"),
-                EntityCondition.makeCondition("statusId", 
EntityOperator.NOT_IN, UtilMisc.toList("ORDER_CANCELLED", "ORDER_REJECTED")),
-                EntityCondition.makeCondition("preferenceStatusId", 
EntityOperator.NOT_IN, UtilMisc.toList("PAYMENT_SETTLED", "PAYMENT_RECEIVED", 
"PAYMENT_DECLINED", "PAYMENT_CANCELLED")) // PAYMENT_NOT_AUTH
-           ), EntityOperator.AND);
+        List<GenericValue> orderPaymentPreferenceSums = 
EntityQuery.use(delegator)
+                .select("maxAmount")
+                .from("OrderPurchasePaymentSummary")
+                .where(EntityCondition.makeCondition("billingAccountId", 
EntityOperator.EQUALS, billingAccountId),
+                        EntityCondition.makeCondition("paymentMethodTypeId", 
EntityOperator.EQUALS, "EXT_BILLACT"),
+                        EntityCondition.makeCondition("statusId", 
EntityOperator.NOT_IN, UtilMisc.toList("ORDER_CANCELLED", "ORDER_REJECTED")),
+                        EntityCondition.makeCondition("preferenceStatusId", 
EntityOperator.NOT_IN, UtilMisc.toList("PAYMENT_SETTLED", "PAYMENT_RECEIVED", 
"PAYMENT_DECLINED", "PAYMENT_CANCELLED"))) // PAYMENT_NOT_AUTH
+                .queryList();
 
-        List<GenericValue> orderPaymentPreferenceSums = 
delegator.findList("OrderPurchasePaymentSummary", whereConditions, 
UtilMisc.toSet("maxAmount"), null, null, false);
         for (GenericValue orderPaymentPreferenceSum : 
orderPaymentPreferenceSums) {
             BigDecimal maxAmount = 
orderPaymentPreferenceSum.getBigDecimal("maxAmount");
             balance = maxAmount != null ? balance.subtract(maxAmount) : 
balance;
         }
 
-        List<GenericValue> paymentAppls = 
delegator.findByAnd("PaymentApplication", UtilMisc.toMap("billingAccountId", 
billingAccountId), null, false);
+        List<GenericValue> paymentAppls = 
EntityQuery.use(delegator).from("PaymentApplication").where("billingAccountId", 
billingAccountId).queryList();
         // TODO: cancelled payments?
         for (GenericValue paymentAppl : paymentAppls) {
             if (paymentAppl.getString("invoiceId") == null) {


Reply via email to