Package org.jdbi.v3.core.result
Interface ResultIterable<T>
- Type Parameters:
- T- iterable element type
- All Superinterfaces:
- Iterable<T>
- All Known Subinterfaces:
- BatchResultIterable<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic classAn implementation ofResultIteratorthat delegates calls to the iterator provided in the constructor.
- 
Method SummaryModifier and TypeMethodDescriptiondefault <R> RCollect the results into a container specified by a collector.default ResultIterable<T>Convenience method to filter theResultIterableby applying the specifiedPredicate.
 This method has the look and feel ofStream.filter(Predicate)without making use of streams.Returns the first row in the result set, if present.findOne()Returns the only row in the result set, if any.default TfindOnly()Deprecated.default Tfirst()Returns the first row in the result set.default voiddefault intforEachWithCount(Consumer<? super T> action) Performs the specified action on each remaining element and returns the iteration i.e.iterator()Stream all the rows of the result set out with anIterator.list()Returns results in aList.default <R> ResultIterable<R>Returns aResultIterable<U>derived from thisResultIterable<T>, by transforming elements using the given mapper function.static <T> ResultIterable<T>of(Supplier<ResultSet> resultSetSupplier, RowMapper<T> mapper, StatementContext ctx) Returns a ResultIterable backed by the given result set supplier, mapper, and context.static <T> ResultIterable<T>of(ResultIterator<T> iterator) Returns a ResultIterable backed by the given iterator.default Tone()Returns the only row in the result set.default <U> Ureduce(U identity, BiFunction<U, T, U> accumulator) Reduce the results.stream()Returns the stream of results.default <X extends Exception>
 voiduseIterator(IteratorConsumer<T, X> consumer) Passes the iterator of results to the consumer.default <X extends Exception>
 voiduseStream(StreamConsumer<T, X> consumer) Passes the stream of results to the consumer.default <R,X extends Exception> 
 RwithIterator(IteratorCallback<T, R, X> callback) Passes the iterator of results to the callback.default <R,X extends Exception> 
 RwithStream(StreamCallback<T, R, X> callback) Passes the stream of results to the callback.Methods inherited from interface java.lang.Iterablespliterator
- 
Method Details- 
ofstatic <T> ResultIterable<T> of(Supplier<ResultSet> resultSetSupplier, RowMapper<T> mapper, StatementContext ctx) Returns a ResultIterable backed by the given result set supplier, mapper, and context.- Type Parameters:
- T- the mapped type
- Parameters:
- resultSetSupplier- result set supplier
- mapper- row mapper
- ctx- statement context
- Returns:
- the result iterable
 
- 
ofReturns a ResultIterable backed by the given iterator.- Type Parameters:
- T- iterator element type
- Parameters:
- iterator- the result iterator
- Returns:
- a ResultIterable
 
- 
iteratorResultIterator<T> iterator()Stream all the rows of the result set out with anIterator. TheIteratormust be closed to release database resources.
- 
useIteratorPasses the iterator of results to the consumer. Database resources owned by the query are released before this method returns.- Parameters:
- consumer- a consumer which receives the iterator of results.
- Throws:
- X- any exception thrown by the callback
 
- 
withIteratorPasses the iterator of results to the callback. Database resources owned by the query are released before this method returns.- Type Parameters:
- R- the type returned by the callback
- Parameters:
- callback- a callback which receives the iterator of results, and returns some result.
- Returns:
- the value returned by the callback.
- Throws:
- X- any exception thrown by the callback
 
- 
mapReturns aResultIterable<U>derived from thisResultIterable<T>, by transforming elements using the given mapper function.- Type Parameters:
- R- Element type of the returned ResultIterable
- Parameters:
- mapper- function to apply to elements of this ResultIterable
- Returns:
- the new ResultIterable
 
- 
forEach
- 
forEachWithCountPerforms the specified action on each remaining element and returns the iteration i.e. record count.
 It is often useful (e.g. for logging) to know the record count while processing result sets.int cnt = h.createQuery("select * from something").mapTo(String.class) .forEachWithCount(System.out::println); System.out.println(cnt + " records selected");- Parameters:
- action- action to apply (required)
- Returns:
- iteration count
- Since:
- 3.31
 
- 
oneReturns the only row in the result set. Returnsnullif the row itself isnull.- Returns:
- the only row in the result set.
- Throws:
- IllegalStateException- if the result set contains zero or multiple rows
 
- 
findOneReturns the only row in the result set, if any. ReturnsOptional.empty()if zero rows are returned, or if the row itself isnull.- Returns:
- the only row in the result set, if any.
- Throws:
- IllegalStateException- if the result set contains multiple rows
 
- 
findOnlyGet the only row in the result set.- Returns:
- the object mapped from the singular row in the results
- Throws:
- IllegalStateException- if zero or multiple rows are returned
 
- 
firstReturns the first row in the result set. Returnsnullif the row itself isnull.- Returns:
- the first row in the result set.
- Throws:
- IllegalStateException- if zero rows are returned
 
- 
findFirstReturns the first row in the result set, if present. ReturnsOptional.empty()if zero rows are returned or the first row isnull.- Returns:
- the first row in the result set, if present.
 
- 
streamReturns the stream of results.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 }- Returns:
- the stream of results.
- See Also:
 
- 
useStreamPasses the stream of results to the consumer. Database resources owned by the query are released before this method returns.- Type Parameters:
- X- the exception type thrown by the callback, if any
- Parameters:
- consumer- a consumer which receives the stream of results.
- Throws:
- X- any exception thrown by the callback
 
- 
withStreamPasses the stream of results to the callback. Database resources owned by the query are released before this method returns.- Type Parameters:
- R- the type returned by the callback
- X- the exception type thrown by the callback, if any
- Parameters:
- callback- a callback which receives the stream of results, and returns some result.
- Returns:
- the value returned by the callback.
- Throws:
- X- any exception thrown by the callback
 
- 
listReturns results in aList.- Returns:
- results in a List.
 
- 
collectCollect the results into a container specified by a collector.- Type Parameters:
- R- the generic type of the container
- Parameters:
- collector- the collector
- Returns:
- the container with the query result
 
- 
reduceReduce the results. Using aBiFunction<U, T, U>, repeatedly combine query results until only a single value remains.- Type Parameters:
- U- the accumulator type
- Parameters:
- identity- the- Uto combine with the first result
- accumulator- the function to apply repeatedly
- Returns:
- the final U
 
- 
filterConvenience method to filter theResultIterableby applying the specifiedPredicate.
 This method has the look and feel ofStream.filter(Predicate)without making use of streams.Please note that filtering takes place in Java i.e. your client code, not in the database. 
 Filtering inside the database will most likely be of higher performance than filtering outside, as intermediate results are loaded into Java and then discarded. Moreover, indexes that may exist in the database will not be utilized here.- Parameters:
- predicate- a non-null predicate to apply to each element to determine whether it should be included in the result
- Returns:
- the new result iterable
- Since:
- 3.31
 
 
- 
one()orfindOne()instead.