org.springframework.batch.item.database.support
Class MultipleColumnJdbcKeyCollector

java.lang.Object
  extended by org.springframework.batch.item.ExecutionContextUserSupport
      extended by org.springframework.batch.item.database.support.MultipleColumnJdbcKeyCollector
All Implemented Interfaces:
KeyCollector

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.

Author:
Lucas Ward
See Also:
DrivingQueryItemReader, ItemPreparedStatementSetter

Constructor Summary
MultipleColumnJdbcKeyCollector()
           
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

MultipleColumnJdbcKeyCollector

public MultipleColumnJdbcKeyCollector()

MultipleColumnJdbcKeyCollector

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

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

retrieveKeys

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
Parameters:
executionContext - ExecutionContext containing any potential initial state that could potentially be used to retrieve the correct keys.
Returns:
list of keys returned by the driving query

updateContext

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
Parameters:
key - to be converted to restart data.

setRestartSql

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

Parameters:
restartQuery -

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Throws:
Exception

setKeyMapper

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

Parameters:
keyMapper -

setSql

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

Parameters:
sql -

setJdbcTemplate

public void setJdbcTemplate(JdbcTemplate jdbcTemplate)

setPreparedStatementSetter

public void setPreparedStatementSetter(ItemPreparedStatementSetter preparedStatementSetter)


Copyright © 2008 SpringSource. All Rights Reserved.