Author: jleroux
Date: Tue Mar 21 12:20:55 2017 New Revision: 1787949 URL: http://svn.apache.org/viewvc?rev=1787949&view=rev Log: No functional changes, replace finally blocks closing EntityListIterator by try-with-resource, and refactors around Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentSearch.java ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppinglist/ShoppingListServices.java ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/shipment/shipment/ShipmentServices.java ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataServices.java Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentSearch.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentSearch.java?rev=1787949&r1=1787948&r2=1787949&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentSearch.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentSearch.java Tue Mar 21 12:20:55 2017 @@ -168,14 +168,11 @@ public class ContentSearch { long startMillis = System.currentTimeMillis(); // do the query - EntityListIterator eli = this.doQuery(delegator); - ArrayList<String> contentIds = this.makeContentIdList(eli); - if (eli != null) { - try { - eli.close(); - } catch (GenericEntityException e) { - Debug.logError(e, "Error closing ContentSearch EntityListIterator"); - } + ArrayList<String> contentIds = null; + try (EntityListIterator eli = this.doQuery(delegator)) { + contentIds = this.makeContentIdList(eli); + } catch (GenericEntityException e) { + Debug.logError(e, "Error closing ContentSearch EntityListIterator"); } long endMillis = System.currentTimeMillis(); Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java?rev=1787949&r1=1787948&r2=1787949&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java Tue Mar 21 12:20:55 2017 @@ -1503,43 +1503,36 @@ public class OrderServices { cond = EntityCondition.makeCondition(exprs, EntityOperator.OR); } - EntityListIterator eli = null; - try { - eli = EntityQuery.use(delegator).select("orderId").from("OrderHeader").where(cond).queryIterator(); - } catch (GenericEntityException e) { - Debug.logError(e, module); - return ServiceUtil.returnError(e.getMessage()); - } - - if (eli != null) { - // reset each order - GenericValue orderHeader = null; - while ((orderHeader = eli.next()) != null) { - String orderId = orderHeader.getString("orderId"); - Map<String, Object> resetResult = null; - try { - resetResult = dispatcher.runSync("resetGrandTotal", UtilMisc.<String, Object>toMap("orderId", orderId, "userLogin", userLogin)); - } catch (GenericServiceException e) { - Debug.logError(e, "ERROR: Cannot reset order totals - " + orderId, module); - } - - if (resetResult != null && ServiceUtil.isError(resetResult)) { - Debug.logWarning(UtilProperties.getMessage(resource_error, - "OrderErrorCannotResetOrderTotals", - UtilMisc.toMap("orderId",orderId,"resetResult",ServiceUtil.getErrorMessage(resetResult)), locale), module); - } - } + try (EntityListIterator eli = EntityQuery.use(delegator) + .select("orderId") + .from("OrderHeader") + .where(cond) + .queryIterator()) { + + if (eli != null) { + // reset each order + GenericValue orderHeader = null; + while ((orderHeader = eli.next()) != null) { + String orderId = orderHeader.getString("orderId"); + Map<String, Object> resetResult = null; + try { + resetResult = dispatcher.runSync("resetGrandTotal", UtilMisc.<String, Object>toMap("orderId", orderId, "userLogin", userLogin)); + } catch (GenericServiceException e) { + Debug.logError(e, "ERROR: Cannot reset order totals - " + orderId, module); + } - // close the ELI - try { - eli.close(); - } catch (GenericEntityException e) { - Debug.logError(e, module); + if (resetResult != null && ServiceUtil.isError(resetResult)) { + Debug.logWarning(UtilProperties.getMessage(resource_error, + "OrderErrorCannotResetOrderTotals", + UtilMisc.toMap("orderId",orderId,"resetResult",ServiceUtil.getErrorMessage(resetResult)), locale), module); + } else { + Debug.logInfo("No orders found for reset processing", module); + } + } } - } else { - Debug.logInfo("No orders found for reset processing", module); + } catch (GenericEntityException e) { + Debug.logError(e, module); } - return ServiceUtil.returnSuccess(); } @@ -1955,7 +1948,7 @@ public class OrderServices { } } } catch (GenericEntityException e) { - String errMsg = UtilProperties.getMessage(resource_error, "OrderDatabaseErrorCheckingIfWeShouldChangeOrderHeaderStatusToApproved", UtilMisc.toMap("errorString", e.toString()), locale); + String errMsg = UtilProperties.getMessage(resource_error, "OrderDatabaseErrorCheckingIfWeShouldChangeOrderHeaderStatusToApproved", UtilMisc.toMap("errorString", e.toString()), locale); Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); } @@ -2014,11 +2007,11 @@ public class OrderServices { Map<String, String> itemCommentMap = UtilGenerics.checkMap(context.get("itemCommentMap")); Map<String, String> itemQuantityMap = UtilGenerics.checkMap(context.get("itemQtyMap")); if ((cancelQuantity == null) && UtilValidate.isNotEmpty(itemQuantityMap)) { - String key = orderItemSeqId+":"+shipGroupSeqId; - if (UtilValidate.isNotEmpty(itemQuantityMap.get(key))) { - cancelQuantity = new BigDecimal(itemQuantityMap.get(key)); - } - + String key = orderItemSeqId+":"+shipGroupSeqId; + if (UtilValidate.isNotEmpty(itemQuantityMap.get(key))) { + cancelQuantity = new BigDecimal(itemQuantityMap.get(key)); + } + } // debugging message info String itemMsgInfo = orderId + " / " + orderItemSeqId + " / " + shipGroupSeqId; @@ -2119,7 +2112,7 @@ public class OrderServices { "orderItemSeqId", orderItem.getString("orderItemSeqId"), "shipGroupSeqId", orderItemShipGroupAssoc.getString("shipGroupSeqId")); if (availableQuantity.compareTo(thisCancelQty) == 0) { - try { + try { dispatcher.runSync("deleteOrderItemShipGroupAssoc", localCtx); } catch (GenericServiceException e) { Debug.logError(e, module); @@ -5569,15 +5562,15 @@ public class OrderServices { Map<String, Object> result = null; boolean beganTransaction = false; - try { + List<EntityExpr> exprs = UtilMisc.toList(EntityCondition.makeCondition("automaticExtend", EntityOperator.EQUALS, "Y"), + EntityCondition.makeCondition("orderId", EntityOperator.NOT_EQUAL, null), + EntityCondition.makeCondition("productId", EntityOperator.NOT_EQUAL, null)); + try (EntityListIterator eli = EntityQuery.use(delegator) + .from("Subscription") + .where(exprs) + .queryIterator()) { + beganTransaction = TransactionUtil.begin(); - - List<EntityExpr> exprs = UtilMisc.toList(EntityCondition.makeCondition("automaticExtend", EntityOperator.EQUALS, "Y"), - EntityCondition.makeCondition("orderId", EntityOperator.NOT_EQUAL, null), - EntityCondition.makeCondition("productId", EntityOperator.NOT_EQUAL, null)); - EntityListIterator eli = null; - eli = EntityQuery.use(delegator).from("Subscription").where(exprs).queryIterator(); - if (eli != null) { GenericValue subscription; while (((subscription = eli.next()) != null)) { @@ -5655,7 +5648,6 @@ public class OrderServices { count++; } } - eli.close(); } } catch (GenericServiceException e) { @@ -6202,17 +6194,17 @@ public class OrderServices { @Override public List<String> call() throws Exception { List<String> orderIds = new LinkedList<String>(); - EntityListIterator eli = null; - try { - eli = EntityQuery.use(delegator).select("orderId").from("OrderHeader").where(cond).orderBy("entryDate ASC").queryIterator(); + try (EntityListIterator eli = EntityQuery.use(delegator) + .select("orderId") + .from("OrderHeader") + .where(cond) + .orderBy("entryDate ASC") + .queryIterator()){ + GenericValue orderHeader; while ((orderHeader = eli.next()) != null) { orderIds.add(orderHeader.getString("orderId")); } - } finally { - if (eli != null) { - eli.close(); - } } return orderIds; } Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppinglist/ShoppingListServices.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppinglist/ShoppingListServices.java?rev=1787949&r1=1787948&r2=1787949&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppinglist/ShoppingListServices.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppinglist/ShoppingListServices.java Tue Mar 21 12:20:55 2017 @@ -125,12 +125,13 @@ public class ShoppingListServices { Locale locale = (Locale) context.get("locale"); boolean beganTransaction = false; - try { - beganTransaction = TransactionUtil.begin(); - - EntityListIterator eli = null; - eli = EntityQuery.use(delegator).from("ShoppingList").where("shoppingListTypeId", "SLT_AUTO_REODR", "isActive", "Y").orderBy("-lastOrderedDate").queryIterator(); + try (EntityListIterator eli = EntityQuery.use(delegator) + .from("ShoppingList") + .where("shoppingListTypeId", "SLT_AUTO_REODR", "isActive", "Y") + .orderBy("-lastOrderedDate") + .queryIterator()) { + beganTransaction = TransactionUtil.begin(); if (eli != null) { GenericValue shoppingList; while (((shoppingList = eli.next()) != null)) { @@ -197,8 +198,6 @@ public class ShoppingListServices { recurrence.incrementCurrentCount(); } } - - eli.close(); } return ServiceUtil.returnSuccess(); Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java?rev=1787949&r1=1787948&r2=1787949&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java Tue Mar 21 12:20:55 2017 @@ -1229,33 +1229,26 @@ public class ProductSearchSession { dynamicViewEntity.addViewLink("PFAC", "PFC", Boolean.FALSE, ModelKeyMap.makeKeyMapList("productFeatureId")); entityConditionList.add(EntityCondition.makeCondition("pfcProductFeatureTypeId", EntityOperator.EQUALS, productFeatureTypeId)); - EntityListIterator eli = null; - try { - eli = EntityQuery.use(delegator) + List<Map<String, String>> featureCountList = null; + try (EntityListIterator eli = EntityQuery.use(delegator) .select(UtilMisc.toSet("pfacProductFeatureId", "featureCount", "pfcDescription", "pfcProductFeatureTypeId")) .from(dynamicViewEntity) .where(entityConditionList) .orderBy(productSearchContext.orderByList) .cursorScrollInsensitive() - .queryIterator(); + .queryIterator()) { + + featureCountList = new LinkedList<Map<String,String>>(); + GenericValue searchResult = null; + while ((searchResult = eli.next()) != null) { + featureCountList.add(UtilMisc.<String, String>toMap("productFeatureId", (String) searchResult.get("pfacProductFeatureId"), "productFeatureTypeId", (String) searchResult.get("pfcProductFeatureTypeId"), "description", (String) searchResult.get("pfcDescription"), "featureCount", Long.toString((Long) searchResult.get("featureCount")))); + } } catch (GenericEntityException e) { Debug.logError(e, "Error in product search", module); return null; } - List<Map<String, String>> featureCountList = new LinkedList<Map<String,String>>(); - GenericValue searchResult = null; - while ((searchResult = eli.next()) != null) { - featureCountList.add(UtilMisc.<String, String>toMap("productFeatureId", (String) searchResult.get("pfacProductFeatureId"), "productFeatureTypeId", (String) searchResult.get("pfcProductFeatureTypeId"), "description", (String) searchResult.get("pfcDescription"), "featureCount", Long.toString((Long) searchResult.get("featureCount")))); - } - if (eli != null) { - try { - eli.close(); - } catch (GenericEntityException e) { - Debug.logError(e, "Error closing ProductSearch EntityListIterator"); - } - } return featureCountList; } @@ -1308,31 +1301,21 @@ public class ProductSearchSession { entityConditionList.add(EntityCondition.makeCondition("ppcPrice", EntityOperator.LESS_THAN_EQUAL_TO, priceHigh)); entityConditionList.add(EntityCondition.makeCondition("ppcProductPriceTypeId", EntityOperator.EQUALS, "LIST_PRICE")); - EntityListIterator eli = null; - try { - eli = EntityQuery.use(delegator).select(UtilMisc.toSet(fieldsToSelect)) - .from(dynamicViewEntity) - .where(entityConditionList) - .orderBy(productSearchContext.orderByList) - .cursorScrollInsensitive() - .queryIterator(); - } catch (GenericEntityException e) { - Debug.logError(e, "Error in product search", module); - return 0; - } - - GenericValue searchResult = null; Long priceRangeCount = Long.valueOf(0); - while ((searchResult = eli.next()) != null) { - priceRangeCount = searchResult.getLong("priceRangeCount"); - } - - if (eli != null) { - try { - eli.close(); - } catch (GenericEntityException e) { - Debug.logError(e, "Error closing ProductSearch EntityListIterator"); + try (EntityListIterator eli = EntityQuery.use(delegator) + .select(UtilMisc.toSet(fieldsToSelect)) + .from(dynamicViewEntity) + .where(entityConditionList) + .orderBy(productSearchContext.orderByList) + .cursorScrollInsensitive() + .queryIterator()) { + + GenericValue searchResult = null; + while ((searchResult = eli.next()) != null) { + priceRangeCount = searchResult.getLong("priceRangeCount"); } + } catch (GenericEntityException e) { + Debug.logError(e, "Error in product search", module); } return priceRangeCount; } @@ -1374,31 +1357,21 @@ public class ProductSearchSession { ProductSearch.getAllSubCategoryIds(productCategoryId, productCategoryIdSet, delegator, productSearchContext.nowTimestamp); entityConditionList.add(EntityCondition.makeCondition("pcmcProductCategoryId", EntityOperator.IN, productCategoryIdSet)); - EntityListIterator eli = null; - try { - eli = EntityQuery.use(delegator).select(UtilMisc.toSet(fieldsToSelect)) - .from(dynamicViewEntity) - .where(entityConditionList) - .orderBy(productSearchContext.orderByList) - .cursorScrollInsensitive() - .queryIterator(); - } catch (GenericEntityException e) { - Debug.logError(e, "Error in product search", module); - return 0; - } - - GenericValue searchResult = null; Long categoryCount = Long.valueOf(0); - while ((searchResult = eli.next()) != null) { - categoryCount = searchResult.getLong("categoryCount"); - } - - if (eli != null) { - try { - eli.close(); - } catch (GenericEntityException e) { - Debug.logError(e, "Error closing ProductSearch EntityListIterator"); + try (EntityListIterator eli = EntityQuery.use(delegator) + .select(UtilMisc.toSet(fieldsToSelect)) + .from(dynamicViewEntity) + .where(entityConditionList) + .orderBy(productSearchContext.orderByList) + .cursorScrollInsensitive() + .queryIterator()) { + + GenericValue searchResult = null; + while ((searchResult = eli.next()) != null) { + categoryCount = searchResult.getLong("categoryCount"); } + } catch (GenericEntityException e) { + Debug.logError(e, "Error in product search", module); } return categoryCount; } Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/shipment/shipment/ShipmentServices.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/shipment/shipment/ShipmentServices.java?rev=1787949&r1=1787948&r2=1787949&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/shipment/shipment/ShipmentServices.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/shipment/shipment/ShipmentServices.java Tue Mar 21 12:20:55 2017 @@ -670,9 +670,11 @@ public class ShipmentServices { Locale locale = (Locale) context.get("locale"); Map<String, String> shipmentMap = new HashMap<String, String>(); - EntityListIterator eli = null; - try { - eli = EntityQuery.use(delegator).from("OdbcPackageIn").orderBy("shipmentId", "shipmentPackageSeqId", "voidIndicator").queryIterator(); + try (EntityListIterator eli = EntityQuery.use(delegator) + .from("OdbcPackageIn") + .orderBy("shipmentId", "shipmentPackageSeqId", "voidIndicator") + .queryIterator()) { + GenericValue pkgInfo; while ((pkgInfo = eli.next()) != null) { String packageSeqId = pkgInfo.getString("shipmentPackageSeqId"); @@ -779,14 +781,6 @@ public class ShipmentServices { } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); - } finally { - if (eli != null) { - try { - eli.close(); - } catch (GenericEntityException e) { - Debug.logError(e, module); - } - } } // update the status of each shipment Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java?rev=1787949&r1=1787948&r2=1787949&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java Tue Mar 21 12:20:55 2017 @@ -1581,17 +1581,9 @@ public class GenericDelegator implements beganTransaction = TransactionUtil.begin(); } - EntityListIterator eli = null; List<GenericValue> list = null; - try { - eli = this.find(entityName, entityCondition, null, fieldsToSelect, orderBy, findOptions); + try (EntityListIterator eli = this.find(entityName, entityCondition, null, fieldsToSelect, orderBy, findOptions)) { list = eli.getCompleteList(); - } finally { - if (eli != null) { - try { - eli.close(); - } catch (Exception exc) {} - } } if (useCache) { Modified: ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataServices.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataServices.java?rev=1787949&r1=1787948&r2=1787949&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataServices.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataServices.java Tue Mar 21 12:20:55 2017 @@ -32,7 +32,6 @@ import java.util.Locale; import java.util.Map; import org.apache.commons.codec.binary.Base64; -import org.apache.shiro.crypto.AesCipherService; import org.apache.ofbiz.base.crypto.DesCrypt; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.FileUtil; @@ -55,6 +54,7 @@ import org.apache.ofbiz.service.Dispatch import org.apache.ofbiz.service.GenericServiceException; import org.apache.ofbiz.service.LocalDispatcher; import org.apache.ofbiz.service.ServiceUtil; +import org.apache.shiro.crypto.AesCipherService; /** * Entity Data Import/Export Services @@ -422,9 +422,10 @@ public class EntityDataServices { String entityName = (String) context.get("entityName"); String fieldName = (String) context.get("fieldName"); Locale locale = (Locale) context.get("locale"); - EntityListIterator eli = null; - try { - eli = EntityQuery.use(delegator).from(entityName).queryIterator(); + try (EntityListIterator eli = EntityQuery.use(delegator) + .from(entityName) + .queryIterator()) { + GenericValue currentValue; while ((currentValue = eli.next()) != null) { byte[] bytes = currentValue.getBytes(fieldName); @@ -436,15 +437,6 @@ public class EntityDataServices { } catch (GenericEntityException e) { Debug.logError(e, "Error unwrapping ByteWrapper records: " + e.toString(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EntityExtErrorUnwrappingRecords", UtilMisc.toMap("errorString", e.toString()), locale)); - } finally { - if (eli != null) { - try { - eli.close(); - } catch (GenericEntityException e) { - String errMsg = "Error closing EntityListIterator: " + e.toString(); - Debug.logError(e, errMsg, module); - } - } } return ServiceUtil.returnSuccess(); |
Free forum by Nabble | Edit this page |