Package org.jdbi.v3.core.result
Interface ResultBearing
-
- All Known Implementing Classes:
BatchResultBearing,MetaData,PreparedBatch,Query
public interface ResultBearingProvides access to the contents of aResultSetby mapping to Java types.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <R> RcollectInto(java.lang.Class<R> containerType)Collect the results into a container of the given type.default java.lang.ObjectcollectInto(java.lang.reflect.Type containerType)Collect the results into a container of the given type.default <R> RcollectInto(GenericType<R> containerType)Collect the results into a container of the given generic type.default <A,R>
RcollectRows(java.util.stream.Collector<RowView,A,R> collector)Collect the results using the given collector.default <T> ResultIterable<T>map(ColumnMapper<T> mapper)Maps this result set to aResultIterable, using the given column mapper.default <T> ResultIterable<T>map(RowMapper<T> mapper)Maps this result set to aResultIterable, using the given row mapper.default <T> ResultIterable<T>map(RowViewMapper<T> mapper)Maps this result set to aResultIterable, using the givenRowViewMapper.default <T> ResultIterable<T>mapTo(java.lang.Class<T> type)Maps this result set to aResultIterableof the given element type.default ResultIterable<?>mapTo(java.lang.reflect.Type type)Maps this result set to aResultIterableof the given element type.default <T> ResultIterable<T>mapTo(GenericType<T> type)Maps this result set to aResultIterableof the given element type.default <T> ResultIterable<T>mapTo(QualifiedType<T> type)Maps this result set to aResultIterableof the given qualified element type.default <T> ResultIterable<T>mapToBean(java.lang.Class<T> type)Maps this result set to aResultIterableof the given element type, usingBeanMapper.default ResultIterable<java.util.Map<java.lang.String,java.lang.Object>>mapToMap()Maps this result set to aResultIterableofMap<String,Object>.default <T> ResultIterable<java.util.Map<java.lang.String,T>>mapToMap(java.lang.Class<T> valueType)Maps this result set to aMapofStringand the given value class.default <T> ResultIterable<java.util.Map<java.lang.String,T>>mapToMap(GenericType<T> valueType)Maps this result set to aMapofStringand the given value type.static ResultBearingof(java.util.function.Supplier<java.sql.ResultSet> resultSetSupplier, StatementContext ctx)Returns a ResultBearing backed by the given result set supplier and context.default <U> UreduceResultSet(U seed, ResultSetAccumulator<U> accumulator)Reduce the results.default <K,V>
java.util.stream.Stream<V>reduceRows(java.util.function.BiConsumer<java.util.Map<K,V>,RowView> accumulator)Reduce the result rows using aMap<K, V>as the result container.default <C,R>
java.util.stream.Stream<R>reduceRows(RowReducer<C,R> rowReducer)Reduce the result rows using the given row reducer.default <U> UreduceRows(U seed, java.util.function.BiFunction<U,RowView,U> accumulator)Reduce the results.<R> RscanResultSet(ResultSetScanner<R> resultSetScanner)Invokes the mapper with a result set supplier, and returns the value returned by the mapper.
-
-
-
Method Detail
-
of
static ResultBearing of(java.util.function.Supplier<java.sql.ResultSet> resultSetSupplier, StatementContext ctx)
Returns a ResultBearing backed by the given result set supplier and context.- Parameters:
resultSetSupplier- result set supplierctx- the statement context- Returns:
- a ResultBearing
-
scanResultSet
<R> R scanResultSet(ResultSetScanner<R> resultSetScanner)
Invokes the mapper with a result set supplier, and returns the value returned by the mapper.- Type Parameters:
R- result type returned by the mapper.- Parameters:
resultSetScanner- result set scanner- Returns:
- the value returned by the mapper.
-
mapTo
default <T> ResultIterable<T> mapTo(java.lang.Class<T> type)
Maps this result set to aResultIterableof the given element type.- Type Parameters:
T- the type to map the result set rows to- Parameters:
type- the type to map the result set rows to- Returns:
- a
ResultIterableof the given type. - See Also:
Configurable.registerRowMapper(RowMapper),Configurable.registerRowMapper(org.jdbi.v3.core.mapper.RowMapperFactory),Configurable.registerColumnMapper(org.jdbi.v3.core.mapper.ColumnMapperFactory),Configurable.registerColumnMapper(ColumnMapper)
-
mapTo
default <T> ResultIterable<T> mapTo(GenericType<T> type)
Maps this result set to aResultIterableof the given element type.- Type Parameters:
T- the type to map the result set rows to- Parameters:
type- the type to map the result set rows to- Returns:
- a
ResultIterableof the given type. - See Also:
Configurable.registerRowMapper(RowMapper),Configurable.registerRowMapper(org.jdbi.v3.core.mapper.RowMapperFactory),Configurable.registerColumnMapper(org.jdbi.v3.core.mapper.ColumnMapperFactory),Configurable.registerColumnMapper(ColumnMapper)
-
mapTo
default ResultIterable<?> mapTo(java.lang.reflect.Type type)
Maps this result set to aResultIterableof the given element type.- Parameters:
type- the type to map the result set rows to- Returns:
- a
ResultIterableof the given type. - See Also:
Configurable.registerRowMapper(RowMapper),Configurable.registerRowMapper(org.jdbi.v3.core.mapper.RowMapperFactory),Configurable.registerColumnMapper(org.jdbi.v3.core.mapper.ColumnMapperFactory),Configurable.registerColumnMapper(ColumnMapper)
-
mapTo
default <T> ResultIterable<T> mapTo(QualifiedType<T> type)
Maps this result set to aResultIterableof the given qualified element type.- Parameters:
type- the qualified type to map the result set rows to- Returns:
- a
ResultIterableof the given type. - See Also:
Configurable.registerRowMapper(RowMapper),Configurable.registerRowMapper(org.jdbi.v3.core.mapper.RowMapperFactory),Configurable.registerColumnMapper(org.jdbi.v3.core.mapper.ColumnMapperFactory),Configurable.registerColumnMapper(ColumnMapper)
-
mapToBean
default <T> ResultIterable<T> mapToBean(java.lang.Class<T> type)
Maps this result set to aResultIterableof the given element type, usingBeanMapper.- Type Parameters:
T- the bean type to map the result set rows to- Parameters:
type- the bean type to map the result set rows to- Returns:
- a
ResultIterableof the given type.
-
mapToMap
default ResultIterable<java.util.Map<java.lang.String,java.lang.Object>> mapToMap()
Maps this result set to aResultIterableofMap<String,Object>. Keys are column names, and values are column values.- Returns:
- a
ResultIterable<Map<String,Object>>.
-
mapToMap
default <T> ResultIterable<java.util.Map<java.lang.String,T>> mapToMap(java.lang.Class<T> valueType)
Maps this result set to aMapofStringand the given value class.- Type Parameters:
T- the value type- Parameters:
valueType- the class to map the resultset columns to- Returns:
- a
Mapof String and the given type. - See Also:
Configurable.registerColumnMapper(ColumnMapper)
-
mapToMap
default <T> ResultIterable<java.util.Map<java.lang.String,T>> mapToMap(GenericType<T> valueType)
Maps this result set to aMapofStringand the given value type.- Type Parameters:
T- the value type- Parameters:
valueType- the type to map the resultset columns to- Returns:
- a
Mapof String and the given type. - See Also:
Configurable.registerColumnMapper(ColumnMapper)
-
map
default <T> ResultIterable<T> map(ColumnMapper<T> mapper)
Maps this result set to aResultIterable, using the given column mapper.- Type Parameters:
T- the type to map the result set rows to- Parameters:
mapper- column mapper used to map the first column of each row- Returns:
- a
ResultIterableof type<T>.
-
map
default <T> ResultIterable<T> map(RowMapper<T> mapper)
Maps this result set to aResultIterable, using the given row mapper.- Type Parameters:
T- the type to map the result set rows to- Parameters:
mapper- mapper used to map each row- Returns:
- a
ResultIterableof type<T>.
-
map
default <T> ResultIterable<T> map(RowViewMapper<T> mapper)
Maps this result set to aResultIterable, using the givenRowViewMapper. This overload only exists to allow RowViewMapper as the type of a lambda expression.- Type Parameters:
T- the type to map the result set rows to- Parameters:
mapper- RowViewMapper used to map each row- Returns:
- a
ResultIterableof type<T>.
-
reduceRows
default <C,R> java.util.stream.Stream<R> reduceRows(RowReducer<C,R> rowReducer)
Reduce the result rows using the given row reducer.- Type Parameters:
C- Mutable result container typeR- Result element type- Parameters:
rowReducer- the row reducer.- Returns:
- the stream of result elements
- See Also:
RowReducer
-
reduceRows
default <K,V> java.util.stream.Stream<V> reduceRows(java.util.function.BiConsumer<java.util.Map<K,V>,RowView> accumulator)
Reduce the result rows using aMap<K, V>as the result container.- Type Parameters:
K- map key typeV- map value type- Parameters:
accumulator- accumulator function which gathers data from eachRowViewinto the result map.- Returns:
- the stream of elements in the container's
Map.values()collection, in the order they were inserted.
-
reduceRows
default <U> U reduceRows(U seed, java.util.function.BiFunction<U,RowView,U> accumulator)Reduce the results. Using aBiFunction<U, RowView, U>, repeatedly combine query results until only a single value remains.- Type Parameters:
U- the type of the accumulator- Parameters:
seed- theUto combine with the first resultaccumulator- the function to apply repeatedly- Returns:
- the final
U
-
reduceResultSet
default <U> U reduceResultSet(U seed, ResultSetAccumulator<U> accumulator)Reduce the results. Using aResultSetAccumulator, repeatedly combine query results until only a single value remains.- Type Parameters:
U- the accumulator type- Parameters:
seed- theUto combine with the first resultaccumulator- the function to apply repeatedly- Returns:
- the final
U
-
collectRows
default <A,R> R collectRows(java.util.stream.Collector<RowView,A,R> collector)
Collect the results using the given collector. Do not attempt to accumulate theRowViewobjects into the result--they are only valid within theCollector.accumulator()function. Instead, extract mapped types from the RowView by callingRowView.getRow()orRowView.getColumn().- Type Parameters:
A- the mutable accumulator type used by the collector.R- the result type returned by the collector.- Parameters:
collector- the collector to collect the result rows.- Returns:
- the result of the collection
-
collectInto
default <R> R collectInto(java.lang.Class<R> containerType)
Collect the results into a container of the given type. A collector must be registered for the container type, which knows the element type for the container. A mapper must be registered for the element type.This method is equivalent to
ResultBearing.mapTo(elementType).collect(containerCollector).- Type Parameters:
R- the result container type- Parameters:
containerType- the container type into which results will be collected- Returns:
- a container into which result rows have been collected
-
collectInto
default <R> R collectInto(GenericType<R> containerType)
Collect the results into a container of the given generic type. A collector must be registered for the container type, which knows the element type for the container. A mapper must be registered for the element type.This method is equivalent to
ResultBearing.mapTo(elementType).collect(containerCollector).Example:
Map<Long, User> usersById = handle.createQuery("select * from user") .configure(MapEntryMappers.class, cfg -> cfg.setKeyColumn("id")) .collectInto(new GenericType<Map<Long, User>>() {});- Type Parameters:
R- the result container type- Parameters:
containerType- the container type into which results will be collected- Returns:
- a container into which result rows have been collected
-
collectInto
default java.lang.Object collectInto(java.lang.reflect.Type containerType)
Collect the results into a container of the given type. A collector must be registered for the container type, which knows the element type for the container. A mapper must be registered for the element type.This method is equivalent to
ResultBearing.mapTo(elementType).collect(containerCollector).- Parameters:
containerType- the container type into which results will be collected- Returns:
- a container into which result rows have been collected
-
-