svn commit: r1761045 - in /ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting: finaccount/FinAccountServices.java payment/PaymentGatewayServices.java

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

svn commit: r1761045 - in /ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting: finaccount/FinAccountServices.java payment/PaymentGatewayServices.java

jleroux@apache.org
Author: jleroux
Date: Fri Sep 16 15:06:20 2016
New Revision: 1761045

URL: http://svn.apache.org/viewvc?rev=1761045&view=rev
Log:
Improves: Use try-with-resources statement wherever it's possible
(OFBIZ-8202)

Reverts r1761023 because it works locally on Windows but not locally on Linux see http://markmail.org/message/r5pxmyymsj74ywek

I have no ideas why this happens yet, still investigating

Modified:
    ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountServices.java
    ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/payment/PaymentGatewayServices.java

Modified: ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountServices.java?rev=1761045&r1=1761044&r2=1761045&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountServices.java Fri Sep 16 15:06:20 2016
@@ -376,7 +376,10 @@ public class FinAccountServices {
                         EntityCondition.makeCondition("finAccountId", EntityOperator.EQUALS, finAccountId));
                 EntityCondition condition = EntityCondition.makeCondition(exprs, EntityOperator.AND);
 
-                try (EntityListIterator eli  = EntityQuery.use(delegator).from("FinAccountTrans").where(condition).orderBy("-transactionDate").queryIterator()) {
+                EntityListIterator eli = null;
+                try {
+                    eli = EntityQuery.use(delegator).from("FinAccountTrans").where(condition).orderBy("-transactionDate").queryIterator();
+
                     GenericValue trans;
                     while (remainingBalance.compareTo(FinAccountHelper.ZERO) < 0 && (trans = eli.next()) != null) {
                         String orderId = trans.getString("orderId");
@@ -472,6 +475,14 @@ public class FinAccountServices {
                 } catch (GeneralException e) {
                     Debug.logError(e, module);
                     return ServiceUtil.returnError(e.getMessage());
+                } finally {
+                    if (eli != null) {
+                        try {
+                            eli.close();
+                        } catch (GenericEntityException e) {
+                            Debug.logWarning(e, module);
+                        }
+                    }
                 }
 
                 // check to make sure we balanced out

Modified: ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/payment/PaymentGatewayServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/payment/PaymentGatewayServices.java?rev=1761045&r1=1761044&r2=1761045&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/payment/PaymentGatewayServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/payment/PaymentGatewayServices.java Fri Sep 16 15:06:20 2016
@@ -2688,10 +2688,16 @@ public class PaymentGatewayServices {
         LocalDispatcher dispatcher = dctx.getDispatcher();
         GenericValue userLogin = (GenericValue) context.get("userLogin");
 
-        try (EntityListIterator eli = EntityQuery.use(delegator).from("OrderPaymentPreference")
+        // get a list of all payment prefs still pending
+        List<EntityExpr> exprs = UtilMisc.toList(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PAYMENT_NOT_AUTH"),
+                EntityCondition.makeCondition("processAttempt", EntityOperator.GREATER_THAN, Long.valueOf(0)));
+
+        EntityListIterator eli = null;
+        try {
+            eli = EntityQuery.use(delegator).from("OrderPaymentPreference")
                     .where(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PAYMENT_NOT_AUTH"),
                             EntityCondition.makeCondition("processAttempt", EntityOperator.GREATER_THAN, Long.valueOf(0)))
-                    .orderBy("orderId").queryIterator()) {
+                    .orderBy("orderId").queryIterator();
             List<String> processList = new LinkedList<String>();
             if (eli != null) {
                 Debug.logInfo("Processing failed order re-auth(s)", module);
@@ -2711,6 +2717,14 @@ public class PaymentGatewayServices {
             }
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
+        } finally {
+            if (eli != null) {
+                try {
+                    eli.close();
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                }
+            }
         }
 
         return ServiceUtil.returnSuccess();
@@ -2727,11 +2741,12 @@ public class PaymentGatewayServices {
         calcCal.add(Calendar.WEEK_OF_YEAR, -1);
         Timestamp oneWeekAgo = new Timestamp(calcCal.getTimeInMillis());
 
-
-        try (EntityListIterator eli = EntityQuery.use(delegator).from("OrderPaymentPreference")
-                .where(EntityCondition.makeCondition("needsNsfRetry", EntityOperator.EQUALS, "Y"),
-                        EntityCondition.makeCondition(ModelEntity.STAMP_FIELD, EntityOperator.LESS_THAN_EQUAL_TO, oneWeekAgo))
-                .orderBy("orderId").queryIterator()) {
+        EntityListIterator eli = null;
+        try {
+            eli = EntityQuery.use(delegator).from("OrderPaymentPreference")
+                    .where(EntityCondition.makeCondition("needsNsfRetry", EntityOperator.EQUALS, "Y"),
+                            EntityCondition.makeCondition(ModelEntity.STAMP_FIELD, EntityOperator.LESS_THAN_EQUAL_TO, oneWeekAgo))
+                    .orderBy("orderId").queryIterator();
 
             List<String> processList = new LinkedList<String>();
             if (eli != null) {
@@ -2752,6 +2767,14 @@ public class PaymentGatewayServices {
             }
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
+        } finally {
+            if (eli != null) {
+                try {
+                    eli.close();
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                }
+            }
         }
         return ServiceUtil.returnSuccess();
     }
@@ -2814,7 +2837,7 @@ public class PaymentGatewayServices {
     }
 
     public static boolean checkAuthValidity(GenericValue orderPaymentPreference, String paymentConfig) {
-        Delegator delegator = orderPaymentPreference.getDelegator();
+     Delegator delegator = orderPaymentPreference.getDelegator();
         Timestamp authTime = PaymentGatewayServices.getAuthTime(orderPaymentPreference);
         if (authTime == null) {
             return false;