private <R> R execute(ResultProducer<R> producer, Consumer<ExecutedBatch> batchConsumer) {
        try {
            return producer.produce(() -> {
                ExecutedBatch executedBatch = internalBatchExecute();
                batchConsumer.accept(executedBatch);
                return executedBatch.stmt;
            }, getContext());
        } catch (SQLException e) {
            cleanUpForException(e);
            throw new UnableToProduceResultException("Exception producing batch result", e, getContext());
        }
    }
Executes the batch, returning the result obtained from the given {@link ResultProducer}.

@param <R> the type of the result
@param producer the result producer.
@return value returned by the result producer.
core/src/main/java/org/jdbi/v3/core/statement/PreparedBatch.java