Java Reference
In-Depth Information
is used to update the account record of the user. This section looks at how to code and configure the
required components to implement the pricing tiers' calculation.
Reading How Many Transactions the Customer Had
There are two ways you can get the number of transactions for each account:
1. You can load each account and its list of transactions (similar to how
Hibernate would do it) and get the size of the transactions list.
2. You can create a custom object and query just for the account number and the
count of transactions the account has had.
The problem with the first option is that it doesn't scale well. As customers accumulate more and
more transactions, this approach may work well for counts in the thousands; but when you have
customers who literally make millions of trades per month, 1 this approach falls apart in a painful way.
Instead, in this example you opt for the second choice.
For this choice, you need to create a special domain object for this step. It contains the account
number and the number of transactions the account has had over the given period. Listing 10-28 shows
the code for the AccountTransactionQuantity domain object.
Listing 10-28. AccountTransactionQuantity
package com.apress.springbatch.statement.domain;
public class AccountTransactionQuantity {
private String accountNumber;
private long transactionCount;
private PricingTier tier;
// Accessors go here
..
@Override
public String toString() {
return accountNumber + " has " + transactionCount +
" transactions this month wich falls into tier " + tier;
}
}
If you remember from the discussion in Chapter 7 about JDBC ItemReaders, there are two possible
approaches: cursor based and paged based. For this reader, you a cursor-based implementation. The
reasons are that it's the default behavior for Spring Batch and there is no improvement in a case like this
from a performance perspective between the two approaches.
To create the ItemReader, you need to create a RowMapper implementation and configure both the
RowMapper and the JdbcCursorItemReader. Listing 10-29 has the code for the RowMapper.
1 Customers like this are typically what are known as algorithmic traders . These customers use computer
models to trigger trades automatically without human intervention.
 
Search WWH ::




Custom Search