Package org.jdbi.v3.core.result
Class BatchResultBearing
- java.lang.Object
-
- org.jdbi.v3.core.result.BatchResultBearing
-
- All Implemented Interfaces:
ResultBearing
public final class BatchResultBearing extends java.lang.Object implements ResultBearing
Extends theResultBearingclass to provide access to the per-batch row modification counts.
-
-
Field Summary
Fields Modifier and Type Field Description private ResultBearingdelegateprivate java.util.function.Supplier<int[]>modifiedRowCountsSupplier
-
Constructor Summary
Constructors Constructor Description BatchResultBearing(ResultBearing delegate, java.util.function.Supplier<int[]> modifiedRowCountsSupplier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <R> RcollectInto(java.lang.Class<R> containerType)Collect the results into a container of the given type.java.lang.ObjectcollectInto(java.lang.reflect.Type containerType)Collect the results into a container of the given type.<R> RcollectInto(GenericType<R> containerType)Collect the results into a container of the given generic type.<A,R>
RcollectRows(java.util.stream.Collector<RowView,A,R> collector)Collect the results using the given collector.<T> BatchResultIterable<T>map(ColumnMapper<T> mapper)Maps this result set to aResultIterable, using the given column mapper.<T> BatchResultIterable<T>map(RowMapper<T> mapper)Maps this result set to aResultIterable, using the given row mapper.<T> BatchResultIterable<T>map(RowViewMapper<T> mapper)Maps this result set to aResultIterable, using the givenRowViewMapper.<T> BatchResultIterable<T>mapTo(java.lang.Class<T> type)Maps this result set to aResultIterableof the given element type.BatchResultIterable<?>mapTo(java.lang.reflect.Type type)Maps this result set to aResultIterableof the given element type.<T> BatchResultIterable<T>mapTo(GenericType<T> type)Maps this result set to aResultIterableof the given element type.<T> BatchResultIterable<T>mapTo(QualifiedType<T> type)Maps this result set to aResultIterableof the given qualified element type.<T> BatchResultIterable<T>mapToBean(java.lang.Class<T> type)Maps this result set to aResultIterableof the given element type, usingBeanMapper.BatchResultIterable<java.util.Map<java.lang.String,java.lang.Object>>mapToMap()Maps this result set to aResultIterableofMap<String,Object>.<T> BatchResultIterable<java.util.Map<java.lang.String,T>>mapToMap(java.lang.Class<T> valueType)Maps this result set to aMapofStringand the given value class.<T> BatchResultIterable<java.util.Map<java.lang.String,T>>mapToMap(GenericType<T> valueType)Maps this result set to aMapofStringand the given value type.int[]modifiedRowCounts()Returns the mod counts for the executedPreparedBatchNote that some database drivers might return special values likeStatement.SUCCESS_NO_INFOorStatement.EXECUTE_FAILED.<U> UreduceResultSet(U seed, ResultSetAccumulator<U> accumulator)Reduce the results.<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.<C,R>
java.util.stream.Stream<R>reduceRows(RowReducer<C,R> rowReducer)Reduce the result rows using the given row reducer.<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.
-
-
-
Field Detail
-
delegate
private final ResultBearing delegate
-
modifiedRowCountsSupplier
private final java.util.function.Supplier<int[]> modifiedRowCountsSupplier
-
-
Constructor Detail
-
BatchResultBearing
public BatchResultBearing(ResultBearing delegate, java.util.function.Supplier<int[]> modifiedRowCountsSupplier)
-
-
Method Detail
-
scanResultSet
public <R> R scanResultSet(ResultSetScanner<R> resultSetScanner)
Description copied from interface:ResultBearingInvokes the mapper with a result set supplier, and returns the value returned by the mapper.- Specified by:
scanResultSetin interfaceResultBearing- Type Parameters:
R- result type returned by the mapper.- Parameters:
resultSetScanner- result set scanner- Returns:
- the value returned by the mapper.
-
mapTo
public <T> BatchResultIterable<T> mapTo(java.lang.Class<T> type)
Description copied from interface:ResultBearingMaps this result set to aResultIterableof the given element type.- Specified by:
mapToin interfaceResultBearing- 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
public <T> BatchResultIterable<T> mapTo(GenericType<T> type)
Description copied from interface:ResultBearingMaps this result set to aResultIterableof the given element type.- Specified by:
mapToin interfaceResultBearing- 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
public BatchResultIterable<?> mapTo(java.lang.reflect.Type type)
Description copied from interface:ResultBearingMaps this result set to aResultIterableof the given element type.- Specified by:
mapToin interfaceResultBearing- 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
public <T> BatchResultIterable<T> mapTo(QualifiedType<T> type)
Description copied from interface:ResultBearingMaps this result set to aResultIterableof the given qualified element type.- Specified by:
mapToin interfaceResultBearing- 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
public <T> BatchResultIterable<T> mapToBean(java.lang.Class<T> type)
Description copied from interface:ResultBearingMaps this result set to aResultIterableof the given element type, usingBeanMapper.- Specified by:
mapToBeanin interfaceResultBearing- 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
public BatchResultIterable<java.util.Map<java.lang.String,java.lang.Object>> mapToMap()
Description copied from interface:ResultBearingMaps this result set to aResultIterableofMap<String,Object>. Keys are column names, and values are column values.- Specified by:
mapToMapin interfaceResultBearing- Returns:
- a
ResultIterable<Map<String,Object>>.
-
mapToMap
public <T> BatchResultIterable<java.util.Map<java.lang.String,T>> mapToMap(java.lang.Class<T> valueType)
Description copied from interface:ResultBearingMaps this result set to aMapofStringand the given value class.- Specified by:
mapToMapin interfaceResultBearing- 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
public <T> BatchResultIterable<java.util.Map<java.lang.String,T>> mapToMap(GenericType<T> valueType)
Description copied from interface:ResultBearingMaps this result set to aMapofStringand the given value type.- Specified by:
mapToMapin interfaceResultBearing- 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
public <T> BatchResultIterable<T> map(ColumnMapper<T> mapper)
Description copied from interface:ResultBearingMaps this result set to aResultIterable, using the given column mapper.- Specified by:
mapin interfaceResultBearing- 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
public <T> BatchResultIterable<T> map(RowMapper<T> mapper)
Description copied from interface:ResultBearingMaps this result set to aResultIterable, using the given row mapper.- Specified by:
mapin interfaceResultBearing- 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
public <T> BatchResultIterable<T> map(RowViewMapper<T> mapper)
Description copied from interface:ResultBearingMaps this result set to aResultIterable, using the givenRowViewMapper. This overload only exists to allow RowViewMapper as the type of a lambda expression.- Specified by:
mapin interfaceResultBearing- 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
public <C,R> java.util.stream.Stream<R> reduceRows(RowReducer<C,R> rowReducer)
Description copied from interface:ResultBearingReduce the result rows using the given row reducer.- Specified by:
reduceRowsin interfaceResultBearing- 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
public <K,V> java.util.stream.Stream<V> reduceRows(java.util.function.BiConsumer<java.util.Map<K,V>,RowView> accumulator)
Description copied from interface:ResultBearingReduce the result rows using aMap<K, V>as the result container.- Specified by:
reduceRowsin interfaceResultBearing- 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
public <U> U reduceRows(U seed, java.util.function.BiFunction<U,RowView,U> accumulator)Description copied from interface:ResultBearingReduce the results. Using aBiFunction<U, RowView, U>, repeatedly combine query results until only a single value remains.- Specified by:
reduceRowsin interfaceResultBearing- 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
public <U> U reduceResultSet(U seed, ResultSetAccumulator<U> accumulator)Description copied from interface:ResultBearingReduce the results. Using aResultSetAccumulator, repeatedly combine query results until only a single value remains.- Specified by:
reduceResultSetin interfaceResultBearing- Type Parameters:
U- the accumulator type- Parameters:
seed- theUto combine with the first resultaccumulator- the function to apply repeatedly- Returns:
- the final
U
-
collectRows
public <A,R> R collectRows(java.util.stream.Collector<RowView,A,R> collector)
Description copied from interface:ResultBearingCollect 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().- Specified by:
collectRowsin interfaceResultBearing- 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
public <R> R collectInto(java.lang.Class<R> containerType)
Description copied from interface:ResultBearingCollect 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).- Specified by:
collectIntoin interfaceResultBearing- 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
public <R> R collectInto(GenericType<R> containerType)
Description copied from interface:ResultBearingCollect 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>>() {});- Specified by:
collectIntoin interfaceResultBearing- 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
public java.lang.Object collectInto(java.lang.reflect.Type containerType)
Description copied from interface:ResultBearingCollect 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).- Specified by:
collectIntoin interfaceResultBearing- Parameters:
containerType- the container type into which results will be collected- Returns:
- a container into which result rows have been collected
-
modifiedRowCounts
public int[] modifiedRowCounts()
Returns the mod counts for the executedPreparedBatchNote that some database drivers might return special values likeStatement.SUCCESS_NO_INFOorStatement.EXECUTE_FAILED.
Note that the result is only available after the statement was executed (eg. by calling map()). Calling this method before execution will return an empty array.- Returns:
- the number of modified rows per batch part for the executed
PreparedBatch.
-
-