package com.github.fjdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Collection;

import com.github.fjdbc.op.CompositeOperation;
import com.github.fjdbc.op.DbOperation;
import com.github.fjdbc.op.StatementOperation;
import com.github.fjdbc.query.Query;
import com.github.fjdbc.query.ResultSetExtractor;

/**
 * Facade to the FJDBC library.
 */
public class Fjdbc {
	private final ConnectionProvider cnxProvider;

	/**
	 * Create a facade to the FJDBC library.
	 * 
	 * @param connectionProvider
	 *            The provider of {@link Connection} instances.
	 */
	public Fjdbc(ConnectionProvider connectionProvider) {
		this.cnxProvider = connectionProvider;
	}

	/**
	 * Create a statement.
	 * <p>
	 * No actual connection is established with the database until the statement is executed.
	 * 
	 * @param sql
	 *            The raw SQL string to be executed.
	 */
	public StatementOperation statement(String sql) {
		return new StatementOperation(cnxProvider, sql);
	}

	/**
	 * Merge a sequence of {@link DbOperation} as a single {@link DbOperation}.
	 * <p>
	 * This allows the operations be executed in a single transaction.
	 */
	public CompositeOperation composite(DbOperation... operations) {
		return new CompositeOperation(cnxProvider, operations);
	}

	/**
	 * Merge a sequence of {@link DbOperation} as a single {@link DbOperation}.
	 * <p>
	 * This allows the operations be executed in a single transaction.
	 */
	public CompositeOperation composite(Collection<? extends DbOperation> operations) {
		return new CompositeOperation(cnxProvider, operations);
	}

	/**
	 * Create a new query.
	 * <p>
	 * No actual connection is established with the database until the statement is executed.
	 * 
	 * @param sql
	 *            The raw SQL string. It should be a SELECT statement.
	 * @param extractor
	 *            Extracts individual objects from a {@link ResultSet}.
	 */
	public <T> Query<T> query(String sql, ResultSetExtractor<T> extractor) {
		return new Query<>(cnxProvider, sql, extractor);
	}

	public ConnectionProvider getConnectionProvider() {
		return cnxProvider;
	}

}
@@ -26,65 +26,8 @@
 %0D%0A%0D%0A
-import java.sql.Connection;%0D%0Aimport java.sql.ResultSet;%0D%0A
 impo
@@ -52,16 +52,16 @@
 ction;%0D%0A
+
 %0D%0Aimport
@@ -968,32 +968,182 @@
 r, sql);%0D%0A%09%7D%0D%0A%0D%0A
+%09public StatementOperation statement(String sql, PreparedStatementBinder binder) %7B%0D%0A%09%09return new StatementOperation(cnxProvider, sql, binder);%0D%0A%09%7D%0D%0A%0D%0A
 %09/**%0D%0A%09 * Merge 
@@ -2137,24 +2137,24 @@
 tractor) %7B%0D%0A
-
 %09%09return new
@@ -2191,32 +2191,205 @@
 ractor);%0D%0A%09%7D%0D%0A%0D%0A
+%09public %3CT%3E Query%3CT%3E query(String sql, PreparedStatementBinder binder, ResultSetExtractor%3CT%3E extractor) %7B%0D%0A%09%09return new Query%3C%3E(cnxProvider, sql, binder, extractor);%0D%0A%09%7D%0D%0A%0D%0A
 %09public Connecti

add convience methods