This is an automated email from the ASF dual-hosted git repository.
dixitdeepak pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new d801361203 Refactor Groovy EntityListIterator usage with
auto-closeable handling… (#1167)
d801361203 is described below
commit d80136120308907d72c0aafbc6b79781eb0db11f
Author: Deepak Dixit <[email protected]>
AuthorDate: Thu May 7 09:52:38 2026 +0530
Refactor Groovy EntityListIterator usage with auto-closeable handling…
(#1167)
Improved : Updated Groovy files to use safer resource management
patterns for EntityListIterator (OFBIZ-13399)
- Replaced manual iterator close handling with try-with-resources style
implementations where applicable
- Used Groovy withCloseable for automatic resource cleanup
- Replaced EntityListIterator usage with EntityQuery.queryPagedList()
where only partial/paged results were required
- Removed unnecessary manual close() calls
- Reduced risk of JDBC cursor and ResultSet resource leaks
- Improved readability and aligned code with modern OFBiz best practices
Changes were applied to Groovy files; full regression testing has not
yet been completed for all updated flows.
---
.../SalesInvoiceByProductCategorySummary.groovy | 41 ++++----
.../content/content/GetContentLookupList.groovy | 14 +--
.../content/survey/EditSurveyQuestions.groovy | 11 +-
.../order/reports/OpenOrderItemsReport.groovy | 113 ++++++++++-----------
.../ofbiz/party/party/PartyFinancialHistory.groovy | 73 +++++++------
.../party/party/UnAppliedInvoicesForParty.groovy | 34 +++----
.../party/party/UnAppliedPaymentsForParty.groovy | 43 ++++----
.../org/apache/ofbiz/party/visit/ShowVisits.groovy | 22 ++--
.../ofbiz/product/catalog/FastLoadCache.groovy | 20 ++--
.../feature/EditFeatureCategoryFeatures.groovy | 7 +-
.../product/ApplyFeaturesFromCategory.groovy | 7 +-
.../CountFacilityInventoryByProduct.groovy | 62 +++++------
.../facility/FindInventoryItemsByLabels.groovy | 15 +--
.../facility/ViewFacilityInventoryByProduct.groovy | 8 +-
.../facility/inventory/InventoryItemTotals.groovy | 7 +-
15 files changed, 220 insertions(+), 257 deletions(-)
diff --git
a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/reports/SalesInvoiceByProductCategorySummary.groovy
b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/reports/SalesInvoiceByProductCategorySummary.groovy
index 2bcd1a606f..dd1c59dae9 100644
---
a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/reports/SalesInvoiceByProductCategorySummary.groovy
+++
b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/reports/SalesInvoiceByProductCategorySummary.groovy
@@ -117,16 +117,17 @@ for (int currentDay = 0; currentDay <= daysInMonth;
currentDay++) {
productAndExprs.add(EntityCondition.makeCondition('invoiceDate',
EntityOperator.GREATER_THAN_EQUAL_TO, currentDayBegin))
productAndExprs.add(EntityCondition.makeCondition('invoiceDate',
EntityOperator.LESS_THAN, nextDayBegin))
- productResultListIterator = select('productId', 'quantityTotal',
'amountTotal')
-
.from('InvoiceItemProductSummary').where(productAndExprs).cursorScrollInsensitive().cache(true).queryIterator()
+ productResultListQuery = select('productId', 'quantityTotal',
'amountTotal')
+
.from('InvoiceItemProductSummary').where(productAndExprs).cursorScrollInsensitive().cache(true)
productResultMap = [:]
- while ((productResult = productResultListIterator.next()) != null) {
- productResultMap[productResult.productId] = productResult
- monthProductResult = UtilMisc.getMapFromMap(monthProductResultMap,
productResult.productId)
- UtilMisc.addToBigDecimalInMap(monthProductResult, 'quantityTotal',
productResult.getBigDecimal('quantityTotal'))
- UtilMisc.addToBigDecimalInMap(monthProductResult, 'amountTotal',
productResult.getBigDecimal('amountTotal'))
+ productResultListQuery.queryIterator().withCloseable {
productResultListIterator ->
+ while ((productResult = productResultListIterator.next()) != null) {
+ productResultMap[productResult.productId] = productResult
+ monthProductResult = UtilMisc.getMapFromMap(monthProductResultMap,
productResult.productId)
+ UtilMisc.addToBigDecimalInMap(monthProductResult, 'quantityTotal',
productResult.getBigDecimal('quantityTotal'))
+ UtilMisc.addToBigDecimalInMap(monthProductResult, 'amountTotal',
productResult.getBigDecimal('amountTotal'))
+ }
}
- productResultListIterator.close()
productResultMapByDayList.add(productResultMap)
// do the category find
@@ -135,16 +136,17 @@ for (int currentDay = 0; currentDay <= daysInMonth;
currentDay++) {
categoryAndExprs.add(EntityCondition.makeCondition('invoiceDate',
EntityOperator.GREATER_THAN_EQUAL_TO, currentDayBegin))
categoryAndExprs.add(EntityCondition.makeCondition('invoiceDate',
EntityOperator.LESS_THAN, nextDayBegin))
- categoryResultListIterator = select('productCategoryId', 'quantityTotal',
'amountTotal')
-
.from('InvoiceItemCategorySummary').where(categoryAndExprs).cursorScrollInsensitive().cache(true).queryIterator()
+ categoryResultListQuery = select('productCategoryId', 'quantityTotal',
'amountTotal')
+
.from('InvoiceItemCategorySummary').where(categoryAndExprs).cursorScrollInsensitive().cache(true)
categoryResultMap = [:]
- while ((categoryResult = categoryResultListIterator.next()) != null) {
- categoryResultMap[categoryResult.productCategoryId] = categoryResult
- monthCategoryResult = UtilMisc.getMapFromMap(monthCategoryResultMap,
categoryResult.productCategoryId)
- UtilMisc.addToBigDecimalInMap(monthCategoryResult, 'quantityTotal',
categoryResult.getBigDecimal('quantityTotal'))
- UtilMisc.addToBigDecimalInMap(monthCategoryResult, 'amountTotal',
categoryResult.getBigDecimal('amountTotal'))
+ categoryResultListQuery.queryIterator().with { categoryResultListIterator
->
+ while ((categoryResult = categoryResultListIterator.next()) != null) {
+ categoryResultMap[categoryResult.productCategoryId] =
categoryResult
+ monthCategoryResult =
UtilMisc.getMapFromMap(monthCategoryResultMap, categoryResult.productCategoryId)
+ UtilMisc.addToBigDecimalInMap(monthCategoryResult,
'quantityTotal', categoryResult.getBigDecimal('quantityTotal'))
+ UtilMisc.addToBigDecimalInMap(monthCategoryResult, 'amountTotal',
categoryResult.getBigDecimal('amountTotal'))
+ }
}
- categoryResultListIterator.close()
categoryResultMapByDayList.add(categoryResultMap)
// do a find for InvoiceItem with a null productId
@@ -153,11 +155,8 @@ for (int currentDay = 0; currentDay <= daysInMonth;
currentDay++) {
productNullAndExprs.add(EntityCondition.makeCondition('productId',
EntityOperator.EQUALS, null))
productNullAndExprs.add(EntityCondition.makeCondition('invoiceDate',
EntityOperator.GREATER_THAN_EQUAL_TO, currentDayBegin))
productNullAndExprs.add(EntityCondition.makeCondition('invoiceDate',
EntityOperator.LESS_THAN, nextDayBegin))
- productNullResultListIterator = select('productId', 'quantityTotal',
'amountTotal')
-
.from('InvoiceItemProductSummary').where(productNullAndExprs).cursorScrollInsensitive().cache(true).queryIterator()
- // should just be 1 result
- productNullResult = productNullResultListIterator.next()
- productNullResultListIterator.close()
+ productNullResult = select('productId', 'quantityTotal', 'amountTotal')
+
.from('InvoiceItemProductSummary').where(productNullAndExprs).cursorScrollInsensitive().cache(true).queryFirst()
if (productNullResult) {
productNullResultByDayList.add(productNullResult)
UtilMisc.addToBigDecimalInMap(monthProductNullResult, 'quantityTotal',
productNullResult.getBigDecimal('quantityTotal'))
diff --git
a/applications/content/src/main/groovy/org/apache/ofbiz/content/content/GetContentLookupList.groovy
b/applications/content/src/main/groovy/org/apache/ofbiz/content/content/GetContentLookupList.groovy
index 69f06fb39e..7248b0427e 100644
---
a/applications/content/src/main/groovy/org/apache/ofbiz/content/content/GetContentLookupList.groovy
+++
b/applications/content/src/main/groovy/org/apache/ofbiz/content/content/GetContentLookupList.groovy
@@ -26,6 +26,7 @@ import org.apache.ofbiz.entity.GenericEntity
import org.apache.ofbiz.entity.model.ModelField
import org.apache.ofbiz.entity.model.ModelEntity
import org.apache.ofbiz.entity.model.ModelReader
+import org.apache.ofbiz.entity.util.EntityListIterator
viewIndex = parameters.VIEW_INDEX ? Integer.valueOf(parameters.VIEW_INDEX) : 0
viewSize = parameters.VIEW_SIZE ? Integer.valueOf(parameters.VIEW_SIZE) : 20
@@ -68,17 +69,17 @@ context.curFindString = curFindString
context.viewSize = viewSize
context.lowIndex = lowIndex
int arraySize = 0
-List resultPartialList
+List resultPartialList = []
if ((highIndex - lowIndex + 1) > 0) {
// get the results as an entity list iterator
boolean beganTransaction = false
- try {
+ entityQuery = from('ContentAssocViewTo')
+ .where('contentIdStart', (String) parameters.get('contentId'))
+ .orderBy('contentId ASC')
+ .cursorScrollInsensitive().cache(true)
+ try (EntityListIterator listIt = entityQuery.queryIterator()) {
beganTransaction = TransactionUtil.begin()
- listIt = from('ContentAssocViewTo')
- .where('contentIdStart', (String) parameters.get('contentId'))
- .orderBy('contentId ASC')
- .cursorScrollInsensitive().cache(true).queryIterator()
resultPartialList = listIt.getPartialList(lowIndex, highIndex -
lowIndex + 1)
arraySize = listIt.getResultsSizeAfterPartialList()
@@ -96,7 +97,6 @@ if ((highIndex - lowIndex + 1) > 0) {
// after rolling back, rethrow the exception
throw e
} finally {
- listIt.close()
// only commit the transaction if we started one... this will throw an
exception if it fails
TransactionUtil.commit(beganTransaction)
}
diff --git
a/applications/content/src/main/groovy/org/apache/ofbiz/content/survey/EditSurveyQuestions.groovy
b/applications/content/src/main/groovy/org/apache/ofbiz/content/survey/EditSurveyQuestions.groovy
index 219cd0c720..fe40f07318 100644
---
a/applications/content/src/main/groovy/org/apache/ofbiz/content/survey/EditSurveyQuestions.groovy
+++
b/applications/content/src/main/groovy/org/apache/ofbiz/content/survey/EditSurveyQuestions.groovy
@@ -40,15 +40,14 @@ context.lowIndex = lowIndex
int listSize = 0
try {
- listIt = from('SurveyQuestionAndAppl')
+ pagedList = from('SurveyQuestionAndAppl')
.where('surveyId', surveyId)
.orderBy('sequenceNum')
.cursorScrollInsensitive()
.cache(true)
- .queryIterator()
- surveyQuestionAndApplList = listIt.getPartialList(lowIndex, highIndex -
lowIndex + 1)
-
- listSize = listIt.getResultsSizeAfterPartialList()
+ .queryPagedList(lowIndex, highIndex - lowIndex + 1)
+ surveyQuestionAndApplList = pagedList.getData()
+ listSize = pagedList.getSize()
if (listSize < highIndex) {
highIndex = listSize
}
@@ -58,8 +57,6 @@ try {
context.listSize = listSize
} catch (GenericEntityException e) {
logError(e, 'Failure in ' + module)
-} finally {
- listIt.close()
}
surveyPageList = from('SurveyPage').where('surveyId',
surveyId).orderBy('sequenceNum').queryList()
surveyMultiRespList = from('SurveyMultiResp').where('surveyId',
surveyId).orderBy('multiRespTitle').queryList()
diff --git
a/applications/order/src/main/groovy/org/apache/ofbiz/order/reports/OpenOrderItemsReport.groovy
b/applications/order/src/main/groovy/org/apache/ofbiz/order/reports/OpenOrderItemsReport.groovy
index f9f48620f2..1c7a9fe703 100644
---
a/applications/order/src/main/groovy/org/apache/ofbiz/order/reports/OpenOrderItemsReport.groovy
+++
b/applications/order/src/main/groovy/org/apache/ofbiz/order/reports/OpenOrderItemsReport.groovy
@@ -70,14 +70,13 @@
conditions.add(EntityCondition.makeCondition('orderItemStatusId', EntityOperator
// get the results as an entity list iterator
try {
- listIt = select('orderId', 'orderDate', 'productId', 'quantityOrdered',
+ listQuery = select('orderId', 'orderDate', 'productId', 'quantityOrdered',
'quantityIssued', 'quantityOpen', 'shipBeforeDate',
'shipAfterDate', 'itemDescription')
.from('OrderItemQuantityReportGroupByItem')
.where(conditions)
.orderBy('orderDate DESC')
.cursorScrollInsensitive()
.distinct()
- .queryIterator()
orderItemList = []
totalCostPrice = 0.0
totalListPrice = 0.0
@@ -87,68 +86,68 @@ try {
totalquantityOrdered = 0.0
totalquantityOpen = 0.0
- listIt.each { listValue ->
- orderId = listValue.orderId
- productId = listValue.productId
- orderDate = listValue.orderDate
- quantityOrdered = listValue.quantityOrdered
- quantityOpen = listValue.quantityOpen
- quantityIssued = listValue.quantityIssued
- itemDescription = listValue.itemDescription
- shipAfterDate = listValue.shipAfterDate
- shipBeforeDate = listValue.shipBeforeDate
- productIdCondExpr = [EntityCondition.makeCondition('productId',
EntityOperator.EQUALS, productId)]
- productPrices = select('price',
'productPriceTypeId').from('ProductPrice').where(productIdCondExpr).queryList()
- costPrice = 0.0
- retailPrice = 0.0
- listPrice = 0.0
+ listQuery.queryIterator().withCloseable { listIt ->
+ while ((listValue = listIt.next()) != null ) {
+ orderId = listValue.orderId
+ productId = listValue.productId
+ orderDate = listValue.orderDate
+ quantityOrdered = listValue.quantityOrdered
+ quantityOpen = listValue.quantityOpen
+ quantityIssued = listValue.quantityIssued
+ itemDescription = listValue.itemDescription
+ shipAfterDate = listValue.shipAfterDate
+ shipBeforeDate = listValue.shipBeforeDate
+ productIdCondExpr = [EntityCondition.makeCondition('productId',
EntityOperator.EQUALS, productId)]
+ productPrices = select('price',
'productPriceTypeId').from('ProductPrice').where(productIdCondExpr).queryList()
+ costPrice = 0.0
+ retailPrice = 0.0
+ listPrice = 0.0
- productPrices.each { productPriceMap ->
- switch (productPriceMap.productPriceTypeId) {
- case 'AVERAGE_COST':
- costPrice = productPriceMap.price
- break
- case 'DEFAULT_PRICE':
- retailPrice = productPriceMap.price
- break
- case 'LIST_PRICE':
- listPrice = productPriceMap.price
- break
+ productPrices.each { productPriceMap ->
+ switch (productPriceMap.productPriceTypeId) {
+ case 'AVERAGE_COST':
+ costPrice = productPriceMap.price
+ break
+ case 'DEFAULT_PRICE':
+ retailPrice = productPriceMap.price
+ break
+ case 'LIST_PRICE':
+ listPrice = productPriceMap.price
+ break
+ }
}
- }
- totalListPrice += listPrice
- totalRetailPrice += retailPrice
- totalCostPrice += costPrice
- totalquantityOrdered += quantityOrdered
- totalquantityOpen += quantityOpen
- costPriceDividendValue = costPrice
- if (costPriceDividendValue) {
- percentMarkup = ((retailPrice - costPrice) / costPrice) * 100
- } else {
- percentMarkup = ''
+ totalListPrice += listPrice
+ totalRetailPrice += retailPrice
+ totalCostPrice += costPrice
+ totalquantityOrdered += quantityOrdered
+ totalquantityOpen += quantityOpen
+ costPriceDividendValue = costPrice
+ if (costPriceDividendValue) {
+ percentMarkup = ((retailPrice - costPrice) / costPrice) * 100
+ } else {
+ percentMarkup = ''
+ }
+ orderItemMap = [orderDate: orderDate,
+ orderId: orderId,
+ productId: productId,
+ itemDescription: itemDescription,
+ quantityOrdered: quantityOrdered,
+ quantityIssued: quantityIssued,
+ quantityOpen: quantityOpen,
+ shipAfterDate: shipAfterDate,
+ shipBeforeDate: shipBeforeDate,
+ costPrice: costPrice,
+ retailPrice: retailPrice,
+ listPrice: listPrice,
+ discount: listPrice - retailPrice,
+ calculatedMarkup: retailPrice - costPrice,
+ percentMarkup: percentMarkup]
+ orderItemList.add(orderItemMap)
}
- orderItemMap = [orderDate: orderDate,
- orderId: orderId,
- productId: productId,
- itemDescription: itemDescription,
- quantityOrdered: quantityOrdered,
- quantityIssued: quantityIssued,
- quantityOpen: quantityOpen,
- shipAfterDate: shipAfterDate,
- shipBeforeDate: shipBeforeDate,
- costPrice: costPrice,
- retailPrice: retailPrice,
- listPrice: listPrice,
- discount: listPrice - retailPrice,
- calculatedMarkup: retailPrice - costPrice,
- percentMarkup: percentMarkup]
- orderItemList.add(orderItemMap)
}
} catch (GenericEntityException e) {
logError(e, 'Failure in ' + module)
-} finally {
- listIt.close()
}
totalAmountList = []
diff --git
a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/PartyFinancialHistory.groovy
b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/PartyFinancialHistory.groovy
index 278d1ee0b5..05ec2eb2e9 100644
---
a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/PartyFinancialHistory.groovy
+++
b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/PartyFinancialHistory.groovy
@@ -19,7 +19,6 @@
package org.apache.ofbiz.party.party
import java.math.RoundingMode
-
import org.apache.ofbiz.accounting.invoice.InvoiceWorker
import org.apache.ofbiz.accounting.payment.PaymentWorker
import org.apache.ofbiz.entity.condition.EntityCondition
@@ -54,30 +53,28 @@ invExprs =
], EntityOperator.OR)
], EntityOperator.AND)
-invIterator =
from('InvoiceAndType').where(invExprs).cursorScrollInsensitive().distinct().queryIterator()
-
-/* codenarc-disable */
-while (invoice = invIterator.next()) {
-/* codenarc-enable */
- Boolean isPurchaseInvoice = EntityTypeUtil.hasParentType(delegator,
'InvoiceType', 'invoiceTypeId',
- invoice.getString('invoiceTypeId'), 'parentTypeId',
'PURCHASE_INVOICE')
- Boolean isSalesInvoice = EntityTypeUtil.hasParentType(delegator,
'InvoiceType', 'invoiceTypeId', (String) invoice.getString('invoiceTypeId'),
- 'parentTypeId', 'SALES_INVOICE')
- if (isPurchaseInvoice) {
- totalInvPuApplied += InvoiceWorker.getInvoiceApplied(invoice,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
- totalInvPuNotApplied += InvoiceWorker.getInvoiceNotApplied(invoice,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
- }
- else if (isSalesInvoice) {
- totalInvSaApplied += InvoiceWorker.getInvoiceApplied(invoice,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
- totalInvSaNotApplied += InvoiceWorker.getInvoiceNotApplied(invoice,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
- }
- else {
- logError('InvoiceType: ' + invoice.invoiceTypeId + ' without a valid
parentTypeId: ' + invoice.parentTypeId
- + ' !!!! Should be either PURCHASE_INVOICE or SALES_INVOICE')
+invQuery =
from('InvoiceAndType').where(invExprs).cursorScrollInsensitive().distinct()
+invQuery.queryIterator().withCloseable { invIterator ->
+ /* codenarc-disable */
+ while (invoice = invIterator.next()) {
+ /* codenarc-enable */
+ Boolean isPurchaseInvoice =
EntityTypeUtil.hasParentType(delegator, 'InvoiceType', 'invoiceTypeId',
+ invoice.getString('invoiceTypeId'), 'parentTypeId',
'PURCHASE_INVOICE')
+ Boolean isSalesInvoice = EntityTypeUtil.hasParentType(delegator,
'InvoiceType',
+ 'invoiceTypeId', (String)
invoice.getString('invoiceTypeId'),
+ 'parentTypeId', 'SALES_INVOICE')
+ if (isPurchaseInvoice) {
+ totalInvPuApplied += InvoiceWorker.getInvoiceApplied(invoice,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
+ totalInvPuNotApplied +=
InvoiceWorker.getInvoiceNotApplied(invoice, actualCurrency).setScale(2,
RoundingMode.HALF_UP)
+ } else if (isSalesInvoice) {
+ totalInvSaApplied += InvoiceWorker.getInvoiceApplied(invoice,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
+ totalInvSaNotApplied +=
InvoiceWorker.getInvoiceNotApplied(invoice, actualCurrency).setScale(2,
RoundingMode.HALF_UP)
+ } else {
+ logError('InvoiceType: ' + invoice.invoiceTypeId + ' without a
valid parentTypeId: ' + invoice.parentTypeId
+ + ' !!!! Should be either PURCHASE_INVOICE or
SALES_INVOICE')
+ }
+ }
}
-}
-
-invIterator.close()
//get total/unapplied/applied payment in/out total amount:
totalPayInApplied = BigDecimal.ZERO
@@ -101,25 +98,23 @@ payExprs =
], EntityOperator.OR)
], EntityOperator.AND)
-payIterator =
from('PaymentAndType').where(payExprs).cursorScrollInsensitive().distinct().queryIterator()
-
+payQuery =
from('PaymentAndType').where(payExprs).cursorScrollInsensitive().distinct()
+payQuery.queryIterator().withCloseable { payIterator ->
/* codenarc-disable */
-while (payment = payIterator.next()) {
+ while (payment = payIterator.next()) {
/* codenarc-enable */
- if (payment.parentTypeId == 'DISBURSEMENT' || payment.parentTypeId ==
'TAX_PAYMENT') {
- totalPayOutApplied += PaymentWorker.getPaymentApplied(payment,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
- totalPayOutNotApplied += PaymentWorker.getPaymentNotApplied(payment,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
- }
- else if (payment.parentTypeId == 'RECEIPT') {
- totalPayInApplied += PaymentWorker.getPaymentApplied(payment,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
- totalPayInNotApplied += PaymentWorker.getPaymentNotApplied(payment,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
- }
- else {
- logError('PaymentTypeId: ' + payment.paymentTypeId + ' without a valid
parentTypeId: ' + payment.parentTypeId
- + ' !!!! Should be either DISBURSEMENT, TAX_PAYMENT or
RECEIPT')
+ if (payment.parentTypeId == 'DISBURSEMENT' || payment.parentTypeId ==
'TAX_PAYMENT') {
+ totalPayOutApplied += PaymentWorker.getPaymentApplied(payment,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
+ totalPayOutNotApplied +=
PaymentWorker.getPaymentNotApplied(payment, actualCurrency).setScale(2,
RoundingMode.HALF_UP)
+ } else if (payment.parentTypeId == 'RECEIPT') {
+ totalPayInApplied += PaymentWorker.getPaymentApplied(payment,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
+ totalPayInNotApplied +=
PaymentWorker.getPaymentNotApplied(payment, actualCurrency).setScale(2,
RoundingMode.HALF_UP)
+ } else {
+ logError('PaymentTypeId: ' + payment.paymentTypeId + ' without a
valid parentTypeId: ' + payment.parentTypeId
+ + ' !!!! Should be either DISBURSEMENT, TAX_PAYMENT or
RECEIPT')
+ }
}
}
-payIterator.close()
context.finanSummary = [:]
context.finanSummary.totalSalesInvoice = totalSalesInvoice =
totalInvSaApplied.add(totalInvSaNotApplied)
diff --git
a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedInvoicesForParty.groovy
b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedInvoicesForParty.groovy
index f4c23c5f4e..ef2f356a1b 100644
---
a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedInvoicesForParty.groovy
+++
b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedInvoicesForParty.groovy
@@ -46,28 +46,28 @@ invExprs =
], EntityOperator.OR)
], EntityOperator.AND)
-invIterator =
from('InvoiceAndType').where(invExprs).cursorScrollInsensitive().distinct().queryIterator()
+invQuery =
from('InvoiceAndType').where(invExprs).cursorScrollInsensitive().distinct()
invoiceList = []
-
+invQuery.queryIterator().withCloseable { invIterator ->
/* codenarc-disable */
-while (invoice = invIterator.next()) {
+ while (invoice = invIterator.next()) {
/* codenarc-enable */
- unAppliedAmount = InvoiceWorker.getInvoiceNotApplied(invoice,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
- if (unAppliedAmount.signum() == 1) {
- if (actualCurrency == true) {
- invoiceCurrencyUomId = invoice.currencyUomId
- } else {
- invoiceCurrencyUomId =
context.defaultOrganizationPartyCurrencyUomId
+ unAppliedAmount = InvoiceWorker.getInvoiceNotApplied(invoice,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
+ if (unAppliedAmount.signum() == 1) {
+ if (actualCurrency == true) {
+ invoiceCurrencyUomId = invoice.currencyUomId
+ } else {
+ invoiceCurrencyUomId =
context.defaultOrganizationPartyCurrencyUomId
+ }
+ invoiceList.add([invoiceId: invoice.invoiceId,
+ invoiceDate: invoice.invoiceDate,
+ unAppliedAmount: unAppliedAmount,
+ invoiceCurrencyUomId: invoiceCurrencyUomId,
+ amount: InvoiceWorker.getInvoiceTotal(invoice,
actualCurrency).setScale(2, RoundingMode.HALF_UP),
+ invoiceTypeId: invoice.invoiceTypeId,
+ invoiceParentTypeId: invoice.parentTypeId])
}
- invoiceList.add([invoiceId: invoice.invoiceId,
- invoiceDate: invoice.invoiceDate,
- unAppliedAmount: unAppliedAmount,
- invoiceCurrencyUomId: invoiceCurrencyUomId,
- amount: InvoiceWorker.getInvoiceTotal(invoice,
actualCurrency).setScale(2, RoundingMode.HALF_UP),
- invoiceTypeId: invoice.invoiceTypeId,
- invoiceParentTypeId: invoice.parentTypeId])
}
}
-invIterator.close()
context.ListUnAppliedInvoices = invoiceList
diff --git
a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedPaymentsForParty.groovy
b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedPaymentsForParty.groovy
index 51605bd171..0fa9daad0b 100644
---
a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedPaymentsForParty.groovy
+++
b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedPaymentsForParty.groovy
@@ -19,7 +19,6 @@
package org.apache.ofbiz.party.party
import java.math.RoundingMode
-
import org.apache.ofbiz.accounting.payment.PaymentWorker
import org.apache.ofbiz.entity.util.EntityFindOptions
import org.apache.ofbiz.entity.condition.EntityCondition
@@ -48,29 +47,29 @@ payExprs =
], EntityOperator.AND)
paymentList = []
-payIterator =
from('PaymentAndType').where(payExprs).cursorScrollInsensitive().distinct().queryIterator()
-
-/* codenarc-disable */
-while (payment = payIterator.next()) {
-/* codenarc-enable */
- unAppliedAmount = PaymentWorker.getPaymentNotApplied(payment,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
- if (unAppliedAmount.signum() == 1) {
- if (actualCurrency == true && payment.actualCurrencyAmount &&
payment.actualCurrencyUomId) {
- amount = payment.actualCurrencyAmount
- paymentCurrencyUomId = payment.actualCurrencyUomId
- } else {
- amount = payment.amount
- paymentCurrencyUomId = payment.currencyUomId
+entityQuery =
from('PaymentAndType').where(payExprs).cursorScrollInsensitive().distinct()
+entityQuery.queryIterator().withCloseable { payIterator ->
+ /* codenarc-disable */
+ while (payment = payIterator.next()) {
+ /* codenarc-enable */
+ unAppliedAmount = PaymentWorker.getPaymentNotApplied(payment,
actualCurrency).setScale(2, RoundingMode.HALF_UP)
+ if (unAppliedAmount.signum() == 1) {
+ if (actualCurrency == true && payment.actualCurrencyAmount &&
payment.actualCurrencyUomId) {
+ amount = payment.actualCurrencyAmount
+ paymentCurrencyUomId = payment.actualCurrencyUomId
+ } else {
+ amount = payment.amount
+ paymentCurrencyUomId = payment.currencyUomId
+ }
+ paymentList.add([paymentId: payment.paymentId,
+ effectiveDate: payment.effectiveDate,
+ unAppliedAmount: unAppliedAmount,
+ amount: amount,
+ paymentCurrencyUomId: paymentCurrencyUomId,
+ paymentTypeId: payment.paymentTypeId,
+ paymentParentTypeId: payment.parentTypeId])
}
- paymentList.add([paymentId: payment.paymentId,
- effectiveDate: payment.effectiveDate,
- unAppliedAmount: unAppliedAmount,
- amount: amount,
- paymentCurrencyUomId: paymentCurrencyUomId,
- paymentTypeId: payment.paymentTypeId,
- paymentParentTypeId: payment.parentTypeId])
}
}
-payIterator.close()
context.paymentList = paymentList
diff --git
a/applications/party/src/main/groovy/org/apache/ofbiz/party/visit/ShowVisits.groovy
b/applications/party/src/main/groovy/org/apache/ofbiz/party/visit/ShowVisits.groovy
index f65651396d..b1215d3a8c 100644
---
a/applications/party/src/main/groovy/org/apache/ofbiz/party/visit/ShowVisits.groovy
+++
b/applications/party/src/main/groovy/org/apache/ofbiz/party/visit/ShowVisits.groovy
@@ -19,6 +19,7 @@
package org.apache.ofbiz.party.visit
import org.apache.ofbiz.entity.transaction.TransactionUtil
+import org.apache.ofbiz.entity.util.EntityQuery
partyId = parameters.partyId
context.partyId = partyId
@@ -28,8 +29,6 @@ context.showAll = showAll
sort = parameters.sort
context.sort = sort
-
-visitListIt = null
sortList = ['-fromDate']
if (sort) {
sortList.add(0, sort)
@@ -48,20 +47,16 @@ try {
lowIndex = (((viewIndex - 1) * viewSize) + 1)
highIndex = viewIndex * viewSize
+ EntityQuery visitQuery =
from('Visit').orderBy(sortList).cursorScrollInsensitive().maxRows(highIndex).distinct()
if (partyId) {
- visitListIt = from('Visit')
- .where('partyId',
partyId).orderBy(sortList).cursorScrollInsensitive().maxRows(highIndex).distinct().queryIterator()
- } else if (showAll.equalsIgnoreCase('true')) {
- visitListIt =
from('Visit').orderBy(sortList).cursorScrollInsensitive().maxRows(highIndex).distinct().queryIterator()
- } else {
+ visitQuery.where('partyId', partyId)
+ } else if (!showAll.equalsIgnoreCase('true')) {
// show active visits
- visitListIt = from('Visit').where('thruDate',
null).orderBy(sortList).cursorScrollInsensitive().maxRows(highIndex).distinct().queryIterator()
+ visitQuery.where('thruDate', null)
}
-
- // get the partial list for this page
- visitList = visitListIt.getPartialList(lowIndex, viewSize) ?: []
-
- visitListSize = visitListIt.getResultsSizeAfterPartialList()
+ pagedList = visitQuery.queryPagedList(lowIndex, viewSize)
+ visitList = pagedList.getData() ?: []
+ visitListSize = pagedList.getSize()
if (highIndex > visitListSize) {
highIndex = visitListSize
}
@@ -79,7 +74,6 @@ try {
throw e
} finally {
// only commit the transaction if we started one... this will throw an
exception if it fails
- visitListIt.close()
TransactionUtil.commit(beganTransaction)
}
diff --git
a/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/FastLoadCache.groovy
b/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/FastLoadCache.groovy
index 1c96ed01ef..f72572dd1f 100644
---
a/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/FastLoadCache.groovy
+++
b/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/FastLoadCache.groovy
@@ -26,16 +26,16 @@ messageList = []
messageList.add('Loading Categories...')
UtilTimer ctimer = new UtilTimer()
messageList.add(ctimer.timerString('Before category find'))
-categories = from('ProductCategory').queryIterator()
messageList.add(ctimer.timerString('Before load all categories into cache'))
category = null
long numCategories = 0
-while ((category = (GenericValue) categories.next()) != null) {
- delegator.putInPrimaryKeyCache(category.getPrimaryKey(), category)
- numCategories++
+from('ProductCategory').queryIterator().withCloseable { categories ->
+ while ((category = (GenericValue) categories.next()) != null) {
+ delegator.putInPrimaryKeyCache(category.getPrimaryKey(), category)
+ numCategories++
+ }
}
-categories.close()
messageList.add(ctimer.timerString('Finished Categories'))
messageList.add('Loaded ' + numCategories + ' Categories')
@@ -45,15 +45,15 @@ messageList.add(' ')
messageList.add('Loading Products...')
UtilTimer ptimer = new UtilTimer()
messageList.add(ptimer.timerString('Before product find'))
-products = from('Product').queryIterator()
messageList.add(ptimer.timerString('Before load all products into cache'))
product = null
long numProducts = 0
-while ((product = (GenericValue) products.next()) != null) {
- delegator.putInPrimaryKeyCache(product.getPrimaryKey(), product)
- numProducts++
+from('Product').queryIterator().withCloseable { products ->
+ while ((product = (GenericValue) products.next()) != null) {
+ delegator.putInPrimaryKeyCache(product.getPrimaryKey(), product)
+ numProducts++
+ }
}
-products.close()
messageList.add(ptimer.timerString('Finished Products'))
messageList.add('Loaded ' + numProducts + ' products')
diff --git
a/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/feature/EditFeatureCategoryFeatures.groovy
b/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/feature/EditFeatureCategoryFeatures.groovy
index 78bf329805..cd7a60306b 100644
---
a/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/feature/EditFeatureCategoryFeatures.groovy
+++
b/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/feature/EditFeatureCategoryFeatures.groovy
@@ -67,15 +67,14 @@ boolean beganTransaction = false
try {
beganTransaction = TransactionUtil.begin()
- productFeaturesEli = from('ProductFeature')
+ productFeaturesPagedList = from('ProductFeature')
.where('productFeatureCategoryId',
productFeatureCategoryId)
.orderBy('productFeatureTypeId',
'defaultSequenceNum', 'description')
.distinct()
.cursorScrollInsensitive()
.maxRows(highIndex)
- .queryIterator()
- productFeatures = productFeaturesEli.getPartialList(lowIndex + 1,
highIndex - lowIndex)
- productFeaturesEli.close()
+ .queryPagedList(lowIndex + 1, highIndex - lowIndex)
+ productFeatures = productFeaturesPagedList.getData()
} catch (GenericEntityException e) {
String errMsg = 'Failure in operation, rolling back transaction'
logError(e, errMsg)
diff --git
a/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/product/ApplyFeaturesFromCategory.groovy
b/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/product/ApplyFeaturesFromCategory.groovy
index 013b790a80..896858acaf 100644
---
a/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/product/ApplyFeaturesFromCategory.groovy
+++
b/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/product/ApplyFeaturesFromCategory.groovy
@@ -65,15 +65,14 @@ boolean beganTransaction = false
try {
beganTransaction = TransactionUtil.begin()
- productFeaturesEli = from('ProductFeature')
+ productFeaturesPagedList = from('ProductFeature')
.where('productFeatureCategoryId', productFeatureCategoryId)
.orderBy('productFeatureTypeId', 'defaultSequenceNum', 'description')
.distinct()
.cursorScrollInsensitive()
.maxRows(highIndex)
- .queryIterator()
- productFeatures = productFeaturesEli.getPartialList(lowIndex + 1,
highIndex - lowIndex)
- productFeaturesEli.close()
+ .queryPagedList(lowIndex + 1, highIndex - lowIndex)
+ productFeatures = productFeaturesPagedList.getData()
} catch (GenericEntityException e) {
String errMsg = 'Failure in operation, rolling back transaction'
logError(e, errMsg)
diff --git
a/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/facility/CountFacilityInventoryByProduct.groovy
b/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/facility/CountFacilityInventoryByProduct.groovy
index 4a69b65b38..b4cccbcb62 100644
---
a/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/facility/CountFacilityInventoryByProduct.groovy
+++
b/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/facility/CountFacilityInventoryByProduct.groovy
@@ -52,7 +52,6 @@ offsetATP = -1
hasOffsetQOH = false
hasOffsetATP = false
-EntityListIterator prodsEli = null
rows = [] as ArrayList
if (action) {
@@ -228,14 +227,13 @@ if (action) {
beganTransaction = false
List prods = null
- try {
- beganTransaction = TransactionUtil.begin()
-
- // get the indexes for the partial list
- lowIndex = ((viewIndex.intValue() * viewSize.intValue()) + 1)
- highIndex = (viewIndex.intValue() + 1) * viewSize.intValue()
- prodsEli =
from(prodView).where(whereCondition).orderBy(orderBy).cursorScrollInsensitive().maxRows(highIndex).distinct().queryIterator()
+ beganTransaction = TransactionUtil.begin()
+ // get the indexes for the partial list
+ lowIndex = ((viewIndex.intValue() * viewSize.intValue()) + 1)
+ highIndex = (viewIndex.intValue() + 1) * viewSize.intValue()
+ try (EntityListIterator prodsEli =
from(prodView).where(whereCondition).orderBy(orderBy).cursorScrollInsensitive().maxRows(highIndex)
+ .distinct().queryIterator()) {
// get the partial list for this page
prods = prodsEli.getPartialList(lowIndex, highIndex)
prodsIt = prods.iterator()
@@ -268,50 +266,50 @@ if (action) {
if (checkTime) {
// Make a query against the sales usage view entity
- salesUsageIt = from(salesUsageViewEntity)
+ salesUsageQuery = from(salesUsageViewEntity)
.where(EntityCondition.makeCondition('facilityId', EntityOperator.EQUALS,
facilityId),
EntityCondition.makeCondition('productId', EntityOperator.EQUALS,
oneProd.productId),
EntityCondition.makeCondition('statusId', EntityOperator.IN,
['ORDER_COMPLETED',
'ORDER_APPROVED', 'ORDER_HELD']),
EntityCondition.makeCondition('orderTypeId', EntityOperator.EQUALS,
'SALES_ORDER'),
EntityCondition.makeCondition('orderDate',
EntityOperator.GREATER_THAN_EQUAL_TO, checkTime))
- .queryIterator()
// Sum the sales usage quantities found
salesUsageQuantity = 0
- salesUsageIt.each { salesUsageItem ->
- if (salesUsageItem.quantity) {
- try {
- salesUsageQuantity +=
salesUsageItem.getDouble('quantity').doubleValue()
- } catch (Exception e) {
- logError(e, 'Caught an exception : ' + e)
- request.setAttribute('_ERROR_MESSAGE', 'An
exception occured please check the log')
+ salesUsageQuery.queryIterator().withCloseable { salesUsageIt ->
+ while ((salesUsageItem = salesUsageIt.next()) != null) {
+ if (salesUsageItem.quantity) {
+ try {
+ salesUsageQuantity +=
salesUsageItem.getDouble('quantity').doubleValue()
+ } catch (Exception e) {
+ logError(e, 'Caught an exception : ' + e)
+ request.setAttribute('_ERROR_MESSAGE', 'An
exception occured please check the log')
+ }
}
}
}
- salesUsageIt.close()
// Make a query against the production usage view entity
- productionUsageIt = from(productionUsageViewEntity)
+ productionUsageQuery = from(productionUsageViewEntity)
.where(EntityCondition.makeCondition('facilityId', EntityOperator.EQUALS,
facilityId),
EntityCondition.makeCondition('productId', EntityOperator.EQUALS,
oneProd.productId),
EntityCondition.makeCondition('workEffortTypeId', EntityOperator.EQUALS,
'PROD_ORDER_TASK'),
EntityCondition.makeCondition('actualCompletionDate',
EntityOperator.GREATER_THAN_EQUAL_TO, checkTime))
- .queryIterator()
// Sum the production usage quantities found
productionUsageQuantity = 0
- productionUsageIt.each { productionUsageItem ->
- if (productionUsageItem.quantity) {
- try {
- productionUsageQuantity +=
productionUsageItem.getDouble('quantity').doubleValue()
- } catch (Exception e) {
- logError(e, 'Caught an exception : ' + e)
- request.setAttribute('_ERROR_MESSAGE', 'An
exception occured please check the log')
+ productionUsageQuery.queryIterator().withCloseable {
productionUsageIt ->
+ while ((productionUsageItem = productionUsageIt.next()) !=
null) {
+ if (productionUsageItem.quantity) {
+ try {
+ productionUsageQuantity +=
productionUsageItem.getDouble('quantity').doubleValue()
+ } catch (Exception e) {
+ logError(e, 'Caught an exception : ' + e)
+ request.setAttribute('_ERROR_MESSAGE', 'An
exception occured please check the log')
+ }
}
}
}
- productionUsageIt.close()
oneInventory.usageQuantity = salesUsageQuantity +
productionUsageQuantity
}
rows.add(oneInventory)
@@ -342,7 +340,6 @@ if (action) {
productListSize = prodsEli.getResultsSizeAfterPartialList()
}
}
- prodsEli.close()
if (highIndex > productListSize) {
highIndex = productListSize
}
@@ -361,13 +358,6 @@ if (action) {
// after rolling back, rethrow the exception
throw e
} finally {
- if (prodsEli != null) {
- try {
- prodsEli.close()
- } catch (Exception exc) {
- logError(exc, module)
- }
- }
// only commit the transaction if we started one... this will throw an
exception if it fails
TransactionUtil.commit(beganTransaction)
}
diff --git
a/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/facility/FindInventoryItemsByLabels.groovy
b/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/facility/FindInventoryItemsByLabels.groovy
index 8c3a7d676f..ee3286ab75 100644
---
a/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/facility/FindInventoryItemsByLabels.groovy
+++
b/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/facility/FindInventoryItemsByLabels.groovy
@@ -24,7 +24,6 @@ import org.apache.ofbiz.entity.condition.EntityOperator
import org.apache.ofbiz.entity.model.DynamicViewEntity
import org.apache.ofbiz.entity.model.ModelKeyMap
import org.apache.ofbiz.entity.transaction.TransactionUtil
-import org.apache.ofbiz.entity.util.EntityListIterator
facilityId = parameters.facilityId
@@ -54,7 +53,6 @@ for (int i = 1; i <= numberOfFields; i++) {
andCondition.add(EntityCondition.makeCondition('inventoryItemLabelId'
+ i, EntityOperator.EQUALS, inventoryItemLabelId))
}
}
-EntityListIterator inventoryItemsEli = null
beganTransaction = false
List inventoryItems = null
if (andCondition.size() > 1) {
@@ -64,25 +62,20 @@ if (andCondition.size() > 1) {
highIndex = (viewIndex - 1) * viewSize
beganTransaction = TransactionUtil.begin()
- inventoryItemsEli = from(inventoryItemAndLabelsView)
-
.where(andCondition).cursorScrollInsensitive().distinct().maxRows(highIndex).queryIterator()
+ inventoryItemsPagedList = from(inventoryItemAndLabelsView)
+
.where(andCondition).cursorScrollInsensitive().distinct().maxRows(highIndex).queryPagedList(lowIndex,
viewSize)
- inventoryItemsSize = inventoryItemsEli.getResultsSizeAfterPartialList()
+ inventoryItemsSize = inventoryItemsPagedList.getSize()
context.inventoryItemsSize = inventoryItemsSize
if (highIndex > inventoryItemsSize) {
highIndex = inventoryItemsSize
}
- // get the partial list for this page
- inventoryItemsEli.beforeFirst()
if (inventoryItemsSize > 0) {
- inventoryItems = inventoryItemsEli.getPartialList(lowIndex,
viewSize)
+ inventoryItems = inventoryItemsPagedList.getData()
} else {
inventoryItems = [] as ArrayList
}
-
- // close the list iterator
- inventoryItemsEli.close()
} catch (GenericEntityException e) {
errMsg = 'Failure in operation, rolling back transaction'
logError(e, errMsg)
diff --git
a/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/facility/ViewFacilityInventoryByProduct.groovy
b/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/facility/ViewFacilityInventoryByProduct.groovy
index 121cd21eb0..22222ae2b3 100644
---
a/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/facility/ViewFacilityInventoryByProduct.groovy
+++
b/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/facility/ViewFacilityInventoryByProduct.groovy
@@ -142,10 +142,10 @@ if (action) {
List prods = null
try {
beganTransaction = TransactionUtil.begin()
- prodsEli =
from(prodView).where(whereCondition).orderBy('productId').cursorScrollInsensitive().distinct().queryIterator()
- prods = prodsEli.getPartialList(lowIndex, highIndex)
- listSize = prodsEli.getResultsSizeAfterPartialList()
- prodsEli.close()
+ prodsPagedList =
from(prodView).where(whereCondition).orderBy('productId').cursorScrollInsensitive()
+ .distinct().queryPagedList(lowIndex, highIndex)
+ prods = prodsPagedList.getData()
+ listSize = prodsPagedList.getSize()
} catch (GenericEntityException e) {
errMsg = 'Failure in operation, rolling back transaction'
logError(e, errMsg)
diff --git
a/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/inventory/InventoryItemTotals.groovy
b/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/inventory/InventoryItemTotals.groovy
index 36e263b311..09e630d69e 100644
---
a/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/inventory/InventoryItemTotals.groovy
+++
b/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/inventory/InventoryItemTotals.groovy
@@ -22,6 +22,7 @@ import org.apache.ofbiz.entity.GenericEntityException
import org.apache.ofbiz.entity.condition.EntityCondition
import org.apache.ofbiz.entity.condition.EntityOperator
import org.apache.ofbiz.entity.transaction.TransactionUtil
+import org.apache.ofbiz.entity.util.EntityListIterator
action = request.getParameter('action')
@@ -38,9 +39,8 @@ if (action) {
conditions = [EntityCondition.makeCondition('statusId',
EntityOperator.NOT_EQUAL, 'INV_DELIVERED')]
conditions.add(EntityCondition.makeCondition('statusId',
EntityOperator.EQUALS, null))
conditionList = EntityCondition.makeCondition(conditions,
EntityOperator.OR)
- try {
- beganTransaction = TransactionUtil.begin()
- invItemListItr =
from('InventoryItem').where(conditionList).orderBy('productId').queryIterator()
+ beganTransaction = TransactionUtil.begin()
+ try (EntityListIterator invItemListItr =
from('InventoryItem').where(conditionList).orderBy('productId').queryIterator())
{
while ((inventoryItem = invItemListItr.next()) != null) {
productId = inventoryItem.productId
product = from('Product').where('productId', productId).queryOne()
@@ -86,7 +86,6 @@ if (action) {
inventoryItemTotals.add(resultMap)
}
}
- invItemListItr.close()
} catch (GenericEntityException e) {
errMsg = 'Failure in operation, rolling back transaction'
logError(e, errMsg)