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

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

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.

Author:
Robert Kasanicky, Lucas Ward
See Also:
DrivingQueryItemReader

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

IbatisKeyCollector

public IbatisKeyCollector()
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.

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Throws:
Exception

setSqlMapClient

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

setDrivingQueryId

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

setRestartQueryId

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

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

getSqlMapClientTemplate

public final SqlMapClientTemplate getSqlMapClientTemplate()


Copyright © 2008 SpringSource. All Rights Reserved.