From a391a25b7fefff6e4f181e78f8010cef9f7c8eab Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Wed, 23 Nov 2016 23:44:54 +1300 Subject: [PATCH] No effective change - update Javadoc on QueryIterator with try with resources --- .../java/com/avaje/ebean/QueryIterator.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/avaje/ebean/QueryIterator.java b/src/main/java/com/avaje/ebean/QueryIterator.java index 96787bd3f..4f714e7bd 100644 --- a/src/main/java/com/avaje/ebean/QueryIterator.java +++ b/src/main/java/com/avaje/ebean/QueryIterator.java @@ -17,8 +17,10 @@ import java.util.Iterator; *

*

* Remember that with {@link QueryIterator} you must call {@link QueryIterator#close()} - * when you have finished iterating the results (typically in a finally block). + * when you have finished iterating the results. Use "try with resources" or ensure it + * is closed in a finally block. *

+ *

Try finally style

*
{@code
  *
  *  Query query = server.find(Customer.class)
@@ -38,6 +40,19 @@ import java.util.Iterator;
  *  }
  *
  * }
+ *

+ *

Try with resources style

+ *
{@code
+ *
+ *  // try with resources
+ *  try (QueryIterator it = query.findIterate()) {
+ *    while (it.hasNext()) {
+ *      Customer customer = it.next();
+ *      // do something with customer ...
+ *    }
+ *  }
+ *
+ * }
* * @param the type of entity bean in the iteration */