Java Reference
In-Depth Information
public void setJobId(long jobId) {
this.jobId = jobId;
public void setWhereClause(String whereClause) {
if(whereClause != null) {
this.whereClause = whereClause;
As you can see, the StepListener in Listing 11-4 updates all the records you identify with the job id
you pass in to be processed by your step. On the other end of the step is the ItemWriteListener . This
listener interface is called either before or after (here, after) a chunk is written. The method afterWrite
takes the same list of items that were previously written by the ItemWriter. Using this lets you update the
staged records to be flagged as processed. Listing 11-5 shows the code for this listener.
Listing 11-5. StagingChunkUpdater
package com.apress.springbatch.statement.listener;
import java.util.List;
import org.springframework.batch.core.ItemWriteListener;
import org.springframework.jdbc.core.JdbcTemplate;
import com.apress.springbatch.statement.domain.AccountTransaction;
public class StagingChunkUpdater extends JdbcTemplate implements
ItemWriteListener<AccountTransaction> {
private String SQL = " set processed = true ";
private String tableName;
private String whereClause = "";
public void beforeWrite(List<? extends AccountTransaction> items) {
public void afterWrite(List<? extends AccountTransaction> items) {
for (AccountTransaction accountTransaction : items) {
update("update " + tableName + SQL + whereClause,
new Object[] {accountTransaction.getId()});
public void onWriteError(Exception exception,
List<? extends AccountTransaction> items) {
public void setTableName(String tableName) {
this.tableName = tableName;
Search WWH ::

Custom Search