class IteratorCachingResultSet extends WrappedResultSet<O> {

    @Override
    public Iterator<O> iterator() {
        if (cachedIterator != null) {
            return cachedIterator;
        }
        final Iterator<O> backingIterator = wrappedResultSet.iterator();
        Iterator<O> wrappingIterator = new Iterator<O>() {

            @Override
            public boolean hasNext() {
                return backingIterator.hasNext();
            }

            @Override
            public O next() {
                cachedIterator = null;
                return backingIterator.next();
            }

            @Override
            public void remove() {
                cachedIterator = null;
                backingIterator.remove();
            }
        };
        this.cachedIterator = wrappingIterator;
        return wrappingIterator;
    }

    public  IteratorCachingResultSet(ResultSet<O> backingResultSet);

}