Java Reference
In-Depth Information
} else if(atq.getTransactionCount() > 100000 && atq.getTransactionCount() <= 1000000)
{
atq.setTier(PricingTier.III);
} else {
atq.setTier(PricingTier.IV);
}
return atq;
}
}
As with each component of the batch process, you need to configure it. This ItemProcessor
obviously doesn't have any dependencies, so the configuration involves nothing more than a bean
definition and updating your step to reference the bean. Listing 10-33 shows the updated configuration
for the calculateTiers step.
Listing 10-33. calculateTiers Step Configuration
...
<beans:bean id="pricingTiersItemProcessor"
class="com.apress.springbatch.statement.processor.PricingTierItemProcessor"/>
...
With the pricing tiers calculated, you need to update the database with the values you've calculated.
That database update occurs in the next section.
Updating the Database with the Calculated Tier
Unlike the steps up to this point, which were mostly about moving data around, step 4 is the first step
intended to apply business rules to the data you already have. Because of that, the ItemReader and the
ItemWriter are simplistic. The logic for this step resides in the ItemProcessor. This section looks at the
ItemWriter required for the tier-processing step.
Because most of the work in this step is done in the ItemProcessor, it should come as no surprise
that the ItemWriter for this step is, again, quite simple. Its responsibility is only to update the account
being processed with the tier you've calculated it to fall into. Using a JdbcBatchItemWriter, you can
perform the required updates. Listing 10-34 shows the configuration for the new ItemWriter.
Listing 10-34. Configuration for tiersUpdateWriter
...
<beans:bean id="tiersUpdateWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="sql"
value="update account set tier = :tier.value where accountNumber = :accountNumber"/>
<beans:property name="itemSqlParameterSourceProvider">
<beans:bean
class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider"/>
</beans:property>
</beans:bean>
...
 
Search WWH ::




Custom Search