svn commit: r1797097 - in /ofbiz/ofbiz-framework/trunk: applications/product/src/main/java/org/apache/ofbiz/product/product/ framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ framework/service/src/main/java/org/apache/ofbiz/service/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1797097 - in /ofbiz/ofbiz-framework/trunk: applications/product/src/main/java/org/apache/ofbiz/product/product/ framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ framework/service/src/main/java/org/apache/ofbiz/service/

jleroux@apache.org
Author: jleroux
Date: Wed May 31 18:43:05 2017
New Revision: 1797097

URL: http://svn.apache.org/viewvc?rev=1797097&view=rev
Log:
No functional changes.

Replaces entityListIterator.close() in finally by try-with-ressource

Modified:
    ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductEvents.java
    ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ListFinder.java
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java

Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductEvents.java?rev=1797097&r1=1797096&r2=1797097&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductEvents.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductEvents.java Wed May 31 18:43:05 2017
@@ -109,12 +109,11 @@ public class ProductEvents {
         }
 
 
-        EntityListIterator entityListIterator = null;
         int numProds = 0;
         int errProds = 0;
 
         boolean beganTx = false;
-        try {
+        try (EntityListIterator  entityListIterator = EntityQuery.use(delegator).from("Product").where(condition).queryIterator()) {
             // begin the transaction
             beganTx = TransactionUtil.begin(7200);
             try {
@@ -122,7 +121,6 @@ public class ProductEvents {
                     long count = EntityQuery.use(delegator).from("Product").where(condition).queryCount();
                     Debug.logInfo("========== Found " + count + " products to index ==========", module);
                 }
-                entityListIterator = EntityQuery.use(delegator).from("Product").where(condition).queryIterator();
             } catch (GenericEntityException gee) {
                 Debug.logWarning(gee, gee.getMessage(), module);
                 Map<String, String> messageMap = UtilMisc.toMap("gee", gee.toString());
@@ -160,21 +158,12 @@ public class ProductEvents {
                 Debug.logError(e2, module);
             }
             return "error";
-        } finally {
-            if (entityListIterator != null) {
-                try {
-                    entityListIterator.close();
-                } catch (GenericEntityException gee) {
-                    Debug.logError(gee, "Error closing EntityListIterator when indexing product keywords.", module);
-                }
-            }
-
-            // commit the transaction
-            try {
-                TransactionUtil.commit(beganTx);
-            } catch (GenericTransactionException e) {
-                Debug.logError(e, module);
-            }
+        }
+        // commit the transaction
+        try {
+            TransactionUtil.commit(beganTx);
+        } catch (GenericTransactionException e) {
+            Debug.logError(e, module);
         }
 
         if (errProds == 0) {

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=1797097&r1=1797096&r2=1797097&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 Wed May 31 18:43:05 2017
@@ -924,16 +924,16 @@ public class ProductSearchSession {
                 addOnTopProdCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, now)));
                 addOnTopProdCondList.add(EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN, now));
                 addOnTopProdCondList.add(EntityCondition.makeCondition("productCategoryId", EntityOperator.EQUALS, addOnTopProdCategoryId));
-                EntityListIterator pli = null;
-                try {
-                    pli = EntityQuery.use(delegator).select(UtilMisc.toSet("productId", "sequenceNum"))
-                            .from("ProductCategoryMember")
-                            .where(addOnTopProdCondList)
-                            .orderBy("sequenceNum")
-                            .cursorScrollInsensitive()
-                            .distinct()
-                            .maxRows(highIndex)
-                            .queryIterator();
+                EntityQuery eq = EntityQuery.use(delegator)
+                        .select(UtilMisc.toSet("productId", "sequenceNum"))
+                        .from("ProductCategoryMember")
+                        .where(addOnTopProdCondList)
+                        .orderBy("sequenceNum")
+                        .cursorScrollInsensitive()
+                        .distinct()
+                        .maxRows(highIndex);
+                
+                try (EntityListIterator pli = eq.queryIterator()) {
                     addOnTopProductCategoryMembers = pli.getPartialList(lowIndex, viewSize);
                     addOnTopListSize = addOnTopProductCategoryMembers.size();
                     for (GenericValue alwaysAddProductCategoryMember: addOnTopProductCategoryMembers) {
@@ -943,14 +943,6 @@ public class ProductSearchSession {
                     listSize = listSize + addOnTopTotalListSize;
                 } catch (GenericEntityException e) {
                     Debug.logError(e, module);
-                } finally {
-                    if (pli != null) {
-                        try {
-                            pli.close();
-                        } catch (GenericEntityException e) {
-                            Debug.logError(e, module);
-                        }
-                    }
                 }
             }
 

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ListFinder.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ListFinder.java?rev=1797097&r1=1797096&r2=1797097&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ListFinder.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ListFinder.java Wed May 31 18:43:05 2017
@@ -207,12 +207,10 @@ public abstract class ListFinder extends
                     options.setMaxRows(size * (index + 1));
                 }
                 boolean beganTransaction = false;
-                try {
+                try (EntityListIterator eli = delegator.find(entityName, whereEntityCondition, havingEntityCondition, fieldsToSelect, orderByFields, options)) {
                     if (useTransaction) {
                         beganTransaction = TransactionUtil.begin();
                     }
-
-                    EntityListIterator eli = delegator.find(entityName, whereEntityCondition, havingEntityCondition, fieldsToSelect, orderByFields, options);
                     this.outputHandler.handleOutput(eli, context, listAcsr);
                 } catch (GenericEntityException e) {
                     String errMsg = "Failure in by " + label + " find operation, rolling back transaction";

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java?rev=1797097&r1=1797096&r2=1797097&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java Wed May 31 18:43:05 2017
@@ -49,6 +49,7 @@ import org.apache.ofbiz.entity.util.Enti
 import org.apache.ofbiz.entity.util.EntityQuery;
 import org.apache.ofbiz.security.Security;
 import org.apache.ofbiz.service.config.ServiceConfigUtil;
+import org.apache.ofbiz.service.config.model.ServiceEngine;
 
 import com.ibm.icu.util.Calendar;
 
@@ -372,7 +373,7 @@ public final class ServiceUtil {
     }
 
     public static Map<String, Object> purgeOldJobs(DispatchContext dctx, Map<String, ? extends Object> context) {
-     Locale locale = (Locale)context.get("locale");
+         Locale locale = (Locale)context.get("locale");
         Debug.logWarning("purgeOldJobs service invoked. This service is obsolete - the Job Scheduler will purge old jobs automatically.", module);
         String sendPool = null;
         Calendar cal = Calendar.getInstance();
@@ -419,22 +420,17 @@ public final class ServiceUtil {
                 try {
                     // begin this transaction
                     beganTx1 = TransactionUtil.begin();
+                    EntityQuery eq = EntityQuery.use(delegator)
+                            .select("jobId")
+                            .from("JobSandbox")
+                            .where(EntityCondition.makeCondition(UtilMisc.toList(doneCond, pool)))
+                            .cursorScrollInsensitive()
+                            .maxRows(1000);
 
-                    EntityListIterator foundJobs = null;
-                    try {
-                        foundJobs = EntityQuery.use(delegator)
-                                               .select("jobId")
-                                               .from("JobSandbox")
-                                               .where(EntityCondition.makeCondition(UtilMisc.toList(doneCond, pool)))
-                                               .cursorScrollInsensitive()
-                                               .maxRows(1000)
-                                               .queryIterator();
+                    try (EntityListIterator foundJobs = eq.queryIterator()) {
                         curList = foundJobs.getPartialList(1, 1000);
-                    } finally {
-                        if (foundJobs != null) {
-                            foundJobs.close();
-                         }
                     }
+
                 } catch (GenericEntityException e) {
                     Debug.logError(e, "Cannot obtain job data from datasource", module);
                     try {
@@ -481,15 +477,14 @@ public final class ServiceUtil {
             // Now JobSandbox data is cleaned up. Now process Runtime data and remove the whole data in single shot that is of no need.
             boolean beganTx3 = false;
             GenericValue runtimeData = null;
-            EntityListIterator runTimeDataIt = null;
             List<GenericValue> runtimeDataToDelete = new LinkedList<GenericValue>();
             long jobsandBoxCount = 0;
             try {
                 // begin this transaction
                 beganTx3 = TransactionUtil.begin();
 
-                runTimeDataIt = EntityQuery.use(delegator).select("runtimeDataId").from("RuntimeData").queryIterator();
-                try {
+                EntityQuery eq =EntityQuery.use(delegator).select("runtimeDataId").from("RuntimeData");
+                try (EntityListIterator  runTimeDataIt = eq.queryIterator()) {
                     while ((runtimeData = runTimeDataIt.next()) != null) {
                         EntityCondition whereCondition = EntityCondition.makeCondition(UtilMisc.toList(EntityCondition.makeCondition("runtimeDataId", EntityOperator.NOT_EQUAL, null),
                                 EntityCondition.makeCondition("runtimeDataId", EntityOperator.EQUALS, runtimeData.getString("runtimeDataId"))), EntityOperator.AND);
@@ -498,8 +493,6 @@ public final class ServiceUtil {
                             runtimeDataToDelete.add(runtimeData);
                         }
                     }
-                } finally {
-                    runTimeDataIt.close();
                 }
                 // Now we are ready to delete runtimeData, we can safely delete complete list that we have recently fetched i.e runtimeDataToDelete.
                 delegator.removeAll(runtimeDataToDelete);