001package gu.sql2java;
002
003import java.util.List;
004import java.util.Map;
005import java.util.concurrent.Callable;
006
007import gu.sql2java.exception.RuntimeDaoException;
008
009public interface SqlRunner {
010
011        /**
012         * Load all the elements using a SQL statement specifying a list of fields to be retrieved.
013         * @param sql the SQL statement for retrieving
014         * @param argList the arguments to use fill given prepared statement,may be null
015         * @return an list of BaseBean bean, or empty list if no row return
016         * @throws RuntimeDaoException 
017         */
018        List<BaseBean> runSqlAsList(String sql, Object... argList) throws RuntimeDaoException;
019
020        /**
021         * Load all the elements using a SQL statement specifying a list of fields to be retrieved.
022         * @param targetTypes map of target type for column name or null
023         * @param sql the SQL statement for retrieving
024         * @param argList the arguments to use fill given prepared statement,may be null
025         * @return an list of row values map, or empty list if no row return
026         * @throws RuntimeDaoException 
027         */
028        List<Map<String, Object>> runSqlForMap(Map<String, Class<?>> targetTypes, String sql, Object... argList)
029                        throws RuntimeDaoException;
030
031        /**
032         * Load all the elements using a SQL statement specifying a fields to be retrieved.
033         * @param targetType target type for column  or null
034         * @param sql the SQL statement for retrieving
035         * @param argList the arguments to use fill given prepared statement,may be null
036         * @return an list of row values , or empty list if no row return
037         * @throws RuntimeDaoException 
038         */
039        <T> List<T> runSqlAsList(Class<T> targetType, String sql, Object... argList) throws RuntimeDaoException;
040
041        /**
042         * Load all the elements using a SQL statement specifying a row of a field to be retrieved.
043         * @param targetType target type for column or null
044         * @param sql the SQL statement for retrieving
045         * @param argList the arguments to use fill given prepared statement,may be null
046         * @return SQL statement return value
047         * @throws RuntimeDaoException
048         */
049        <T> T runSqlForValue(Class<T> targetType, String sql, Object... argList) throws RuntimeDaoException;
050
051        /**
052         * Run {@code Callable<T>} as a transaction.<br>
053         * all exceptions but {@code SQLException} threw by {@code Callable<T>} is wrapped into {@code RuntimeException}<br>
054         * throw {@code NullPointerException} if {@code fun} be {@code null}<br>
055         * @param <T>  type of return result
056         * @param fun
057         * @return
058         * @throws RuntimeDaoException
059         */
060        <T> T runAsTransaction(Callable<T> fun) throws RuntimeDaoException;
061
062        /**
063         * Run {@code Runnable} as a transaction.no return
064         * @param fun
065         * @see #runAsTransaction(Runnable)
066         * @throws RuntimeDaoException
067         */
068        void runAsTransaction(Runnable fun) throws RuntimeDaoException;
069
070        /**
071         *  run a SQL statement.
072         * @param sql the SQL statement for running
073         * @param argList the arguments to use fill given prepared statement,may be null
074         * @return {@code true} if success,otherwise {@code false}
075         */
076        boolean runSql(String sql, Object[] argList);
077
078}