Class IbatisKeyCollector

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

public class IbatisKeyCollector
extends ExecutionContextUserSupport
implements KeyCollector

KeyCollector based on iBATIS ORM framework. It is functionally similar to SingleColumnJdbcKeyCollector but does not make assumptions about the primary key structure. A separate restart query is necessary to ensure that only the required keys remaining for processing are returned, rather than the entire original list.

Robert Kasanicky, Lucas Ward
See Also:

Constructor Summary
Method Summary
 void afterPropertiesSet()
 SqlMapClientTemplate getSqlMapClientTemplate()
 List retrieveKeys(ExecutionContext executionContext)
          Retrieve the keys to be iterated over.
 void setDrivingQueryId(String drivingQueryId)
 void setRestartQueryId(String restartQueryId)
          Set the id of the restart query.
 void setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
 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 IbatisKeyCollector()
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 afterPropertiesSet()
                        throws Exception


public void setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
sqlMapClient - configured iBATIS client


public void setDrivingQueryId(String drivingQueryId)
drivingQueryId - id of the iBATIS select statement that will be used to retrieve the list of primary keys


public void setRestartQueryId(String restartQueryId)
Set the id of the restart query.

restartQueryId - id of the iBatis select statement that will be used to retrieve the list of primary keys after a restart.


public final SqlMapClientTemplate getSqlMapClientTemplate()

Copyright © 2008 SpringSource. All Rights Reserved.