|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.batch.item.ExecutionContextUserSupport org.springframework.batch.item.database.support.SingleColumnJdbcKeyCollector
public class SingleColumnJdbcKeyCollector
Jdbc KeyCollector
implementation that only works for a single column key. A sql query must be passed in which
will be used to return a list of keys. Each key will be mapped by a RowMapper
that returns a mapped key. By
default, the SingleColumnRowMapper
is used, and will convert keys into well known types at runtime. It is
extremely important to note that only one column should be mapped to an object and returned as a key. If multiple
columns are returned as a key in this strategy, then restart will not function properly. Instead a strategy that
supports keys comprised of multiple columns should be used.
Restartability: Because the key is only one column, restart is made much more simple. Before each commit, the last processed key is returned to be stored as restart data. Upon restart, that same key is given back to restore from, using a separate 'RestartQuery'. This means that only the keys remaining to be processed are returned, rather than returning the original list of keys and iterating forward to that last committed point.
SingleColumnRowMapper
Constructor Summary | |
---|---|
SingleColumnJdbcKeyCollector()
|
|
SingleColumnJdbcKeyCollector(JdbcTemplate jdbcTemplate,
String sql)
Constructs a new instance using the provided jdbcTemplate and string representing the sql statement that should be used to retrieve keys. |
Method Summary | |
---|---|
void |
afterPropertiesSet()
|
List |
retrieveKeys(ExecutionContext executionContext)
Retrieve the keys to be iterated over. |
void |
setJdbcTemplate(JdbcTemplate jdbcTemplate)
Set the JdbcTemplate to be used. |
void |
setKeyMapper(RowMapper keyMapper)
Set the RowMapper to be used to map each key to an object. |
void |
setRestartSql(String restartSql)
Set the SQL query to be used to return the remaining keys to be processed. |
void |
setSql(String sql)
Set the SQL statement to be used to return the keys to be processed. |
void |
updateContext(Object key,
ExecutionContext executionContext)
Get the restart data representing the last processed key. |
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 SingleColumnJdbcKeyCollector()
public SingleColumnJdbcKeyCollector(JdbcTemplate jdbcTemplate, String sql)
jdbcTemplate
- sql
-
IllegalArgumentException
- if jdbcTemplate is null.
IllegalArgumentException
- if sql string is empty or null.Method Detail |
---|
public List retrieveKeys(ExecutionContext executionContext)
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.
retrieveKeys
in interface KeyCollector
executionContext
- ExecutionContext containing any potential initial state
that could potentially be used to retrieve the correct keys.
public void updateContext(Object key, ExecutionContext executionContext)
updateContext
in interface KeyCollector
key
- to be converted to restart data.
IllegalArgumentException
- if key is null.public void afterPropertiesSet() throws Exception
Exception
public void setKeyMapper(RowMapper keyMapper)
RowMapper
to be used to map each key to an object.
keyMapper
- public void setRestartSql(String restartSql)
restartSql
- public void setSql(String sql)
sql
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate)
JdbcTemplate
to be used.
jdbcTemplate
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |