Java Reference
In-Depth Information
public AccountSummary process(AccountSummary summary) throws Exception {
List<Transaction> transactions = transactionDao
for (Transaction transaction : transactions) {
+ transaction.getAmount());
return summary;
public void setTransactionDao(TransactionDao transactionDao) {
this.transactionDao = transactionDao;
As Listing 6-28 shows, to apply the transactions to each of the account summary records, you load
all of the Transaction s related to AccountSummary 's account number. From there, you loop through the
Transaction s, adjusting the current balance by each transaction's amount before returning the
AccountSummary to be updated in the database.
The final piece of the puzzle for this job is TransactionDaoImpl , as shown in Listing 6-29. Using
Spring's org.springframework.jdbc.core.JdbcTemplate , you query the Transaction table for Transaction
records that are associated with the requested account number.
Listing 6-29. TransactionDaoImpl
package com.apress.springbatch.chapter6;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
public class TransactionDaoImpl extends JdbcTemplate implements TransactionDao {
public List<Transaction> getTransactionsByAccountNumber(
String accountNumber) {
return query(
"select, t.timestamp, t.amount from transaction t " +
"inner join account_summary a on = t.account_summary_" +
"id where a.account_number = ?",
new Object[] { accountNumber },
new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum)
throws SQLException{
Transaction trans = new Transaction();
Search WWH ::

Custom Search