Java Reference
In-Depth Information
You may wonder about the :tier.value parameter defined in the SQL in this example. Because you
define a getValue method on the PricingTier enum , you can use the dot notation and save the value of
the tier as its integer value. This is purely a personal preference in this case.
Apress Investments doesn't make its money by moving data around. It makes its money by charging
fees per transaction. In the next section, you look at how those fees are calculated.
Calculating Transaction Fees
With the pricing tier determined, you can calculate the cost of each transaction. To do this, you need two
pieces of information: the price of the purchase and the pricing tier you calculated in the previous step.
This section looks at how to calculate a fee and update the transaction accordingly.
Reading the Transactions
Just as in the previous step, you use a new domain object for this step. In this case, you have a class that
extends Transaction but adds a couple of Account fields that you need (pricing tier, specifically) to make
the calculations. Listing 10-35 shows the new domain object.
Listing 10-35. AccountTransaction
package com.apress.springbatch.statement.domain;
import java.math.BigDecimal;
public class AccountTransaction extends Transaction {
private String accountNumber;
private PricingTier tier;
private BigDecimal fee;
private long quantity;
private BigDecimal price;
// Accessors go here
public String toString() {
return getId() + ":" + accountNumber + ":" + getTicker() +
":" + getTradeTimestamp().getTime() + ":" + fee;
Each AccountTransaction represents a transaction that needs a fee to be calculated. When the fee
has been calculated, the ItemWriter updates the transaction. The process for creating this ItemReader is
no different than creating the one covered in the previous section. You have a JdbcCursorItemReader
that executes the SQL query you configure and uses the RowMapper you configure to map the results to
the AccountTransaction object. Listing 10-36 shows the code required for the RowMapper.
Search WWH ::

Custom Search