com.alexkasko.springjdbc.iterable
Class IterableJdbcTemplate

java.lang.Object
  extended by org.springframework.jdbc.support.JdbcAccessor
      extended by org.springframework.jdbc.core.JdbcTemplate
          extended by com.alexkasko.springjdbc.iterable.IterableJdbcTemplate
All Implemented Interfaces:
IterableJdbcOperations, org.springframework.beans.factory.InitializingBean, org.springframework.jdbc.core.JdbcOperations

public class IterableJdbcTemplate
extends org.springframework.jdbc.core.JdbcTemplate
implements IterableJdbcOperations

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

Author:
alexkasko Date: 11/7/12

Constructor Summary
IterableJdbcTemplate(DataSource dataSource)
          Constructor
IterableJdbcTemplate(DataSource dataSource, int fetchSize)
          Constructor, takes fetchSize
 
Method Summary
static void closeQuetly(CloseableIterator<?> iter)
          Deprecated. 
<T> CloseableIterator<T>
queryForIter(org.springframework.jdbc.core.PreparedStatementCreator psc, org.springframework.jdbc.core.PreparedStatementSetter pss, org.springframework.jdbc.core.RowMapper<T> rowMapper)
          Query using a prepared statement, mapping each row to a Java object via a RowMapper.
<T> CloseableIterator<T>
queryForIter(org.springframework.jdbc.core.PreparedStatementCreator psc, org.springframework.jdbc.core.RowMapper<T> rowMapper)
          Query using a prepared statement, mapping each row to a Java object via a RowMapper.
 CloseableIterator<Map<String,Object>> queryForIter(String sql)
          Execute a query for a result iterator, given static SQL.
<T> CloseableIterator<T>
queryForIter(String sql, Class<T> elementType)
          Execute a query for a result шterator, given static SQL.
<T> CloseableIterator<T>
queryForIter(String sql, Class<T> elementType, Object... args)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result iterator.
 CloseableIterator<Map<String,Object>> queryForIter(String sql, Object... args)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result iterator.
<T> CloseableIterator<T>
queryForIter(String sql, Object[] args, 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 iterator.
 CloseableIterator<Map<String,Object>> queryForIter(String sql, Object[] args, int[] argTypes)
          Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result iterator.
<T> CloseableIterator<T>
queryForIter(String sql, Object[] args, int[] argTypes, 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 iterator.
<T> CloseableIterator<T>
queryForIter(String sql, Object[] args, int[] argTypes, 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.
<T> CloseableIterator<T>
queryForIter(String sql, Object[] args, 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.
<T> CloseableIterator<T>
queryForIter(String sql, org.springframework.jdbc.core.PreparedStatementSetter pss, org.springframework.jdbc.core.RowMapper<T> rowMapper)
          Query given SQL to create a prepared statement from SQL and a PreparedStatementSetter implementation that knows how to bind values to the query, mapping each row to a Java object via a RowMapper.
<T> CloseableIterator<T>
queryForIter(String sql, org.springframework.jdbc.core.RowMapper<T> rowMapper)
          Execute a query given static SQL, mapping each row to a Java object via a RowMapper.
<T> CloseableIterator<T>
queryForIter(String sql, org.springframework.jdbc.core.RowMapper<T> rowMapper, Object... args)
          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.JdbcTemplate
applyStatementSettings, batchUpdate, batchUpdate, call, createConnectionProxy, createResultsMap, execute, execute, execute, execute, execute, execute, execute, extractOutputParameters, extractReturnedResults, getColumnMapRowMapper, getFetchSize, getMaxRows, getNativeJdbcExtractor, getQueryTimeout, getSingleColumnRowMapper, handleWarnings, handleWarnings, isIgnoreWarnings, isResultsMapCaseInsensitive, isSkipResultsProcessing, isSkipUndeclaredResults, newArgPreparedStatementSetter, newArgTypePreparedStatementSetter, processResultSet, query, query, query, query, query, query, query, query, query, query, query, query, query, query, query, query, query, query, query, queryForInt, queryForInt, queryForInt, queryForList, queryForList, queryForList, queryForList, queryForList, queryForList, queryForList, queryForLong, queryForLong, queryForLong, queryForMap, queryForMap, queryForMap, queryForObject, queryForObject, queryForObject, queryForObject, queryForObject, queryForObject, queryForObject, queryForObject, queryForRowSet, queryForRowSet, queryForRowSet, setFetchSize, setIgnoreWarnings, setMaxRows, setNativeJdbcExtractor, setQueryTimeout, setResultsMapCaseInsensitive, setSkipResultsProcessing, setSkipUndeclaredResults, update, update, update, update, update, update, update
 
Methods inherited from class org.springframework.jdbc.support.JdbcAccessor
afterPropertiesSet, getDataSource, getExceptionTranslator, isLazyInit, setDatabaseProductName, setDataSource, setExceptionTranslator, setLazyInit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IterableJdbcTemplate

public IterableJdbcTemplate(DataSource dataSource)
Constructor

Parameters:
dataSource - data source

IterableJdbcTemplate

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

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

closeQuetly

@Deprecated
public static void closeQuetly(CloseableIterator<?> iter)
Deprecated. 

Static method to use in finally methods for closing CloseableIterators. Writes warning into log on exception. Since 1.2 IOUtils.closeQuietly() may be used instead this one.

Parameters:
iter - iterator to close

queryForIter

public <T> CloseableIterator<T> queryForIter(org.springframework.jdbc.core.PreparedStatementCreator psc,
                                             org.springframework.jdbc.core.RowMapper<T> rowMapper)
                                  throws org.springframework.dao.DataAccessException
Query using a prepared statement, mapping each row to a Java object via a RowMapper.

A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.

Specified by:
queryForIter in interface IterableJdbcOperations
Parameters:
psc - object that can create a PreparedStatement given a Connection If this is null, the SQL will be assumed to contain no bind parameters.
rowMapper - object that will map one object per row
Returns:
the result Iterator, containing mapped objects
Throws:
org.springframework.dao.DataAccessException - if there is any problem
See Also:
PreparedStatementCreatorFactory

queryForIter

public <T> CloseableIterator<T> queryForIter(org.springframework.jdbc.core.PreparedStatementCreator psc,
                                             org.springframework.jdbc.core.PreparedStatementSetter pss,
                                             org.springframework.jdbc.core.RowMapper<T> rowMapper)
                                  throws org.springframework.dao.DataAccessException
Query using a prepared statement, mapping each row to a Java object via a RowMapper.

A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.

Specified by:
queryForIter in interface IterableJdbcOperations
Parameters:
psc - object that can create a PreparedStatement given a Connection
pss - object that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters.
rowMapper - object that will map one object per row
Returns:
the result Iterator, containing mapped objects
Throws:
org.springframework.dao.DataAccessException - if there is any problem
See Also:
PreparedStatementCreatorFactory

queryForIter

public <T> CloseableIterator<T> queryForIter(String sql,
                                             org.springframework.jdbc.core.RowMapper<T> rowMapper)
                                  throws org.springframework.dao.DataAccessException
Execute a query given static SQL, mapping each row to a Java object via a RowMapper.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForIter method with null as argument array.

Specified by:
queryForIter in interface IterableJdbcOperations
Parameters:
sql - SQL query to execute
rowMapper - object that will map one object per row
Returns:
the result Iterator, containing mapped objects
Throws:
org.springframework.dao.DataAccessException - if there is any problem executing the query
See Also:
IterableJdbcOperations.queryForIter(String, Object[], RowMapper)

queryForIter

public <T> CloseableIterator<T> queryForIter(String sql,
                                             Class<T> elementType)
                                  throws org.springframework.dao.DataAccessException
Execute a query for a result шterator, given static SQL.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForIter method with null as argument array.

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

Specified by:
queryForIter in interface IterableJdbcOperations
Parameters:
sql - SQL query to execute
elementType - the required type of element in the result шterator (for example, Integer.class)
Returns:
an Iterator of objects that match the specified element type
Throws:
org.springframework.dao.DataAccessException - if there is any problem executing the query
See Also:
IterableJdbcOperations.queryForIter(String, Object[], Class), SingleColumnRowMapper

queryForIter

public CloseableIterator<Map<String,Object>> queryForIter(String sql)
                                                   throws org.springframework.dao.DataAccessException
Execute a query for a result iterator, given static SQL.

Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForIter method with null as argument array.

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

Specified by:
queryForIter in interface IterableJdbcOperations
Parameters:
sql - SQL query to execute
Returns:
an Iterator that contains a Map per row
Throws:
org.springframework.dao.DataAccessException - if there is any problem executing the query
See Also:
IterableJdbcOperations.queryForIter(String, Object[])

queryForIter

public <T> CloseableIterator<T> queryForIter(String sql,
                                             org.springframework.jdbc.core.PreparedStatementSetter pss,
                                             org.springframework.jdbc.core.RowMapper<T> rowMapper)
                                  throws org.springframework.dao.DataAccessException
Query given SQL to create a prepared statement from SQL and a PreparedStatementSetter implementation that knows how to bind values to the query, mapping each row to a Java object via a RowMapper.

Specified by:
queryForIter in interface IterableJdbcOperations
Parameters:
sql - SQL query to execute
pss - object that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to set fetch size and other performance options.
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,
                                             Object[] args,
                                             int[] argTypes,
                                             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 IterableJdbcOperations
Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
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
See Also:
Types

queryForIter

public <T> CloseableIterator<T> queryForIter(String sql,
                                             Object[] args,
                                             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 IterableJdbcOperations
Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
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.RowMapper<T> rowMapper,
                                             Object... args)
                                  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 IterableJdbcOperations
Parameters:
sql - SQL query to execute
rowMapper - object that will map one object per row
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
the result List, containing mapped objects
Throws:
org.springframework.dao.DataAccessException - if the query fails

queryForIter

public <T> CloseableIterator<T> queryForIter(String sql,
                                             Object[] args,
                                             int[] argTypes,
                                             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 iterator.

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

Specified by:
queryForIter in interface IterableJdbcOperations
Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
elementType - the required type of element in the result iterator (for example, Integer.class)
Returns:
a Iterator of objects that match the specified element type
Throws:
org.springframework.dao.DataAccessException - if the query fails
See Also:
IterableJdbcOperations.queryForIter(String, Class), SingleColumnRowMapper

queryForIter

public <T> CloseableIterator<T> queryForIter(String sql,
                                             Object[] args,
                                             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 iterator.

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

Specified by:
queryForIter in interface IterableJdbcOperations
Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
elementType - the required type of element in the result iterator (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:
IterableJdbcOperations.queryForIter(String, Class), SingleColumnRowMapper

queryForIter

public <T> CloseableIterator<T> queryForIter(String sql,
                                             Class<T> elementType,
                                             Object... args)
                                  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 iterator.

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

Specified by:
queryForIter in interface IterableJdbcOperations
Parameters:
sql - SQL query to execute
elementType - the required type of element in the result iterator (for example, Integer.class)
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
an Iterator of objects that match the specified element type
Throws:
org.springframework.dao.DataAccessException - if the query fails
See Also:
IterableJdbcOperations.queryForIter(String, Class), SingleColumnRowMapper

queryForIter

public CloseableIterator<Map<String,Object>> queryForIter(String sql,
                                                          Object[] args,
                                                          int[] argTypes)
                                                   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 iterator.

The results will be mapped to an Iterator (one entry for each row) of Maps (one entry for each column, using the column name as the key). Thus Each element in the iterator will be of the form returned by JdbcOperations' queryForMap() methods.

Specified by:
queryForIter in interface IterableJdbcOperations
Parameters:
sql - SQL query to execute
args - arguments to bind to the query
argTypes - SQL types of the arguments (constants from java.sql.Types)
Returns:
an Iterator that contains a Map per row
Throws:
org.springframework.dao.DataAccessException - if the query fails
See Also:
IterableJdbcOperations.queryForIter(String), Types

queryForIter

public CloseableIterator<Map<String,Object>> queryForIter(String sql,
                                                          Object... args)
                                                   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 iterator.

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

Specified by:
queryForIter in interface IterableJdbcOperations
Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
Returns:
an Iterator that contains a Map per row
Throws:
org.springframework.dao.DataAccessException - if the query fails
See Also:
IterableJdbcOperations.queryForIter(String)


Copyright © 2013. All Rights Reserved.