com.alexkasko.springjdbc.iterable
Class IterableNamedParameterJdbcTemplate

java.lang.Object
  extended by org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
      extended by com.alexkasko.springjdbc.iterable.IterableNamedParameterJdbcTemplate
All Implemented Interfaces:
IterableNamedParameterJdbcOperations, org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations

public class IterableNamedParameterJdbcTemplate
extends org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
implements IterableNamedParameterJdbcOperations

NamedParameterJdbcTemplate extension. All methods, that return List mirrored with queryForIter methods that return CloseableIterator.

Author:
alexkasko Date: 11/7/12

Constructor Summary
IterableNamedParameterJdbcTemplate(DataSource dataSource)
          Constructor
IterableNamedParameterJdbcTemplate(DataSource dataSource, int fetchSize)
          Constructor, takes fetchSize
 
Method Summary
 IterableJdbcOperations getIterableJdbcOperations()
          Expose IterableJdbcTemplate to allow queries without named parameters
 CloseableIterator<Map<String,Object>> queryForIter(String sql, Map<String,?> paramMap)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
<T> CloseableIterator<T>
queryForIter(String sql, Map<String,?> paramMap, Class<T> elementType)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
<T> CloseableIterator<T>
queryForIter(String sql, Map<String,?> paramMap, org.springframework.jdbc.core.RowMapper<T> rowMapper)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.
 CloseableIterator<Map<String,Object>> queryForIter(String sql, org.springframework.jdbc.core.namedparam.SqlParameterSource paramSource)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
<T> CloseableIterator<T>
queryForIter(String sql, org.springframework.jdbc.core.namedparam.SqlParameterSource paramSource, Class<T> elementType)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
<T> CloseableIterator<T>
queryForIter(String sql, org.springframework.jdbc.core.namedparam.SqlParameterSource paramSource, org.springframework.jdbc.core.RowMapper<T> rowMapper)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.
 
Methods inherited from class org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
batchUpdate, batchUpdate, execute, execute, getJdbcOperations, getParsedSql, getPreparedStatementCreator, query, query, query, query, query, query, queryForInt, queryForInt, queryForList, queryForList, queryForList, queryForList, queryForLong, queryForLong, queryForMap, queryForMap, queryForObject, queryForObject, queryForObject, queryForObject, queryForRowSet, queryForRowSet, update, update, update, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IterableNamedParameterJdbcTemplate

public IterableNamedParameterJdbcTemplate(DataSource dataSource)
Constructor

Parameters:
dataSource - data source

IterableNamedParameterJdbcTemplate

public IterableNamedParameterJdbcTemplate(DataSource dataSource,
                                          int fetchSize)
Constructor, takes fetchSize

Parameters:
dataSource - data source
fetchSize - fetchSize property value
Method Detail

getIterableJdbcOperations

public IterableJdbcOperations getIterableJdbcOperations()
Expose IterableJdbcTemplate to allow queries without named parameters

Specified by:
getIterableJdbcOperations in interface IterableNamedParameterJdbcOperations

queryForIter

public <T> CloseableIterator<T> queryForIter(String sql,
                                             org.springframework.jdbc.core.namedparam.SqlParameterSource paramSource,
                                             org.springframework.jdbc.core.RowMapper<T> rowMapper)
                                  throws org.springframework.dao.DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.

Specified by:
queryForIter in interface IterableNamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
rowMapper - object that will map one object per row
Returns:
the result Iterator, containing mapped objects
Throws:
org.springframework.dao.DataAccessException - if the query fails

queryForIter

public <T> CloseableIterator<T> queryForIter(String sql,
                                             Map<String,?> paramMap,
                                             org.springframework.jdbc.core.RowMapper<T> rowMapper)
                                  throws org.springframework.dao.DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.

Specified by:
queryForIter in interface IterableNamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
rowMapper - object that will map one object per row
Returns:
the result Iterator, containing mapped objects
Throws:
org.springframework.dao.DataAccessException - if the query fails

queryForIter

public <T> CloseableIterator<T> queryForIter(String sql,
                                             org.springframework.jdbc.core.namedparam.SqlParameterSource paramSource,
                                             Class<T> elementType)
                                  throws org.springframework.dao.DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.

Specified by:
queryForIter in interface IterableNamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
elementType - the required type of element in the result list (for example, Integer.class)
Returns:
an Iterator of objects that match the specified element type
Throws:
org.springframework.dao.DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForList(String, Class), SingleColumnRowMapper

queryForIter

public <T> CloseableIterator<T> queryForIter(String sql,
                                             Map<String,?> paramMap,
                                             Class<T> elementType)
                                  throws org.springframework.dao.DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.

Specified by:
queryForIter in interface IterableNamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
elementType - the required type of element in the result list (for example, Integer.class)
Returns:
an Iterator of objects that match the specified element type
Throws:
org.springframework.dao.DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForList(String, Class), SingleColumnRowMapper

queryForIter

public CloseableIterator<Map<String,Object>> queryForIter(String sql,
                                                          org.springframework.jdbc.core.namedparam.SqlParameterSource paramSource)
                                                   throws org.springframework.dao.DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Thus Each element in the list will be of the form returned by this interface's queryForMap() methods.

Specified by:
queryForIter in interface IterableNamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramSource - container of arguments to bind to the query
Returns:
an Iterator that contains a Map per row
Throws:
org.springframework.dao.DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForList(String)

queryForIter

public CloseableIterator<Map<String,Object>> queryForIter(String sql,
                                                          Map<String,?> paramMap)
                                                   throws org.springframework.dao.DataAccessException
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Each element in the list will be of the form returned by this interface's queryForMap() methods.

Specified by:
queryForIter in interface IterableNamedParameterJdbcOperations
Parameters:
sql - SQL query to execute
paramMap - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
Returns:
an Iterator that contains a Map per row
Throws:
org.springframework.dao.DataAccessException - if the query fails
See Also:
JdbcTemplate.queryForList(String)


Copyright © 2013. All Rights Reserved.