001 package com.alexkasko.springjdbc.iterable;
002
003 import org.springframework.dao.DataAccessException;
004 import org.springframework.jdbc.core.RowMapper;
005 import org.springframework.jdbc.core.namedparam.SqlParameterSource;
006
007 import java.util.Map;
008
009 /**
010 * Extension interface for {@code NamedParameterJdbcOperations}. All methods, that return {@code List}
011 * mirrored with {@code queryForIter} methods that return {@link CloseableIterator}.
012 * Javadocs borrowed from {@code NamedParameterJdbcOperations}.
013 *
014 * @author alexkasko
015 * Date: 11/7/12
016 */
017 public interface IterableNamedParameterJdbcOperations {
018
019 /**
020 * Expose IterableJdbcTemplate to allow queries
021 * without named parameters
022 */
023 IterableJdbcOperations getIterableJdbcOperations();
024
025 /**
026 * Query given SQL to create a prepared statement from SQL and a list
027 * of arguments to bind to the query, mapping each row to a Java object
028 * via a RowMapper.
029 *
030 * @param sql SQL query to execute
031 * @param paramSource container of arguments to bind to the query
032 * @param rowMapper object that will map one object per row
033 * @return the result Iterator, containing mapped objects
034 * @throws org.springframework.dao.DataAccessException
035 * if the query fails
036 */
037 <T> CloseableIterator<T> queryForIter(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
038 throws DataAccessException;
039
040 /**
041 * Query given SQL to create a prepared statement from SQL and a list
042 * of arguments to bind to the query, mapping each row to a Java object
043 * via a RowMapper.
044 *
045 * @param sql SQL query to execute
046 * @param paramMap map of parameters to bind to the query
047 * (leaving it to the PreparedStatement to guess the corresponding SQL type)
048 * @param rowMapper object that will map one object per row
049 * @return the result Iterator, containing mapped objects
050 * @throws org.springframework.dao.DataAccessException
051 * if the query fails
052 */
053 <T> CloseableIterator<T> queryForIter(String sql, Map<String, ?> paramMap, RowMapper<T> rowMapper)
054 throws DataAccessException;
055
056 /**
057 * Query given SQL to create a prepared statement from SQL and a
058 * list of arguments to bind to the query, expecting a result list.
059 * <p>The results will be mapped to a List (one entry for each row) of
060 * result objects, each of them matching the specified element type.
061 *
062 * @param sql SQL query to execute
063 * @param paramSource container of arguments to bind to the query
064 * @param elementType the required type of element in the result list
065 * (for example, <code>Integer.class</code>)
066 * @return an Iterator of objects that match the specified element type
067 * @throws org.springframework.dao.DataAccessException
068 * if the query fails
069 * @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String, Class)
070 * @see org.springframework.jdbc.core.SingleColumnRowMapper
071 */
072 <T> CloseableIterator<T> queryForIter(String sql, SqlParameterSource paramSource, Class<T> elementType)
073 throws DataAccessException;
074
075 /**
076 * Query given SQL to create a prepared statement from SQL and a
077 * list of arguments to bind to the query, expecting a result list.
078 * <p>The results will be mapped to a List (one entry for each row) of
079 * result objects, each of them matching the specified element type.
080 *
081 * @param sql SQL query to execute
082 * @param paramMap map of parameters to bind to the query
083 * (leaving it to the PreparedStatement to guess the corresponding SQL type)
084 * @param elementType the required type of element in the result list
085 * (for example, <code>Integer.class</code>)
086 * @return an Iterator of objects that match the specified element type
087 * @throws org.springframework.dao.DataAccessException
088 * if the query fails
089 * @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String, Class)
090 * @see org.springframework.jdbc.core.SingleColumnRowMapper
091 */
092 <T> CloseableIterator<T> queryForIter(String sql, Map<String, ?> paramMap, Class<T> elementType)
093 throws DataAccessException;
094
095 /**
096 * Query given SQL to create a prepared statement from SQL and a
097 * list of arguments to bind to the query, expecting a result list.
098 * <p>The results will be mapped to a List (one entry for each row) of
099 * Maps (one entry for each column, using the column name as the key).
100 * Thus Each element in the list will be of the form returned by this interface's
101 * queryForMap() methods.
102 *
103 * @param sql SQL query to execute
104 * @param paramSource container of arguments to bind to the query
105 * @return an Iterator that contains a Map per row
106 * @throws org.springframework.dao.DataAccessException
107 * if the query fails
108 * @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String)
109 */
110 CloseableIterator<Map<String, Object>> queryForIter(String sql, SqlParameterSource paramSource) throws DataAccessException;
111
112 /**
113 * Query given SQL to create a prepared statement from SQL and a
114 * list of arguments to bind to the query, expecting a result list.
115 * <p>The results will be mapped to a List (one entry for each row) of
116 * Maps (one entry for each column, using the column name as the key).
117 * Each element in the list will be of the form returned by this interface's
118 * queryForMap() methods.
119 *
120 * @param sql SQL query to execute
121 * @param paramMap map of parameters to bind to the query
122 * (leaving it to the PreparedStatement to guess the corresponding SQL type)
123 * @return an Iterator that contains a Map per row
124 * @throws org.springframework.dao.DataAccessException
125 * if the query fails
126 * @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String)
127 */
128 CloseableIterator<Map<String, Object>> queryForIter(String sql, Map<String, ?> paramMap) throws DataAccessException;
129
130 }