Class IteratorCachingResultSet<O>

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Iterable<O>

    public class IteratorCachingResultSet<O>
    extends WrappedResultSet<O>
    A ResultSet which wraps a backing ResultSet, and which caches the iterator returned by the backing ResultSet, to enable repeated invocations on IteratorCachingResultSet.iterator().hasNext(), to avoid each time requesting a new iterator from the backing ResultSet.

    An effect of this caching is that if the application calls ResultSet.isEmpty() or ResultSet.isNotEmpty() on this ResultSet before it begins iteration, only one iterator will actually be requested from the backing ResultSet because the cached iterator will be reused each time.

    On the other hand, whenever the application actually begins to iterate through results, this ResultSet will detect it, and if iterator() is invoked again, it will avoid returning the same cached iterator and will obtain a new iterator instead.

    Author:
    niall.gallagher