T - iterable element type@FunctionalInterface public interface ResultIterable<T> extends Iterable<T>
| Modifier and Type | Method and Description |
|---|---|
default <R> R |
collect(Collector<T,?,R> collector)
Collect the results into a container specified by a collector.
|
default Optional<T> |
findFirst() |
default T |
findOnly()
Get the only row in the result set.
|
default void |
forEach(Consumer<? super T> action) |
ResultIterator<T> |
iterator()
Stream all the rows of the result set out
with an
Iterator. |
default List<T> |
list()
Returns results in a
List. |
static <T> ResultIterable<T> |
of(ResultIterator<T> iterator)
Returns a ResultIterable backed by the given iterator.
|
static <T> ResultIterable<T> |
of(Supplier<ResultSet> supplier,
RowMapper<T> mapper,
StatementContext ctx)
Returns a ResultIterable backed by the given result set supplier, mapper, and context.
|
default <U> U |
reduce(U identity,
BiFunction<U,T,U> accumulator)
Reduce the results.
|
default Stream<T> |
stream()
Returns the stream of results.
|
default <X extends Exception> |
useStream(StreamConsumer<T,X> consumer)
Passes the stream of results to the consumer.
|
default <R,X extends Exception> |
withStream(StreamCallback<T,R,X> callback)
Passes the stream of results to the callback.
|
spliteratordefault <R> R collect(Collector<T,?,R> collector)
R - the generic type of the containercollector - the collectordefault T findOnly()
IllegalStateException - if zero or multiple rows are returnedResultIterator<T> iterator()
Iterator. The Iterator must be
closed to release database resources.static <T> ResultIterable<T> of(ResultIterator<T> iterator)
T - iterator element typeiterator - the result iteratorstatic <T> ResultIterable<T> of(Supplier<ResultSet> supplier, RowMapper<T> mapper, StatementContext ctx)
T - the mapped typesupplier - result set suppliermapper - row mapperctx - statement contextdefault <U> U reduce(U identity,
BiFunction<U,T,U> accumulator)
BiFunction<U, T, U>, repeatedly
combine query results until only a single value remains.U - the accumulator typeidentity - the U to combine with the first resultaccumulator - the function to apply repeatedlyUdefault Stream<T> stream()
Note: the returned stream owns database resources, and must be closed via a call to BaseStream.close(), or
by using the stream in a try-with-resources block:
try (Stream<T> stream = query.stream()) {
// do stuff with stream
}
useStream(StreamConsumer),
withStream(StreamCallback)default <X extends Exception> void useStream(StreamConsumer<T,X> consumer) throws X extends Exception
X - the exception type thrown by the callback, if anyconsumer - a consumer which receives the stream of results.X - any exception thrown by the callbackX extends Exceptiondefault <R,X extends Exception> R withStream(StreamCallback<T,R,X> callback) throws X extends Exception
R - the type returned by the callbackX - the exception type thrown by the callback, if anycallback - a callback which receives the stream of results, and returns some result.X - any exception thrown by the callbackX extends ExceptionCopyright © 2017. All rights reserved.