package com.firefly.reactive.adapter.db;

import com.firefly.db.SQLConnection;
import com.firefly.db.SQLResultSet;
import com.firefly.db.TransactionIsolation;
import com.firefly.utils.function.Func1;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

/**
 * SQLConnection reactor adapter
 *
 * @see com.firefly.db.SQLConnection
 * @author Pengtao Qiu
 */
public interface ReactiveSQLConnection {

    <T> Mono<T> queryForSingleColumn(String sql, Object... params);

    <T> Mono<T> queryForObject(String sql, Class<T> clazz, Object... params);

    <T> Mono<T> queryById(Object id, Class<T> clazz);

    <K, V> Mono<Map<K, V>> queryForBeanMap(String sql, Class<V> valueClass, Object... params);

    <T> Mono<List<T>> queryForList(String sql, Class<T> clazz, Object... params);

    <T> Mono<T> query(String sql, Func1<SQLResultSet, T> handler, Object... params);

    Mono<Integer> update(String sql, Object... params);

    <T> Mono<Integer> updateObject(T object);

    <T> Mono<T> insert(String sql, Object... params);

    <T, R> Mono<R> insertObject(T object);

    <T, R> Mono<R> insertObjectBatch(List<T> list, Class<T> clazz, Func1<SQLResultSet, R> handler);

    <T, R> Mono<List<R>> insertObjectBatch(List<T> list, Class<T> clazz);

    <R> Mono<R> insertBatch(String sql, Object[][] params, Func1<SQLResultSet, R> handler);

    <T> Mono<Integer> deleteById(Object id, Class<T> clazz);

    Mono<int[]> executeBatch(String sql, Object[][] params);

    Mono<Boolean> setTransactionIsolation(TransactionIsolation transactionIsolation);

    Mono<Boolean> setAutoCommit(boolean autoCommit);

    boolean getAutoCommit();

    Mono<Boolean> rollback();

    Mono<Boolean> commit();

    Mono<Boolean> close();

    Mono<Boolean> commitAndClose();

    Mono<Boolean> rollbackAndClose();

    <T> Mono<T> inTransaction(Func1<ReactiveSQLConnection, Mono<T>> func1);

    Mono<Boolean> beginTransaction();

    Mono<Boolean> rollbackAndEndTransaction();

    Mono<Boolean> commitAndEndTransaction();

    SQLConnection getSQLConnection();

}

@@ -35,16 +35,54 @@
 er.db;%0A%0A
+import com.firefly.db.RecordNotFound;%0A
 import c
@@ -350,16 +350,62 @@
  adapter
+. It wraps SQLConnection using Spring reactor.
 %0A *%0A * @
@@ -514,302 +514,2201 @@
     
-%3CT%3E Mono%3CT%3E queryForSingleColumn(String sql, Object... params);%0A%0A    %3CT%3E Mono%3CT%3E queryForObject(String sql, Class%3CT%3E clazz, Object... params);%0A%0A    %3CT%3E Mono%3CT%3E queryById(Object id, Class%3CT%3E clazz);%0A%0A    %3CK, V%3E Mono%3CMap%3CK, V%3E%3E queryForBeanMap(String sql, Class%3CV%3E valueClass, Object... params);%0A
+/**%0A     * Query single column record by SQL%0A     *%0A     * @param sql    An SQL that may contain one or more '?' IN parameter placeholders%0A     * @param params SQL parameters%0A     * @param %3CT%3E    The type of column%0A     * @return The future result%0A     * @throws RecordNotFound If the database has not record throw RecordNotFound exception%0A     */%0A    %3CT%3E Mono%3CT%3E queryForSingleColumn(String sql, Object... params);%0A%0A    /**%0A     * Query record and bind object%0A     *%0A     * @param sql    An SQL that may contain one or more '?' IN parameter placeholders%0A     * @param clazz  The Class reference of bound object%0A     * @param params SQL parameters%0A     * @param %3CT%3E    The type of bound object%0A     * @return The future result%0A     * @throws RecordNotFound If the database has not record throw RecordNotFound exception%0A     */%0A    %3CT%3E Mono%3CT%3E queryForObject(String sql, Class%3CT%3E clazz, Object... params);%0A%0A    /**%0A     * Query record by id%0A     *%0A     * @param id    Primary key%0A     * @param clazz The Class reference of bound object%0A     * @param %3CT%3E   The type of bound object%0A     * @return The future result%0A     * @throws RecordNotFound If the database has not record of this id throw RecordNotFound exception%0A     */%0A    %3CT%3E Mono%3CT%3E queryById(Object id, Class%3CT%3E clazz);%0A%0A    /**%0A     * Query records and convert records to a Map%0A     *%0A     * @param sql        An SQL that may contain one or more '?' IN parameter placeholders%0A     * @param valueClass The Class reference of bound object%0A     * @param params     SQL parameters%0A     * @param %3CK%3E        The type of primary key%0A     * @param %3CV%3E        The type of bound object%0A     * @return The future result that contains a map, the key is primary key of record, the value is bound object.%0A     */%0A    %3CK, V%3E Mono%3CMap%3CK, V%3E%3E queryForBeanMap(String sql, Class%3CV%3E valueClass, Object... params);%0A%0A    /**%0A     * Query records and bind object%0A     *%0A     * @param sql    An SQL that may contain one or more '?' IN parameter placeholders%0A     * @param clazz  The Class reference of bound object%0A     * @param params SQL parameters%0A     * @param %3CT%3E    The type of bound object%0A     * @return The future result that contains a list%0A     */
 %0A   

add document for ReactiveSQLConnection