|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.batch.item.database.AbstractTransactionalResourceItemWriter org.springframework.batch.item.database.BatchSqlUpdateItemWriter
public class BatchSqlUpdateItemWriter
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 AbstractTransactionalResourceItemWriter.write(Object)
is called inside a transaction,
and that AbstractTransactionalResourceItemWriter.flush()
is then subsequently called before the transaction
commits, or AbstractTransactionalResourceItemWriter.clear()
before it rolls back.
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. |
protected void |
doClear()
No-op. |
protected void |
doFlush()
Create and execute batch prepared statement. |
protected void |
doWrite(Object output)
No-op. |
protected String |
getResourceKey()
|
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 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. |
Methods inherited from class org.springframework.batch.item.database.AbstractTransactionalResourceItemWriter |
---|
clear, flush, getProcessed, write |
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 preparedStatementSetter)
ItemPreparedStatementSetter
.
preparedStatementSetter
- the ItemPreparedStatementSetter
to
setpublic void setJdbcTemplate(JdbcOperations jdbcTemplate)
JdbcOperations
.
jdbcTemplate
- the JdbcOperations
to setpublic void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
protected void doFlush() throws EmptyResultDataAccessException
doFlush
in class AbstractTransactionalResourceItemWriter
EmptyResultDataAccessException
- if any of the items does not cause an updateprotected String getResourceKey()
getResourceKey
in class AbstractTransactionalResourceItemWriter
RepeatContext
.protected void doWrite(Object output)
doWrite
in class AbstractTransactionalResourceItemWriter
protected void doClear() throws ClearFailedException
doClear
in class AbstractTransactionalResourceItemWriter
ClearFailedException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |