Java Reference
In-Depth Information
<beans:bean id="transactionPricingRowMapper"
class="com.apress.springbatch.statement.reader.AccountTransactionRowMapper"/>
<step id="calculateTransactionFees">
<tasklet task-executor="taskExecutor">
<chunk reader="transactionPricingItemReader" processor="feesItemProcessor"
writer="applyFeeWriter" commit-interval="100"/>
</tasklet>
</step>
<job id="statementJob" incrementer="idIncrementer">
<step id="step1" parent="importCustomerAndTransactionData" next="step2"/>
<step id="step2" parent="retrieveStockPrices" next="step3"/>
<step id="step3" parent="importStockPrices" next="step4"/>
<step id="step4" parent="calculateTiers" next="step5"/>
<step id="step5" parent="calculateTransactionFees"/>
</job>
...
The configuration for the calculateTransactionFees step shown in Listing 10-37 begins with the
definition of the ItemReader—a JdbcCursorItemReader in this case. transactionPricingItemReader
requires three dependencies: a datasource, the SQL, and a reference to the RowMapper implementation
you coded back in Listing 10-36. After the ItemReader configuration, you configure an instance of the
RowMapper the ItemReader needs for the dataset it is processing. Finally the configuration for your step
is provided. However, just as in the previous steps you've configured, you still have more to do before
this is operational. First you need to code and configure the ItemProcessor, which is covered in the next
section.
Calculating Transaction Prices
Table 10-1 showed that tiers II through IV all have a flat fee, but tier I's fee consists of a flat fee of $9.00
plus 0.1% of the total cost of the transaction. For example, if the transaction consists of 20 shares of HD
stock at $40.00 each, the fee is calculated as
($40.00 × 20 shares)0.001 = $0.80
To calculate what the fee is for each transaction a customer has made, you implement an
ItemProcessor to apply that logic. This section looks at how to develop and configure the ItemProcessor
required to calculate the customer's transaction fees.
The code for this ItemProcessor is straightforward; Listing 10-37 has the code for
FeesItemProcessor .
Listing 10-37. FeesItemProcessor
package com.apress.springbatch.statement.processor;
import java.math.BigDecimal;
import org.springframework.batch.item.ItemProcessor;
import com.apress.springbatch.statement.domain.AccountTransaction;
 
Search WWH ::




Custom Search