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:public R produce(Supplier<PreparedStatement> statementSupplier, StatementContext context) { ... try (StatementContext context = ctx) { PreparedStatement statement = statementSupplier.get() // generate and return result from the statement } }
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 callsstatementSupplier.get()
.public R produce(Supplier<PreparedStatement> statementSupplier, StatementContext context) { ... // the implementation of SomeOtherClass.createResponse which may call statementSupplier.get() // is now responsible to close the StatementContext. return SomeOtherClass.createResponse(statementSupplier, ..., ctx); }
- 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.
-