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.

@FunctionalInterface public interface ResultProducer<R>
Produces a result from an executed PreparedStatement.
  • Method Details

    • produce

      R produce(Supplier<PreparedStatement> statementSupplier, StatementContext ctx) throws SQLException
      Produces a statement result from a lazily supplied PreparedStatement. The statement is not executed until statementSupplier.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 or ResultIterable) without calling statementSupplier.get(), in which case the burden of closing resources falls to whichever object ultimately does get() 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.