Java Reference
In-Depth Information
</beans:bean>
<beans:bean id="transactionDao"
class="com.apress.springbatch.chapter6.TransactionDaoImpl">
<beans:property name="dataSource" ref="dataSource"/>
</beans:bean>
<beans:bean id="transactionApplierProcessor"
class="com.apress.springbatch.chapter6.TransactionApplierProcessor">
<beans:property name="transactionDao" ref="transactionDao"/>
</beans:bean>
<beans:bean id="accountSummaryUpdater"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<beans:property name="assertUpdates" value="true" />
<beans:property name="itemSqlParameterSourceProvider">
<beans:bean class="org.springframework.batch.item.database.
BeanPropertyItemSqlParameterSourceProvider" />
</beans:property>
<beans:property name="sql" value="UPDATE ACCOUNT_SUMMARY SET
CURRENT_BALANCE = :currentBalance WHERE ACCOUNT_NUMBER = :accountNumber" />
<step id="applyTransactionsStep">
<tasklet>
<chunk reader="accountSummaryReader"
processor="transactionApplierProcessor"
writer="accountSummaryUpdater" commit-interval="100"/>
</tasklet>
</step>
...
The second step of this job applies the transactions to the user's account. The configuration for this
step begins with the ItemReader you use to read the account summary records from the database. As
each item is read, you update the currentBalance field with each of the transactions you imported in the
previous step in the transactionApplierProcessor . This ItemProcessor uses a data access object (DAO)
to look up the transactions for the account as they're processed. Finally, the account is updated with the
new currentBalance value using the accountSummaryUpdater ItemWriter. The configuration for the step
itself links the ItemReader, ItemProcessor, and ItemWriter together at the end of Listing 6-24.
The last step in the job, generateAccountSummaryStep , consists of the same accountSummaryReader
configured in Listing 6-24, but it adds a new ItemWriter that writes the summary file. Listing 6-25 shows
the configuration of the new ItemWriter and the related step.
Listing 6-25. generateAccountSummaryStep Configuration
<beans:bean id="summaryFile"
class="org.springframework.core.io.FileSystemResource" scope="step">
<beans:constructor-arg value="#{jobParameters[summaryFile]}"/>
</beans:bean>
<beans:bean id="accountSummaryWriter"
class="org.springframework.batch.item.file.FlatFileItemWriter"
 
Search WWH ::




Custom Search