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.
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 should
ResultSet.next()
over rows it wants to consider.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionscanResultSet
(Supplier<ResultSet> resultSetSupplier, StatementContext ctx) Scans the lazily-suppliedResultSet
into a result.
-
Method Details
-
scanResultSet
Scans the lazily-suppliedResultSet
into 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:
SQLException
- if anything goes wrong
-