svn commit: r1761047 - in /ofbiz/trunk: applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/ applications/accounting/src/main/java/org/apache/ofbiz/accounting/payment/ framework/entity/src/main/java/org/apache/ofbiz/entity/util/

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

svn commit: r1761047 - in /ofbiz/trunk: applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/ applications/accounting/src/main/java/org/apache/ofbiz/accounting/payment/ framework/entity/src/main/java/org/apache/ofbiz/entity/util/

jleroux@apache.org
Author: jleroux
Date: Fri Sep 16 15:15:34 2016
New Revision: 1761047

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

These are a non functional changes for the accounting component
I forgot to commit the change in EntityListIterator.java, hence a lot of confusion, sorry guys

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
    ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.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=1761047&r1=1761046&r2=1761047&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:15:34 2016
@@ -376,10 +376,7 @@ public class FinAccountServices {
                         EntityCondition.makeCondition("finAccountId", EntityOperator.EQUALS, finAccountId));
                 EntityCondition condition = EntityCondition.makeCondition(exprs, EntityOperator.AND);
 
-                EntityListIterator eli = null;
-                try {
-                    eli = EntityQuery.use(delegator).from("FinAccountTrans").where(condition).orderBy("-transactionDate").queryIterator();
-
+                try (EntityListIterator 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");
@@ -475,14 +472,6 @@ 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=1761047&r1=1761046&r2=1761047&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:15:34 2016
@@ -2688,16 +2688,10 @@ public class PaymentGatewayServices {
         LocalDispatcher dispatcher = dctx.getDispatcher();
         GenericValue userLogin = (GenericValue) context.get("userLogin");
 
-        // 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")
+        try (EntityListIterator 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);
@@ -2717,14 +2711,6 @@ 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();
@@ -2741,12 +2727,11 @@ public class PaymentGatewayServices {
         calcCal.add(Calendar.WEEK_OF_YEAR, -1);
         Timestamp oneWeekAgo = new Timestamp(calcCal.getTimeInMillis());
 
-        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();
+
+        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()) {
 
             List<String> processList = new LinkedList<String>();
             if (eli != null) {
@@ -2767,14 +2752,6 @@ 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();
     }
@@ -2837,7 +2814,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;

Modified: ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java?rev=1761047&r1=1761046&r2=1761047&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java (original)
+++ ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java Fri Sep 16 15:15:34 2016
@@ -44,7 +44,7 @@ import org.apache.ofbiz.entity.model.Mod
 /**
  * Generic Entity Cursor List Iterator for Handling Cursored DB Results
  */
-public class EntityListIterator implements ListIterator<GenericValue> {
+public class EntityListIterator implements AutoCloseable, ListIterator<GenericValue> {
 
     /** Module Name Used for debugging */
     public static final String module = EntityListIterator.class.getName();