|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.batch.item.database.BatchSqlUpdateItemWriter<T>
public class BatchSqlUpdateItemWriter<T>
ItemWriter that uses the batching features from
PreparedStatement if available and can take some rudimentary steps to
locate a failure during a flush, and identify the items that failed. When one
of those items is encountered again the batch is flushed aggressively so that
the bad item is eventually identified and can be dealt with in
isolation.
The user must provide an SQL query and a special callback
ItemPreparedStatementSetter, which is responsible for mapping the
item to a PreparedStatement.
It is expected that write(List) is called inside a transaction.
The writer is thread safe after its properties are set (normal singleton
behaviour), so it can be used to write in multiple concurrent transactions.
Note, however, that the set of failed items is stored in a collection
internally, and this collection is never cleared, so it is not a great idea
to go on using the writer indefinitely. Normally it would be used for the
duration of a batch job and then discarded.
| Constructor Summary | |
|---|---|
BatchSqlUpdateItemWriter()
|
|
| Method Summary | |
|---|---|
void |
afterPropertiesSet()
Check mandatory properties - there must be a delegate. |
void |
setAssertUpdates(boolean assertUpdates)
Public setter for the flag that determines whether an assertion is made that all items cause at least one row to be updated. |
void |
setItemPreparedStatementSetter(ItemPreparedStatementSetter<T> preparedStatementSetter)
Public setter for the ItemPreparedStatementSetter. |
void |
setJdbcTemplate(JdbcOperations jdbcTemplate)
Public setter for the JdbcOperations. |
void |
setSql(String sql)
Public setter for the query string to execute on write. |
void |
write(List<? extends T> items)
Process the supplied data element. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BatchSqlUpdateItemWriter()
| Method Detail |
|---|
public void setAssertUpdates(boolean assertUpdates)
assertUpdates - the flag to set. Defaults to true;public void setSql(String sql)
ItemPreparedStatementSetter.
sql - the query to setpublic void setItemPreparedStatementSetter(ItemPreparedStatementSetter<T> preparedStatementSetter)
ItemPreparedStatementSetter.
preparedStatementSetter - the ItemPreparedStatementSetter to
setpublic void setJdbcTemplate(JdbcOperations jdbcTemplate)
JdbcOperations.
jdbcTemplate - the JdbcOperations to set
public void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface InitializingBeanException
public void write(List<? extends T> items)
throws Exception
ItemWriter
write in interface ItemWriter<T>Exception - if there are errors. The framework will catch the
exception and convert or rethrow it as appropriate.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||