001package com.avaje.ebean; 002 003import java.util.Iterator; 004 005/** 006 * Used to provide iteration over query results. 007 * <p> 008 * This can be used when you want to process a very large number of results and 009 * means that you don't have to hold all the results in memory at once (unlike 010 * findList(), findSet() etc where all the beans are held in the List or Set 011 * etc). 012 * </p> 013 * 014 * <pre class="code"> 015 * 016 * Query<Customer> query = server.find(Customer.class) 017 * .fetch("contacts", new FetchConfig().query(2)) 018 * .where().gt("id", 0) 019 * .orderBy("id") 020 * .setMaxRows(2); 021 * 022 * QueryIterator<Customer> it = query.findIterate(); 023 * try { 024 * while (it.hasNext()) { 025 * Customer customer = it.next(); 026 * // do something with customer... 027 * } 028 * } finally { 029 * // close the associated resources 030 * it.close(); 031 * } 032 * </pre> 033 * 034 * @author rbygrave 035 * 036 * @param <T> 037 * the type of entity bean in the iteration 038 */ 039public interface QueryIterator<T> extends Iterator<T>, java.io.Closeable { 040 041 /** 042 * Returns <tt>true</tt> if the iteration has more elements. 043 */ 044 boolean hasNext(); 045 046 /** 047 * Returns the next element in the iteration. 048 */ 049 T next(); 050 051 /** 052 * Remove is not allowed. 053 */ 054 void remove(); 055 056 /** 057 * Close the underlying resources held by this iterator. 058 */ 059 void close(); 060}