Package org.jdbi.v3.core.result
Interface ResultSetScanner<T>
-
- Type Parameters:
T- the collected result type
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface ResultSetScanner<T>Scan over rows of result sets, mapping and collecting the rows to a result type. Unlike the Row and ColumnMappers, this interface lets you control the ResultSet scrolling - the implementation shouldResultSet.next()over rows it wants to consider.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description TscanResultSet(java.util.function.Supplier<java.sql.ResultSet> resultSetSupplier, StatementContext ctx)Scans the lazily-suppliedResultSetinto a result.
-
-
-
Method Detail
-
scanResultSet
T scanResultSet(java.util.function.Supplier<java.sql.ResultSet> resultSetSupplier, StatementContext ctx) throws java.sql.SQLException
Scans the lazily-suppliedResultSetinto a result. The ResultSet is not produced (and typically, the statement the result came from is not executed) untilresultSetSupplier.get()is called.Implementors that call
resultSetSupplier.get()must ensure that the statement context is closed when thescanResultSet(Supplier, StatementContext)method exits. Otherwise, database resource may not be freed.public T scanResultSet(Supplier<ResultSet> resultSetSupplier, StatementContext ctx) { ... try (StatementContext context = ctx) { ResultSet resultSet = resultSetSupplier.get(); // generate and return result from the result set. } }Alternatively, implementors may return some intermediate result object (e.g.
ResultIterable) without callingresultSetSupplier.get(), in which case the burden of closing resources falls to whichever object ultimately callsresultSetSupplier.get().public T scanResultSet(Supplier<ResultSet> resultSetSupplier, StatementContext ctx) { ... // the implementation of SomeOtherClass.createResponse which may call resultSetSupplier.get() // is now responsible to register the result set for cleanup and to close the StatementContext. return SomeOtherClass.createResponse(resultSetSupplier, ..., ctx); }- Parameters:
resultSetSupplier- supplies a ResultSet.ctx- the statement context.- Returns:
- the mapped result
- Throws:
java.sql.SQLException- if anything goes wrong
-
-