Author: jleroux
Date: Fri Sep 16 11:53:27 2016 New Revision: 1761023 URL: http://svn.apache.org/viewvc?rev=1761023&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 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=1761023&r1=1761022&r2=1761023&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 11:53:27 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=1761023&r1=1761022&r2=1761023&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 11:53:27 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; |
Free forum by Nabble | Edit this page |