Fixes Issue
30120:ScrollableResults object should be closed
ScrollableResults objects are closed in a finally block.
--- 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 09:56:13 2015 +0530
@@ -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);
--- 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 09:56:13 2015 +0530
@@ -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;
--- 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 09:56:13 2015 +0530
@@ -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);
--- 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 09:56:13 2015 +0530
@@ -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)
+ 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 (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();
}
}
}
--- 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 09:56:13 2015 +0530
@@ -58,8 +58,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 +78,9 @@
OBDal.getInstance().getSession().clear();
}
}
- } finally {
- scrollLines.close();
}
+ } finally {
+ scrollLines.close();
}
}
}