details: https://code.openbravo.com/erp/devel/pi/rev/ba00fcc9d5bf changeset: 26891:ba00fcc9d5bf user: Atul Gaware <atul.gaware <at> openbravo.com> date: Wed Jun 10 09:56:13 2015 +0530 summary: Fixes Issue 30120:ScrollableResults object should be closed
ScrollableResults objects are closed in a finally block. details: https://code.openbravo.com/erp/devel/pi/rev/4c6de7a747e1 changeset: 26892:4c6de7a747e1 user: Víctor Martínez Romanos <victor.martinez <at> openbravo.com> date: Wed Jun 10 17:02:19 2015 +0200 summary: Related to issue 30120: Applied OB code format diffstat: src/org/openbravo/costing/LCMatchingProcess.java | 40 +++++---- src/org/openbravo/costing/LandedCostDistributionByAmount.java | 30 ++++--- src/org/openbravo/costing/LandedCostProcess.java | 46 +++++----- src/org/openbravo/costing/StandardCostAdjustment.java | 36 ++++--- src/org/openbravo/event/GLJournalEventHandler.java | 12 +- 5 files changed, 91 insertions(+), 73 deletions(-) diffs (249 lines): diff -r 34641a1a0c78 -r 4c6de7a747e1 src/org/openbravo/costing/LCMatchingProcess.java --- a/src/org/openbravo/costing/LCMatchingProcess.java Wed Jun 10 15:51:06 2015 +0200 +++ b/src/org/openbravo/costing/LCMatchingProcess.java Wed Jun 10 17:02:19 2015 +0200 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2014 Openbravo SLU + * All portions are Copyright (C) 2014-2015 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************* @@ -166,25 +166,29 @@ ScrollableResults receiptamts = qryLCRLA.scroll(ScrollMode.FORWARD_ONLY); int i = 0; - while (receiptamts.next()) { - Object[] receiptAmt = receiptamts.get(); - BigDecimal amt = (BigDecimal) receiptAmt[0]; - ShipmentInOutLine receiptLine = OBDal.getInstance().get(ShipmentInOutLine.class, - receiptAmt[1]); - MaterialTransaction trx = receiptLine.getMaterialMgmtMaterialTransactionList().get(0); - CostAdjustmentLine cal = CostAdjustmentUtils.insertCostAdjustmentLine(trx, ca, amt, true, - referenceDate); - cal.setNeedsPosting(Boolean.FALSE); - cal.setUnitCost(Boolean.FALSE); - cal.setCurrency(lcCost.getCurrency()); - OBDal.getInstance().save(cal); + try { + while (receiptamts.next()) { + Object[] receiptAmt = receiptamts.get(); + BigDecimal amt = (BigDecimal) receiptAmt[0]; + ShipmentInOutLine receiptLine = OBDal.getInstance().get(ShipmentInOutLine.class, + receiptAmt[1]); + MaterialTransaction trx = receiptLine.getMaterialMgmtMaterialTransactionList().get(0); + CostAdjustmentLine cal = CostAdjustmentUtils.insertCostAdjustmentLine(trx, ca, amt, true, + referenceDate); + cal.setNeedsPosting(Boolean.FALSE); + cal.setUnitCost(Boolean.FALSE); + cal.setCurrency(lcCost.getCurrency()); + OBDal.getInstance().save(cal); - if (i % 100 == 0) { - OBDal.getInstance().flush(); - OBDal.getInstance().getSession().clear(); - ca = OBDal.getInstance().get(CostAdjustment.class, ca.getId()); + if (i % 100 == 0) { + OBDal.getInstance().flush(); + OBDal.getInstance().getSession().clear(); + ca = OBDal.getInstance().get(CostAdjustment.class, ca.getId()); + } + i++; } - i++; + } finally { + receiptamts.close(); } ca = OBDal.getInstance().get(CostAdjustment.class, ca.getId()); CostAdjustmentProcess.doProcessCostAdjustment(ca); diff -r 34641a1a0c78 -r 4c6de7a747e1 src/org/openbravo/costing/LandedCostDistributionByAmount.java --- a/src/org/openbravo/costing/LandedCostDistributionByAmount.java Wed Jun 10 15:51:06 2015 +0200 +++ b/src/org/openbravo/costing/LandedCostDistributionByAmount.java Wed Jun 10 17:02:19 2015 +0200 @@ -67,20 +67,24 @@ critLCRL.add(Restrictions.eq(LCReceipt.PROPERTY_LANDEDCOST, landedCost)); ScrollableResults receiptCosts = getReceiptCosts(landedCost, false); int i = 0; - while (receiptCosts.next()) { - String strTrxCur = (String) receiptCosts.get()[2]; - BigDecimal trxAmt = (BigDecimal) receiptCosts.get()[3]; - if (!strTrxCur.equals(strCurId)) { - trxAmt = getConvertedAmount(trxAmt, strTrxCur, strCurId, dateReference, strOrgId); + try { + while (receiptCosts.next()) { + String strTrxCur = (String) receiptCosts.get()[2]; + BigDecimal trxAmt = (BigDecimal) receiptCosts.get()[3]; + if (!strTrxCur.equals(strCurId)) { + trxAmt = getConvertedAmount(trxAmt, strTrxCur, strCurId, dateReference, strOrgId); + } + + totalAmt = totalAmt.add(trxAmt); + + if (i % 100 == 0) { + OBDal.getInstance().flush(); + OBDal.getInstance().getSession().clear(); + } + i++; } - - totalAmt = totalAmt.add(trxAmt); - - if (i % 100 == 0) { - OBDal.getInstance().flush(); - OBDal.getInstance().getSession().clear(); - } - i++; + } finally { + receiptCosts.close(); } BigDecimal pendingAmt = baseAmt; diff -r 34641a1a0c78 -r 4c6de7a747e1 src/org/openbravo/costing/LandedCostProcess.java --- a/src/org/openbravo/costing/LandedCostProcess.java Wed Jun 10 15:51:06 2015 +0200 +++ b/src/org/openbravo/costing/LandedCostProcess.java Wed Jun 10 17:02:19 2015 +0200 @@ -226,29 +226,33 @@ ScrollableResults receiptamts = qryLCRLA.scroll(ScrollMode.FORWARD_ONLY); int i = 0; - while (receiptamts.next()) { - log.debug("Process receipt amounts"); - Object[] receiptAmt = receiptamts.get(); - BigDecimal amt = (BigDecimal) receiptAmt[0]; - Currency lcCostCurrency = OBDal.getInstance().get(Currency.class, receiptAmt[1]); - ShipmentInOutLine receiptLine = OBDal.getInstance().get(ShipmentInOutLine.class, - receiptAmt[2]); - // MaterialTransaction receiptLine = (MaterialTransaction) record[1]; - MaterialTransaction trx = receiptLine.getMaterialMgmtMaterialTransactionList().get(0); - CostAdjustmentLine cal = CostAdjustmentUtils.insertCostAdjustmentLine(trx, ca, amt, true, - referenceDate); - cal.setNeedsPosting(Boolean.FALSE); - cal.setUnitCost(Boolean.FALSE); - cal.setCurrency(lcCostCurrency); - cal.setLineNo((i + 1) * 10L); - OBDal.getInstance().save(cal); + try { + while (receiptamts.next()) { + log.debug("Process receipt amounts"); + Object[] receiptAmt = receiptamts.get(); + BigDecimal amt = (BigDecimal) receiptAmt[0]; + Currency lcCostCurrency = OBDal.getInstance().get(Currency.class, receiptAmt[1]); + ShipmentInOutLine receiptLine = OBDal.getInstance().get(ShipmentInOutLine.class, + receiptAmt[2]); + // MaterialTransaction receiptLine = (MaterialTransaction) record[1]; + MaterialTransaction trx = receiptLine.getMaterialMgmtMaterialTransactionList().get(0); + CostAdjustmentLine cal = CostAdjustmentUtils.insertCostAdjustmentLine(trx, ca, amt, true, + referenceDate); + cal.setNeedsPosting(Boolean.FALSE); + cal.setUnitCost(Boolean.FALSE); + cal.setCurrency(lcCostCurrency); + cal.setLineNo((i + 1) * 10L); + OBDal.getInstance().save(cal); - if (i % 100 == 0) { - OBDal.getInstance().flush(); - OBDal.getInstance().getSession().clear(); - ca = OBDal.getInstance().get(CostAdjustment.class, ca.getId()); + if (i % 100 == 0) { + OBDal.getInstance().flush(); + OBDal.getInstance().getSession().clear(); + ca = OBDal.getInstance().get(CostAdjustment.class, ca.getId()); + } + i++; } - i++; + } finally { + receiptamts.close(); } CostAdjustmentProcess.doProcessCostAdjustment(ca); diff -r 34641a1a0c78 -r 4c6de7a747e1 src/org/openbravo/costing/StandardCostAdjustment.java --- a/src/org/openbravo/costing/StandardCostAdjustment.java Wed Jun 10 15:51:06 2015 +0200 +++ b/src/org/openbravo/costing/StandardCostAdjustment.java Wed Jun 10 17:02:19 2015 +0200 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2014 Openbravo SLU + * All portions are Copyright (C) 2014-2015 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************* @@ -88,22 +88,26 @@ ScrollableResults trxs = getRelatedTransactions(newCosting.getStartingDate(), newCosting.getEndingDate()); int i = 1; - while (trxs.next()) { - MaterialTransaction relTrx = (MaterialTransaction) trxs.get()[0]; - BigDecimal currentCost = CostAdjustmentUtils.getTrxCost(relTrx, true, trx.getCurrency()); - BigDecimal expectedCost = relTrx.getMovementQuantity().abs().multiply(unitCost) - .setScale(stdCurPrecission, RoundingMode.HALF_UP); - if (expectedCost.compareTo(currentCost) != 0) { - CostAdjustmentLine newCAL = insertCostAdjustmentLine(relTrx, - expectedCost.subtract(currentCost), null); - newCAL.setRelatedTransactionAdjusted(true); + try { + while (trxs.next()) { + MaterialTransaction relTrx = (MaterialTransaction) trxs.get()[0]; + BigDecimal currentCost = CostAdjustmentUtils.getTrxCost(relTrx, true, trx.getCurrency()); + BigDecimal expectedCost = relTrx.getMovementQuantity().abs().multiply(unitCost) + .setScale(stdCurPrecission, RoundingMode.HALF_UP); + if (expectedCost.compareTo(currentCost) != 0) { + CostAdjustmentLine newCAL = insertCostAdjustmentLine(relTrx, + expectedCost.subtract(currentCost), null); + newCAL.setRelatedTransactionAdjusted(true); + } + + if (i % 100 == 0) { + OBDal.getInstance().flush(); + OBDal.getInstance().getSession().clear(); + } + i++; } - - if (i % 100 == 0) { - OBDal.getInstance().flush(); - OBDal.getInstance().getSession().clear(); - } - i++; + } finally { + trxs.close(); } } } diff -r 34641a1a0c78 -r 4c6de7a747e1 src/org/openbravo/event/GLJournalEventHandler.java --- a/src/org/openbravo/event/GLJournalEventHandler.java Wed Jun 10 15:51:06 2015 +0200 +++ b/src/org/openbravo/event/GLJournalEventHandler.java Wed Jun 10 17:02:19 2015 +0200 @@ -43,7 +43,8 @@ return entities; } - public void onUpdate(@Observes EntityUpdateEvent event) { + public void onUpdate(@Observes + EntityUpdateEvent event) { if (!isValidEvent(event)) { return; } @@ -58,8 +59,9 @@ GLJournalLine.class); gljournallineCriteria.add(Restrictions.eq(GLJournalLine.PROPERTY_JOURNALENTRY, glj)); ScrollableResults scrollLines = gljournallineCriteria.scroll(ScrollMode.FORWARD_ONLY); - if (gljournallineCriteria.count() > 0) { - try { + + try { + if (gljournallineCriteria.count() > 0) { int i = 0; while (scrollLines.next()) { final GLJournalLine journalLine = (GLJournalLine) scrollLines.get()[0]; @@ -77,9 +79,9 @@ OBDal.getInstance().getSession().clear(); } } - } finally { - scrollLines.close(); } + } finally { + scrollLines.close(); } } } ------------------------------------------------------------------------------ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits