/** * A binder that takes a binder and an iterable, applies the binder to each element of the iterable and adds it as a batch, * executes the batch, and returns the total update count. Used in BatchInsertGenKeysOp and BatchUpdateOp * @param binder the binder for a single element in the iterable * @param as the iterable * @param <A> the type of elements in the iterable * @return the total update count, as an Option. The option will be none() iff any of the elements in the update count * is equal to Statement.SUCCESS_NO_INFO */ public static <A> Try1<PreparedStatement, Option<Integer>, SQLException> batchBinder( F<A, TryEffect1<PreparedStatement, SQLException>> binder, Iterable<A> as) { return ps -> { for (A a : as) { binder.f(a).f(ps); ps.addBatch(); } return sumBatchResult(ps.executeBatch()); }; }