package com.github.fjdbc;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Collection;

import com.github.fjdbc.util.IntSequence;

/**
 * Represent a function that binds values to a prepared statement.
 */
@FunctionalInterface
public interface PreparedStatementBinder {
	void bind(PreparedStatement st, IntSequence paramIndex) throws SQLException;

	public default void bind(PreparedStatement st) throws SQLException {
		bind(st, new IntSequence(1));
	}

	public static PreparedStatementBinder create(Object... params) {
		return (st, index) -> {
			for (final Object param : params) {
				st.setObject(index.next(), param);
			}
		};
	}

	public static PreparedStatementBinder createBatch(Collection<? extends Collection<Object>> params) {
		return (st, index) -> {
			for (final Collection<Object> paramCollection : params) {
				for (final Object param : paramCollection) {
					st.setObject(index.next(), param);
				}
				st.addBatch();
				index.reset();
			}
		};
	}

}

@@ -92,38 +92,8 @@
 on;%0D
-%0Aimport java.util.Collection;%0D
 %0A%0D%0Ai
@@ -309,18 +309,18 @@
 atement 
+p
 s
-t
 , IntSeq
@@ -329,14 +329,9 @@
 nce 
-paramI
+i
 ndex
@@ -360,118 +360,8 @@
 %0D%0A%0D%0A
-%09public default void bind(PreparedStatement st) throws SQLException %7B%0D%0A%09%09bind(st, new IntSequence(1));%0D%0A%09%7D%0D%0A%0D%0A
 %09pub
@@ -552,355 +552,7 @@
 %0D%0A%0D%0A
-%09public static PreparedStatementBinder createBatch(Collection%3C? extends Collection%3CObject%3E%3E params) %7B%0D%0A%09%09return (st, index) -%3E %7B%0D%0A%09%09%09for (final Collection%3CObject%3E paramCollection : params) %7B%0D%0A%09%09%09%09for (final Object param : paramCollection) %7B%0D%0A%09%09%09%09%09st.setObject(index.next(), param);%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%09st.addBatch();%0D%0A%09%09%09%09index.reset();%0D%0A%09%09%09%7D%0D%0A%09%09%7D;%0D%0A%09%7D%0D%0A%0D%0A
 %7D%0D%0A

remove useless utility methods