svn commit: r1139890 - /ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1139890 - /ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java

doogie-3
Author: doogie
Date: Sun Jun 26 18:11:44 2011
New Revision: 1139890

URL: http://svn.apache.org/viewvc?rev=1139890&view=rev
Log:
FIX: service:createAlsoBoughtProductAssocs was run in a
transaction, but on large systems, when fetching all orders and all
bought products, then running createAlsoBoughtProductAssocsForOrder in a
loop, the outer transaction would time out.  Turn off transactions on
the outer layer, and do it all internally.

Modified:
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=1139890&r1=1139889&r2=1139890&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Sun Jun 26 18:11:44 2011
@@ -31,6 +31,7 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.Callable;
 
 import javax.transaction.Transaction;
 
@@ -5550,7 +5551,7 @@ public class OrderServices {
     }
 
     public static Map<String, Object> createAlsoBoughtProductAssocs(DispatchContext dctx, Map<String, ? extends Object> context) {
-        Delegator delegator = dctx.getDelegator();
+        final Delegator delegator = dctx.getDelegator();
         LocalDispatcher dispatcher = dctx.getDispatcher();
         // All orders with an entryDate > orderEntryFromDateTime will be processed
         Timestamp orderEntryFromDateTime = (Timestamp) context.get("orderEntryFromDateTime");
@@ -5590,29 +5591,38 @@ public class OrderServices {
         if (!processAllOrders && orderEntryFromDateTime != null) {
             orderCondList.add(EntityCondition.makeCondition("entryDate", EntityOperator.GREATER_THAN, orderEntryFromDateTime));
         }
-        EntityCondition cond = EntityCondition.makeCondition(orderCondList);
-        EntityListIterator eli = null;
+        final EntityCondition cond = EntityCondition.makeCondition(orderCondList);
+        List<String> orderIds;
         try {
-            eli = delegator.find("OrderHeader", cond, null, null, UtilMisc.toList("entryDate ASC"), null);
+            orderIds = TransactionUtil.doNewTransaction("getSalesOrderIds", new Callable<List<String>>() {
+                public List<String> call() throws Exception {
+                    List<String> orderIds = new LinkedList<String>();
+                    EntityListIterator eli = null;
+                    try {
+                        eli = delegator.find("OrderHeader", cond, null, UtilMisc.toSet("orderId"), UtilMisc.toList("entryDate ASC"), null);
+                        GenericValue orderHeader;
+                        while ((orderHeader = eli.next()) != null) {
+                            orderIds.add(orderHeader.getString("orderId"));
+                        }
+                    } finally {
+                        if (eli != null) {
+                            eli.close();
+                        }
+                    }
+                    return orderIds;
+                }
+            });
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
             return ServiceUtil.returnError(e.getMessage());
         }
-        if (eli != null) {
-            GenericValue orderHeader = null;
-            while ((orderHeader = eli.next()) != null) {
-                Map<String, Object> svcIn = FastMap.newInstance();
-                svcIn.put("userLogin", context.get("userLogin"));
-                svcIn.put("orderId", orderHeader.get("orderId"));
-                try {
-                    dispatcher.runSync("createAlsoBoughtProductAssocsForOrder", svcIn);
-                } catch (GenericServiceException e) {
-                    Debug.logError(e, module);
-                }
-            }
+        for (String orderId: orderIds) {
+            Map<String, Object> svcIn = FastMap.newInstance();
+            svcIn.put("userLogin", context.get("userLogin"));
+            svcIn.put("orderId", orderId);
             try {
-                eli.close();
-            } catch (GenericEntityException e) {
+                dispatcher.runSync("createAlsoBoughtProductAssocsForOrder", svcIn);
+            } catch (GenericServiceException e) {
                 Debug.logError(e, module);
             }
         }