A combination of
AutoCloseable
and
Iterator
This allows an iterator that encapsulates a chunking SQL operation. Suggested loop sytax is to
use a try-with-resources statement containing a while loop.
try(CloseableIterator it = .... ){
while(it.hasNext()){
}
}
The contract of this interface is that the the
AutoCloseable.close()
should be invokable
multiple times without additional error.
If the
Iterator
is run to completion than the object should automatically close. An additional
call to close should only be required for an incomplete iterator (for example if an exception is thrown).