Java Reference
In-Depth Information
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="sql"
value="select a.id as account_id, a.accountNumber, a.cashBalance, a.tier, c.address1 as
address, c.city, c.state, c.zip, c.id as customer_id, c.firstName, c.lastName from customer c
left outer join account a on a.customer_id = c.id order by c.id"/>
<beans:property name="rowMapper" ref="customerStatementRowMapper"/>
</beans:bean>
<beans:bean id="customerStatementRowMapper"
class="com.apress.springbatch.statement.reader.CustomerStatementRowMapper"/>
<beans:bean id="customerStatementReader"
class="com.apress.springbatch.statement.reader.CustomerStatementReader">
<beans:property name="customerReader" ref="customerReader"/>
<beans:property name="tickerDao" ref="tickerDao"/>
</beans:bean>
<step id="generateMonthlyStatements">
<tasklet>
<chunk reader="customerStatementReader" writer="statementsWriter"
commit-interval="1">
<streams>
<stream ref="customerReader"/>
</streams>
</chunk>
</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" next="step6"/>
<step id="step6" parent="generateMonthlyStatements"/>
</job>
…
The configuration in Listing 10-44 begins with the definition of the JdbcCursorItemReader used to
read the customer data. As in any of your JdbcCursorItemReader configurations, you provide a
datasource, SQL, and a RowMapper implementation (the
customerStatementReader
RowMapper). The
configuration for the RowMapper on which
customerReader
depends is next in the list. The
CustomerStatementReader
configuration is configured next. Its only two dependencies,
customerReader
and a reference to the
TickerDaoJdbc
,
are both provided.
The last part of Listing 10-44 is the configuration of the final step in the job. Although it looks like a
normal step, two aspects of it are unique. First is the registration of
customerReader
as a stream. As you
saw in Chapter 7, if an ItemReader needs to be opened and isn't configured directly as the ItemReader
for the step, you need to register it as a stream so Spring Batch calls the
open
method for you. The second
interesting piece for this step is the commit count: it's set to 1. The reason is the ItemWriter you use, as
you see next.