Package org.jdbi.v3.core.result
Interface ResultProducer<R>
- Type Parameters:
R
- 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.
Produces a result from an executed
PreparedStatement
.-
Method Summary
Modifier and TypeMethodDescriptionproduce
(Supplier<PreparedStatement> statementSupplier, StatementContext ctx) Produces a statement result from a lazily suppliedPreparedStatement
.
-
Method Details
-
produce
Produces a statement result from a lazily suppliedPreparedStatement
. The statement is not executed untilstatementSupplier.get()
is invoked.Implementors that call
statementSupplier.get()
must ensure that the statement context is closed before returning, to ensure that database resources are freed:try { PreparedStatement statement = statementSupplier.get() // generate and return result from the statement } finally { ctx.close(); }
Alternatively, implementors may return some intermediate result object (e.g.
ResultBearing
orResultIterable
) without callingstatementSupplier.get()
, in which case the burden of closing resources falls to whichever object ultimately doesget()
the statement.- Parameters:
statementSupplier
- supplies a PreparedStatement, post-execution.ctx
- the statement context- Returns:
- an object of the type your caller expects
- Throws:
SQLException
- if an error occurs while producing the result.
-