All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.firefly.db.SQLConnection Maven / Gradle / Ivy

package com.firefly.db;

import com.firefly.utils.function.Func1;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
 * The asynchronous SQL connection. It can execute SQL and bind result to Java bean.
 *
 * @author Pengtao Qiu
 */
public interface SQLConnection {

    /**
     * Query single column record by SQL
     *
     * @param sql    An SQL that may contain one or more '?' IN parameter placeholders
     * @param params SQL parameters
     * @param     The type of column
     * @return The future result
     * @throws RecordNotFound If the database has not record throw RecordNotFound exception
     */
     CompletableFuture queryForSingleColumn(String sql, Object... params);

    /**
     * Query record and bind object
     *
     * @param sql    An SQL that may contain one or more '?' IN parameter placeholders
     * @param clazz  The Class reference of bound object
     * @param params SQL parameters
     * @param     The type of bound object
     * @return The future result
     * @throws RecordNotFound If the database has not record throw RecordNotFound exception
     */
     CompletableFuture queryForObject(String sql, Class clazz, Object... params);

    /**
     * Query record by id
     *
     * @param id    Primary key
     * @param clazz The Class reference of bound object
     * @param    The type of bound object
     * @return The future result
     * @throws RecordNotFound If the database has not record of this id throw RecordNotFound exception
     */
     CompletableFuture queryById(Object id, Class clazz);

    /**
     * Query records and convert records to a Map
     *
     * @param sql        An SQL that may contain one or more '?' IN parameter placeholders
     * @param valueClass The Class reference of bound object
     * @param params     SQL parameters
     * @param         The type of primary key
     * @param         The type of bound object
     * @return The future result that contains a map, the key is primary key of record, the value is bound object.
     */
     CompletableFuture> queryForBeanMap(String sql, Class valueClass, Object... params);

    /**
     * Query records and bind object
     *
     * @param sql    An SQL that may contain one or more '?' IN parameter placeholders
     * @param clazz  The Class reference of bound object
     * @param params SQL parameters
     * @param     The type of bound object
     * @return The future result that contains a list
     */
     CompletableFuture> queryForList(String sql, Class clazz, Object... params);

     CompletableFuture query(String sql, Func1 handler, Object... params);

    CompletableFuture update(String sql, Object... params);

     CompletableFuture updateObject(T object);

     CompletableFuture insert(String sql, Object... params);

     CompletableFuture insertObject(T object);

     CompletableFuture insertObjectBatch(List list, Class clazz, Func1 handler);

     CompletableFuture> insertObjectBatch(List list, Class clazz);

     CompletableFuture insertBatch(String sql, Object[][] params, Func1 handler);

     CompletableFuture deleteById(Object id, Class clazz);

    CompletableFuture executeBatch(String sql, Object[][] params);

    CompletableFuture setTransactionIsolation(TransactionIsolation transactionIsolation);

    CompletableFuture setAutoCommit(boolean autoCommit);

    boolean getAutoCommit();

    CompletableFuture rollback();

    CompletableFuture commit();

    CompletableFuture close();

    CompletableFuture commitAndClose();

    CompletableFuture rollbackAndClose();

     CompletableFuture inTransaction(Func1> func1);

    CompletableFuture beginTransaction();

    CompletableFuture rollbackAndEndTransaction();

    CompletableFuture commitAndEndTransaction();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy