Class MultipleColumnJdbcKeyCollector

  extended by org.springframework.batch.item.ExecutionContextUserSupport
      extended by
All Implemented Interfaces:

public class MultipleColumnJdbcKeyCollector
extends ExecutionContextUserSupport
implements KeyCollector

JDBC implementation of the KeyCollector interface that works for composite keys. (i.e. keys represented by multiple columns) A SQL query to be used to return the keys and a ItemPreparedStatementSetter to map each row in the result set to an Object must be set in order to work correctly.

Lucas Ward
See Also:
DrivingQueryItemReader, ItemPreparedStatementSetter

Constructor Summary
MultipleColumnJdbcKeyCollector(JdbcTemplate jdbcTemplate, String sql)
          Construct a new ItemReader.
Method Summary
 void afterPropertiesSet()
 List retrieveKeys(ExecutionContext executionContext)
          Retrieve the keys to be iterated over.
 void setJdbcTemplate(JdbcTemplate jdbcTemplate)
 void setKeyMapper(RowMapper keyMapper)
          Set the RowMapper to be used to map a result set to keys.
 void setPreparedStatementSetter(ItemPreparedStatementSetter preparedStatementSetter)
 void setRestartSql(String restartQuery)
          Set the query to use to retrieve keys in order to restore the previous state for restart.
 void setSql(String sql)
          Set the sql statement used to generate the keys list.
 void updateContext(Object key, ExecutionContext executionContext)
          Given the provided key, store it in the provided ExecutionContext.
Methods inherited from class org.springframework.batch.item.ExecutionContextUserSupport
getKey, setName
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public MultipleColumnJdbcKeyCollector()


public MultipleColumnJdbcKeyCollector(JdbcTemplate jdbcTemplate,
                                      String sql)
Construct a new ItemReader.

jdbcTemplate -
sql - - SQL statement that returns all keys to process. object.
Method Detail


public List retrieveKeys(ExecutionContext executionContext)
Description copied from interface: KeyCollector

Retrieve the keys to be iterated over. If the ExecutionContext provided includes any state relevant to this collector (because it was stored as part of saveState()) then it should start from the point indicated by that state.

In the case of a restart, (i.e. the ExecutionContext contains relevant state) this method should return only the keys that are remaining to be processed. For example, if the are 1,000 keys, and the 500th is processed before the batch job terminates unexpectedly, upon restart keys 501 through 1,000 should be returned.

Specified by:
retrieveKeys in interface KeyCollector
executionContext - ExecutionContext containing any potential initial state that could potentially be used to retrieve the correct keys.
list of keys returned by the driving query


public void updateContext(Object key,
                          ExecutionContext executionContext)
Description copied from interface: KeyCollector
Given the provided key, store it in the provided ExecutionContext. This is necessary because retrieveKeys() will be called with the ExecutionContext that is provided as a result of this method. Since only the KeyCollector can know what format the ExecutionContext should be in, it should also save the state, as opposed to the DrivingQueryItemReader doing it for all KeyCollector implementations.

Specified by:
updateContext in interface KeyCollector
key - to be converted to restart data.


public void setRestartSql(String restartQuery)
Set the query to use to retrieve keys in order to restore the previous state for restart.

restartQuery -


public void afterPropertiesSet()
                        throws Exception


public void setKeyMapper(RowMapper keyMapper)
Set the RowMapper to be used to map a result set to keys.

keyMapper -


public void setSql(String sql)
Set the sql statement used to generate the keys list.

sql -


public void setJdbcTemplate(JdbcTemplate jdbcTemplate)


public void setPreparedStatementSetter(ItemPreparedStatementSetter preparedStatementSetter)

Copyright © 2008 SpringSource. All Rights Reserved.