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 9fd008f208 Replace EntityListIterator.hasNext() with next()-based
iteration for performance (#1163)
9fd008f208 is described below
commit 9fd008f208f8137604351dee356b37219fca510b
Author: Deepak Dixit <[email protected]>
AuthorDate: Tue May 5 18:23:31 2026 +0530
Replace EntityListIterator.hasNext() with next()-based iteration for
performance (#1163)
Improved: Updated iteration logic to avoid using
EntityListIterator.hasNext(), which is inefficient due to JDBC ResultSet
behavior.
- Replaced hasNext() checks with next() != null pattern
- Aligned with recommended usage in EntityListIterator JavaDoc
- Prevented unnecessary ResultSet cursor operations and warning logs
- Improved iteration performance and reduced overhead
Example:
while ((value = iterator.next()) != null) { ... }
---
.../accounting/reports/SalesInvoiceByProductCategorySummary.groovy | 6 ++----
.../groovy/org/apache/ofbiz/order/entry/StorePaymentOptions.groovy | 3 +--
.../groovy/org/apache/ofbiz/product/catalog/FastLoadCache.groovy | 6 ++----
.../facility/facility/CountFacilityInventoryByProduct.groovy | 3 +--
.../org/apache/ofbiz/product/facility/shipment/PackingSlip.groovy | 3 +--
.../main/groovy/org/apache/ofbiz/webtools/entity/XmlDsDump.groovy | 6 ++----
6 files changed, 9 insertions(+), 18 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 0bcb833f37..2bcd1a606f 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
@@ -120,8 +120,7 @@ for (int currentDay = 0; currentDay <= daysInMonth;
currentDay++) {
productResultListIterator = select('productId', 'quantityTotal',
'amountTotal')
.from('InvoiceItemProductSummary').where(productAndExprs).cursorScrollInsensitive().cache(true).queryIterator()
productResultMap = [:]
- while (productResultListIterator.hasNext()) {
- productResult = productResultListIterator.next()
+ while ((productResult = productResultListIterator.next()) != null) {
productResultMap[productResult.productId] = productResult
monthProductResult = UtilMisc.getMapFromMap(monthProductResultMap,
productResult.productId)
UtilMisc.addToBigDecimalInMap(monthProductResult, 'quantityTotal',
productResult.getBigDecimal('quantityTotal'))
@@ -139,8 +138,7 @@ for (int currentDay = 0; currentDay <= daysInMonth;
currentDay++) {
categoryResultListIterator = select('productCategoryId', 'quantityTotal',
'amountTotal')
.from('InvoiceItemCategorySummary').where(categoryAndExprs).cursorScrollInsensitive().cache(true).queryIterator()
categoryResultMap = [:]
- while (categoryResultListIterator.hasNext()) {
- categoryResult = categoryResultListIterator.next()
+ while ((categoryResult = categoryResultListIterator.next()) != null) {
categoryResultMap[categoryResult.productCategoryId] = categoryResult
monthCategoryResult = UtilMisc.getMapFromMap(monthCategoryResultMap,
categoryResult.productCategoryId)
UtilMisc.addToBigDecimalInMap(monthCategoryResult, 'quantityTotal',
categoryResult.getBigDecimal('quantityTotal'))
diff --git
a/applications/order/src/main/groovy/org/apache/ofbiz/order/entry/StorePaymentOptions.groovy
b/applications/order/src/main/groovy/org/apache/ofbiz/order/entry/StorePaymentOptions.groovy
index ab3c0f4f3d..e8d9f0033b 100644
---
a/applications/order/src/main/groovy/org/apache/ofbiz/order/entry/StorePaymentOptions.groovy
+++
b/applications/order/src/main/groovy/org/apache/ofbiz/order/entry/StorePaymentOptions.groovy
@@ -25,8 +25,7 @@ productStore = ProductStoreWorker.getProductStore(request)
productStorePaymentMethodTypeIdMap = [:]
productStorePaymentSettingList =
productStore.getRelated('ProductStorePaymentSetting', null, null, true)
productStorePaymentSettingIter = productStorePaymentSettingList.iterator()
-while (productStorePaymentSettingIter.hasNext()) {
- productStorePaymentSetting = productStorePaymentSettingIter.next()
+while ((productStorePaymentSetting = productStorePaymentSettingIter.next()) !=
null) {
productStorePaymentMethodTypeIdMap.put(productStorePaymentSetting.get('paymentMethodTypeId'),
true)
}
context.put('productStorePaymentMethodTypeIdMap',
productStorePaymentMethodTypeIdMap)
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 7c37690421..1c96ed01ef 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
@@ -31,8 +31,7 @@ messageList.add(ctimer.timerString('Before load all
categories into cache'))
category = null
long numCategories = 0
-while (categories.hasNext()) {
- category = (GenericValue) categories.next()
+while ((category = (GenericValue) categories.next()) != null) {
delegator.putInPrimaryKeyCache(category.getPrimaryKey(), category)
numCategories++
}
@@ -50,8 +49,7 @@ products = from('Product').queryIterator()
messageList.add(ptimer.timerString('Before load all products into cache'))
product = null
long numProducts = 0
-while (products.hasNext()) {
- product = (GenericValue) products.next()
+while ((product = (GenericValue) products.next()) != null) {
delegator.putInPrimaryKeyCache(product.getPrimaryKey(), product)
numProducts++
}
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 5d79186284..4a69b65b38 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
@@ -322,8 +322,7 @@ if (action) {
// attempt to get the full size
if (hasOffsetQOH || hasOffsetATP) {
rowProcessed = 0
- while (prodsEli.hasNext()) {
- nextValue = prodsEli.next()
+ while ((nextValue = prodsEli.next()) != null) {
offsetQOHQtyAvailable =
nextValue.getDouble('offsetQOHQtyAvailable')
offsetATPQtyAvailable =
nextValue.getDouble('offsetATPQtyAvailable')
if (hasOffsetATP) {
diff --git
a/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/shipment/PackingSlip.groovy
b/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/shipment/PackingSlip.groovy
index 88c692c4f4..5a8caa4d33 100644
---
a/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/shipment/PackingSlip.groovy
+++
b/applications/product/src/main/groovy/org/apache/ofbiz/product/facility/shipment/PackingSlip.groovy
@@ -59,8 +59,7 @@ previousShipmentIter = from('Shipment')
EntityOperator.AND))
.queryIterator()
-while (previousShipmentIter.hasNext()) {
- previousShipmentItem = previousShipmentIter.next()
+while ((previousShipmentItem = previousShipmentIter.next()) != null) {
if (previousShipmentItem.shipmentId != shipment.shipmentId) {
previousShipmentItems =
previousShipmentItem.getRelated('ShipmentItem', null, null, false)
previousShipmentItems.each { shipmentItem ->
diff --git
a/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/XmlDsDump.groovy
b/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/XmlDsDump.groovy
index a11e903cb8..59d8367fe8 100644
---
a/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/XmlDsDump.groovy
+++
b/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/XmlDsDump.groovy
@@ -220,8 +220,7 @@ if (passedEntityNames) {
}
curNumberWritten = 0
- while (values.hasNext()) {
- value = values.next()
+ while ((value = values.next()) != null) {
value.writeXmlText(writer, '')
numberWritten++
curNumberWritten++
@@ -277,8 +276,7 @@ if (passedEntityNames) {
isFirst = true
writer = null
fileSplitNumber = 1
- while (values.hasNext()) {
- value = values.next()
+ while ((value = values.next()) != null) {
//Don't bother writing the file if there's nothing
//to put into it
if (isFirst) {