package com.github.fjdbc;

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);
	}

	public StatementOperation statement(String sql, PreparedStatementBinder binder) {
		return new StatementOperation(cnxProvider, sql, binder);
	}

	/**
	 * 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 <T> Query<T> query(String sql, PreparedStatementBinder binder, ResultSetExtractor<T> extractor) {
		return new Query<>(cnxProvider, sql, binder, extractor);
	}

	public ConnectionProvider getConnectionProvider() {
		return cnxProvider;
	}

}
@@ -18,24 +18,60 @@
 b.fjdbc;%0D%0A%0D%0A
+import java.sql.PreparedStatement;%0D%0A
 import java.
@@ -482,22 +482,16 @@
 brary.%0D%0A
-%09 * %0D%0A
 %09 * @par
@@ -520,28 +520,24 @@
 %0A%09 *        
-    
 The provider
@@ -805,38 +805,32 @@
 t is executed.%0D%0A
-%09 * %0D%0A
 %09 * @param sql%0D%0A
@@ -832,36 +832,32 @@
 sql%0D%0A%09 *        
-    
 The raw SQL stri
@@ -984,32 +984,384 @@
 r, sql);%0D%0A%09%7D%0D%0A%0D%0A
+%09/**%0D%0A%09 * Create a statement.%0D%0A%09 * %3Cp%3E%0D%0A%09 * No actual connection is established with the database until the statement is executed.%0D%0A%09 * @param sql%0D%0A%09 *        The raw SQL string to be executed.%0D%0A%09 * @param binder%0D%0A%09 *        The binder of %7B@link PreparedStatement%7D parameters, or %7B@code null%7D if this query does not have%0D%0A%09 *        parameters.%0D%0A%09 */%0D%0A
 %09public Statemen
@@ -2249,14 +2249,8 @@
 d.%0D%0A
-%09 * %0D%0A
 %09 * 
@@ -2268,28 +2268,24 @@
 %0A%09 *        
-    
 The raw SQL 
@@ -2347,28 +2347,24 @@
 tractor%0D%0A%09 *
-    
         Extr
@@ -2545,32 +2545,490 @@
 ractor);%0D%0A%09%7D%0D%0A%0D%0A
+%09/**%0D%0A%09 * Create a new query.%0D%0A%09 * %3Cp%3E%0D%0A%09 * No actual connection is established with the database until the statement is executed.%0D%0A%09 * @param sql%0D%0A%09 *        The raw SQL string. It should be a SELECT statement.%0D%0A%09 * @param binder%0D%0A%09 *        The binder of %7B@link PreparedStatement%7D parameters, or %7B@code null%7D if this query does not have%0D%0A%09 *        parameters.%0D%0A%09 * @param extractor%0D%0A%09 *        Extracts individual objects from a %7B@link ResultSet%7D.%0D%0A%09 */%0D%0A
 %09public %3CT%3E Quer

add javadoc