Java Reference
In-Depth Information
if(recordCount == expectedRecordCount) {
return execution.getExitStatus();
} else {
return ExitStatus.STOPPED;
}
}
}
For the job to execute, four other classes are required: Transaction , AccountSummary ,
TransactionApplierProcessor , and TransactionDaoImpl . The first two, Transaction and AccountSummary ,
are nothing more than the POJOs used to represent the two record formats. Transaction has four fields
to represent both the transaction input file record format and its related Transaction database table
format. The fields represented in the Transaction class are as follows:
id : An int representing the primary key for the database
accountNumber : A String representing the account number for the transaction as
found in the transaction input file
timestamp : A java.util.Date representing the timestamp as found in the
transaction input file
amount : A double representing the amount of the transaction as found in the
transaction input file
The AccountSummary class represents the format of the Account_Summary database table and the
subsequent accountSummary output file. The fields found in the AccountSummary class (with the
appropriate getters and setters) are as follows:
id : An int representing the primary key of the Account_Summary database table
accountNumber : A String representing the account number
currentBalance : A double representing the current balance of the account
The other two classes are related to step2 of the job. This step applies each of the transactions to its
appropriate account's balance. To do this, the step reads in each of account that has any transactions
associated with it, loads all the related transactions, updates the record, and writes the updated record to
the database. The reader and writer for this step are declared in the XML from Listing 6-19, but the
processor is something you have to write yourself. Listing 6-28 shows the ItemProcessor,
TransactionApplierProcessor .
Listing 6-28. TransactionApplierProcessor
package com.apress.springbatch.chapter6;
import java.util.List;
import org.springframework.batch.item.ItemProcessor;
public class TransactionApplierProcessor implements
ItemProcessor<AccountSummary, AccountSummary> {
private TransactionDao transactionDao;
 
Search WWH ::




Custom Search