You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2007/04/16 21:08:04 UTC

svn commit: r529363 - /ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java

Author: jonesde
Date: Mon Apr 16 12:08:03 2007
New Revision: 529363

URL: http://svn.apache.org/viewvc?view=rev&rev=529363
Log:
Fixed problem caused by recent ProductSearch changes; also fixed issue with transaction for query and such, uses a timeout of 10 minutes instead of 1 as well for these ops

Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java

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?view=diff&rev=529363&r1=529362&r2=529363
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java Mon Apr 16 12:08:03 2007
@@ -53,6 +53,7 @@
 
     public static final String module = ProductSearchEvents.class.getName();
     public static final String resource = "ProductUiLabels";
+    public static final int DEFAULT_TX_TIMEOUT = 600;
 
     /** Removes the results of a search from the specified category
      *@param request The HTTPRequest object for the current request
@@ -64,24 +65,23 @@
         String productCategoryId = request.getParameter("SE_SEARCH_CATEGORY_ID");
         String errMsg=null;
 
-        EntityListIterator eli = getProductSearchResults(request);
-        if (eli == null) {
-            errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
-            request.setAttribute("_ERROR_MESSAGE_", errMsg);
-            return "error";
-        }
-
         try {
-            boolean beganTransaction = TransactionUtil.begin();
+            boolean beganTransaction = TransactionUtil.begin(DEFAULT_TX_TIMEOUT);
             try {
+                EntityListIterator eli = getProductSearchResults(request);
+                if (eli == null) {
+                    errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
+                    request.setAttribute("_ERROR_MESSAGE_", errMsg);
+                    return "error";
+                }
+
                 int numRemoved = 0;
                 GenericValue searchResultView = null;
                 while ((searchResultView = (GenericValue) eli.next()) != null) {
-                    String productId = searchResultView.getString("productId");
+                    String productId = searchResultView.getString("mainProductId");
                     numRemoved += delegator.removeByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId )) ;
                 }
                 eli.close();
-                TransactionUtil.commit(beganTransaction);
                 Map messageMap = UtilMisc.toMap("numRemoved", Integer.toString(numRemoved));
                 errMsg = UtilProperties.getMessage(resource,"productsearchevents.removed_x_items", messageMap, UtilHttp.getLocale(request));
                 request.setAttribute("_EVENT_MESSAGE_", errMsg);
@@ -92,6 +92,8 @@
                 request.setAttribute("_ERROR_MESSAGE_", errMsg);
                 TransactionUtil.rollback(beganTransaction, errMsg, e);
                 return "error";
+            } finally {
+                TransactionUtil.commit(beganTransaction);
             }
         } catch (GenericTransactionException e) {
             Map messageMap = UtilMisc.toMap("errSearchResult", e.toString());
@@ -125,21 +127,20 @@
            return "error";
        }
 
-       EntityListIterator eli = getProductSearchResults(request);
-       if (eli == null) {
-           errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
-           request.setAttribute("_ERROR_MESSAGE_", errMsg);
-           return "error";
-       }
-
        try {
-           boolean beganTransaction = TransactionUtil.begin();
+           boolean beganTransaction = TransactionUtil.begin(DEFAULT_TX_TIMEOUT);
            try {
+               EntityListIterator eli = getProductSearchResults(request);
+               if (eli == null) {
+                   errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
+                   request.setAttribute("_ERROR_MESSAGE_", errMsg);
+                   return "error";
+               }
 
                GenericValue searchResultView = null;
                int numExpired=0;
                while ((searchResultView = (GenericValue) eli.next()) != null) {
-                   String productId = searchResultView.getString("productId");
+                   String productId = searchResultView.getString("mainProductId");
                    //get all tuples that match product and category
                    List pcmList = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId ));
 
@@ -158,7 +159,6 @@
                errMsg = UtilProperties.getMessage(resource,"productsearchevents.expired_x_items", messageMap, UtilHttp.getLocale(request));
                request.setAttribute("_EVENT_MESSAGE_", errMsg);
                eli.close();
-               TransactionUtil.commit(beganTransaction);
            } catch (GenericEntityException e) {
                Map messageMap = UtilMisc.toMap("errSearchResult", e.toString());
                errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request));
@@ -166,6 +166,8 @@
                request.setAttribute("_ERROR_MESSAGE_", errMsg);
                TransactionUtil.rollback(beganTransaction, errMsg, e);
                return "error";
+           } finally {
+               TransactionUtil.commit(beganTransaction);
            }
        } catch (GenericTransactionException e) {
            Map messageMap = UtilMisc.toMap("errSearchResult", e.toString());
@@ -199,22 +201,21 @@
             return "error";
         }
 
-       EntityListIterator eli = getProductSearchResults(request);
-       if (eli == null) {
-           errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
-           request.setAttribute("_ERROR_MESSAGE_", errMsg);
-           return "error";
-       }
-
        try {
-           boolean beganTransaction = TransactionUtil.begin();
+           boolean beganTransaction = TransactionUtil.begin(DEFAULT_TX_TIMEOUT);
            try {
+               EntityListIterator eli = getProductSearchResults(request);
+               if (eli == null) {
+                   errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
+                   request.setAttribute("_ERROR_MESSAGE_", errMsg);
+                   return "error";
+               }
 
                GenericValue searchResultView = null;
                List searchResultList = new ArrayList();
                int numAdded = 0;
                while ((searchResultView = (GenericValue) eli.next()) != null) {
-                   String productId = searchResultView.getString("productId");
+                   String productId = searchResultView.getString("mainProductId");
 
                    GenericValue pcm=delegator.makeValue("ProductCategoryMember", null);
                    pcm.set("productCategoryId", productCategoryId);
@@ -228,7 +229,6 @@
                errMsg = UtilProperties.getMessage(resource,"productsearchevents.added_x_product_category_members", messageMap, UtilHttp.getLocale(request));
                request.setAttribute("_EVENT_MESSAGE_", errMsg);
                eli.close();
-               TransactionUtil.commit(beganTransaction);
            } catch (GenericEntityException e) {
                Map messageMap = UtilMisc.toMap("errSearchResult", e.toString());
                errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request));
@@ -236,6 +236,8 @@
                request.setAttribute("_ERROR_MESSAGE_", errMsg);
                TransactionUtil.rollback(beganTransaction, errMsg, e);
                return "error";
+           } finally {
+               TransactionUtil.commit(beganTransaction);
            }
        } catch (GenericTransactionException e) {
            Map messageMap = UtilMisc.toMap("errSearchResult", e.toString());
@@ -289,20 +291,20 @@
             return "error";
         }
 
-        EntityListIterator eli = getProductSearchResults(request);
-        if (eli == null) {
-            String errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
-            request.setAttribute("_ERROR_MESSAGE_", errMsg);
-            return "error";
-        }
-
         try {
-            boolean beganTransaction = TransactionUtil.begin();
+            boolean beganTransaction = TransactionUtil.begin(DEFAULT_TX_TIMEOUT);
             try {
+                EntityListIterator eli = getProductSearchResults(request);
+                if (eli == null) {
+                    String errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
+                    request.setAttribute("_ERROR_MESSAGE_", errMsg);
+                    return "error";
+                }
+
                 GenericValue searchResultView = null;
                 int numAdded = 0;
                 while ((searchResultView = (GenericValue) eli.next()) != null) {
-                    String productId = searchResultView.getString("productId");
+                    String productId = searchResultView.getString("mainProductId");
                     GenericValue pfa=delegator.makeValue("ProductFeatureAppl", null);
                     pfa.set("productId", productId);
                     pfa.set("productFeatureId", productFeatureId);
@@ -318,13 +320,14 @@
                 String eventMsg = UtilProperties.getMessage(resource, "productSearchEvents.added_param_features", messageMap, locale) + ".";
                 request.setAttribute("_EVENT_MESSAGE_", eventMsg);
                 eli.close();
-                TransactionUtil.commit(beganTransaction);
             } catch (GenericEntityException e) {
                 String errorMsg = UtilProperties.getMessage(resource, "productSearchEvents.error_getting_results", locale) + " : " + e.toString();
                 request.setAttribute("_ERROR_MESSAGE_", errorMsg);
                 Debug.logError(e, errorMsg, module);
                 TransactionUtil.rollback(beganTransaction, errorMsg, e);
                 return "error";
+            } finally {
+                TransactionUtil.commit(beganTransaction);
             }
         } catch (GenericTransactionException e) {
             String errorMsg = UtilProperties.getMessage(resource, "productSearchEvents.error_getting_results", locale) + " : " + e.toString();
@@ -347,33 +350,34 @@
 
         String productFeatureId = request.getParameter("productFeatureId");
 
-        EntityListIterator eli = getProductSearchResults(request);
-        if (eli == null) {
-            String errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
-            request.setAttribute("_ERROR_MESSAGE_", errMsg);
-            return "error";
-        }
-
         try {
-            boolean beganTransaction = TransactionUtil.begin();
+            boolean beganTransaction = TransactionUtil.begin(DEFAULT_TX_TIMEOUT);
             try {
+                EntityListIterator eli = getProductSearchResults(request);
+                if (eli == null) {
+                    String errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
+                    request.setAttribute("_ERROR_MESSAGE_", errMsg);
+                    return "error";
+                }
+
                 GenericValue searchResultView = null;
                 int numRemoved = 0;
                 while ((searchResultView = (GenericValue) eli.next()) != null) {
-                    String productId = searchResultView.getString("productId");
+                    String productId = searchResultView.getString("mainProductId");
                     numRemoved += delegator.removeByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", productId, "productFeatureId", productFeatureId));
                 }
                 Map messageMap = UtilMisc.toMap("numRemoved", new Integer(numRemoved), "productFeatureId", productFeatureId);
                 String eventMsg = UtilProperties.getMessage(resource, "productSearchEvents.removed_param_features", messageMap, locale) + ".";
                 request.setAttribute("_EVENT_MESSAGE_", eventMsg);
                 eli.close();
-                TransactionUtil.commit(beganTransaction);
             } catch (GenericEntityException e) {
                 String errorMsg = UtilProperties.getMessage(resource, "productSearchEvents.error_getting_results", locale) + " : " + e.toString();
                 request.setAttribute("_ERROR_MESSAGE_", errorMsg);
                 Debug.logError(e, errorMsg, module);
                 TransactionUtil.rollback(beganTransaction, errorMsg, e);
                 return "error";
+            } finally {
+                TransactionUtil.commit(beganTransaction);
             }
         } catch (GenericTransactionException e) {
             String errorMsg = UtilProperties.getMessage(resource, "productSearchEvents.error_getting_results", locale) + " : " + e.toString();
@@ -395,21 +399,20 @@
         String errMsg = null;
         List productExportList = new ArrayList();
 
-        EntityListIterator eli = getProductSearchResults(request);
-        if (eli == null) {
-            errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
-            request.setAttribute("_ERROR_MESSAGE_", errMsg);
-            return "error";
-        }
-
         try {
-            boolean beganTransaction = TransactionUtil.begin();
+            boolean beganTransaction = TransactionUtil.begin(DEFAULT_TX_TIMEOUT);
             try {
+                EntityListIterator eli = getProductSearchResults(request);
+                if (eli == null) {
+                    errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
+                    request.setAttribute("_ERROR_MESSAGE_", errMsg);
+                    return "error";
+                }
 
                 GenericValue searchResultView = null;
                 while ((searchResultView = (GenericValue) eli.next()) != null) {
                     Map productMap = new HashMap();
-                    String productId = searchResultView.getString("productId");
+                    String productId = searchResultView.getString("mainProductId");
                     productMap.put("productId", productId);
                     
                     List productFeaturesCustomRaw = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureTypeId", "HAZMAT") );
@@ -425,7 +428,6 @@
                     productExportList.add(productMap);
                 }
                 eli.close();
-                TransactionUtil.commit(beganTransaction);
             } catch (GenericEntityException e) {
                 Map messageMap = UtilMisc.toMap("errSearchResult", e.toString());
                 errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request));
@@ -433,6 +435,8 @@
                 request.setAttribute("_ERROR_MESSAGE_", errMsg);
                 TransactionUtil.rollback(beganTransaction, errMsg, e);
                 return "error";
+            } finally {
+                TransactionUtil.commit(beganTransaction);
             }
         } catch (GenericTransactionException e) {
             Map messageMap = UtilMisc.toMap("errSearchResult", e.toString());