001package com.avaje.ebean;
002
003/**
004 * Used to process a query result one bean at a time via a callback to this
005 * visitor.
006 * <p>
007 * If you wish to stop further processing return false from the accept method.
008 * </p>
009 * <p>
010 * Unlike findList() and findSet() using a QueryResultVisitor does not require
011 * all the beans in the query result to be held in memory at once. This makes
012 * QueryResultVisitor useful for processing large queries.
013 * </p>
014 * <p/>
015 * <pre class="code">
016 *
017 * Query&lt;Customer&gt; query = server.find(Customer.class)
018 *     .fetch(&quot;contacts&quot;, new FetchConfig().query(2))
019 *     .where().gt(&quot;id&quot;, 0)
020 *     .orderBy(&quot;id&quot;)
021 *     .setMaxRows(2);
022 *
023 * query.findEachWhile((Customer customer) -> {
024 *
025 *     // do something with customer
026 *     System.out.println(&quot;-- visit &quot; + customer);
027 *
028 *     // return true to continue processing or false to stop
029 *     return (customer.getId() < 40);
030 * });
031 * </pre>
032 *
033 * @param <T> the type of entity bean being queried.
034 */
035public interface QueryEachWhileConsumer<T> {
036
037  /**
038   * Process the bean and return true if you want to continue processing more
039   * beans. Return false if you want to stop processing further.
040   *
041   * @param bean the entity bean to process
042   * @return true to continue processing more beans or false to stop.
043   */
044  boolean accept(T bean);
045}