@Override protected Object reducedResult(Stream<?> stream, StatementContext ctx) { Collector collector = ctx.findCollectorFor(returnType.getType()).orElse(null); if (collector != null) { return stream.collect(collector); } return checkResult(stream.findFirst().orElse(null), returnType); }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) protected Object mappedResult(ResultIterable<?> iterable, StatementContext ctx) { Collector collector = ctx.findCollectorFor(returnType.getType()).orElse(null); if (collector != null) { return iterable.collect(collector); } return checkResult(iterable.findFirst().orElse(null), returnType); }
/** * 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. * <p> * This method is equivalent to {@code ResultBearing.mapTo(elementType).collect(containerCollector)}. * </p> * * @param containerType the container type into which results will be collected * @return a container into which result rows have been collected */ @SuppressWarnings({ "unchecked", "rawtypes" }) default Object collectInto(Type containerType) { return scanResultSet((rs, ctx) -> { Collector collector = ctx.findCollectorFor(containerType) .orElseThrow(() -> new NoSuchCollectorException("No collector registered for container type " + containerType)); Type elementType = ctx.findElementTypeFor(containerType) .orElseThrow(() -> new ElementTypeNotFoundException("Unknown element type for container type " + containerType)); RowMapper<?> mapper = ctx.findMapperFor(elementType) .orElseThrow(() -> new NoSuchMapperException("No mapper registered for element type " + elementType)); return ResultIterable.of(rs, mapper, ctx).collect(collector); }); } }
/** * 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. * <p> * This method is equivalent to {@code ResultBearing.mapTo(elementType).collect(containerCollector)}. * </p> * * @param containerType the container type into which results will be collected * @return a container into which result rows have been collected */ @SuppressWarnings("unchecked") default Object collectInto(Type containerType) { return mapResultSet((rs, ctx) -> { Collector collector = ctx.findCollectorFor(containerType) .orElseThrow(() -> new NoSuchCollectorException("No collector registered for container type " + containerType)); Type elementType = ctx.findElementTypeFor(containerType) .orElseThrow(() -> new ElementTypeNotFoundException("Unknown element type for container type " + containerType)); RowMapper<?> mapper = ctx.findRowMapperFor(elementType) .orElseThrow(() -> new UnsupportedOperationException("No mapper registered for element type " + elementType)); return ResultIterable.of(rs, mapper, ctx).collect(collector); }); } }