Class LazyResultSet<T>

  • All Implemented Interfaces:
    ResultSet<T>, Iterable<T>

    public class LazyResultSet<T>
    extends Object
    implements ResultSet<T>
    Result set that allows for asynchronous execution of the actual query. Callers should dispatch the query and call the constructor of this class with a supplier that fetches the result and blocks on it if necessary.

    If the execution is synchronous or the results are known a priori, consider using ListResultSet.

    • Constructor Detail

      • LazyResultSet

        public LazyResultSet​(Supplier<com.google.common.collect.ImmutableList<T>> r)
    • Method Detail

      • iterator

        public Iterator<T> iterator()
        Description copied from interface: ResultSet
        Obtain an iterator to loop through the results.

        The iterator can be obtained only once. When the iterator completes ( hasNext() returns false) ResultSet.close() will be automatically called.

        Specified by:
        iterator in interface Iterable<T>
        Specified by:
        iterator in interface ResultSet<T>
      • toList

        public com.google.common.collect.ImmutableList<T> toList()
        Description copied from interface: ResultSet
        Materialize all results as a single list.

        Prior to returning ResultSet.close() is invoked. This method must not be combined with ResultSet.iterator() on the same instance.

        Specified by:
        toList in interface ResultSet<T>
        Returns:
        immutable list of the complete results.
      • close

        public void close()
        Description copied from interface: ResultSet
        Close the result, discarding any further results.

        This method may be invoked more than once. Its main use is to stop obtaining results before the iterator has finished.

        Specified by:
        close in interface ResultSet<T>