Java Reference
In-Depth Information
Listing 10-29. AccountTransactionQuantityRowMapper
package com.apress.springbatch.statement.reader;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.apress.springbatch.statement.domain.AccountTransactionQuantity;
public class AccountTransactionQuantityRowMapper implements RowMapper {
public AccountTransactionQuantity mapRow(ResultSet resultSet, int arg1)
throws SQLException {
AccountTransactionQuantity qty = new AccountTransactionQuantity();
qty.setAccountNumber(resultSet.getString("accountNumber"));
qty.setTransactionCount(resultSet.getLong("qty"));
return qty;
}
}
To configure AccountTransactionQuantityRowMapper (wow, that's a mouthful) and the
JdbcCursorItemReader is very easy. The JdbcCursorItemReader is the only thing with dependencies, and
you configure only the basics here: a datasource, a row mapper, and the SQL statement to be executed.
Listing 10-30 contains the configuration for this ItemReader and the calculateTiers step.
Listing 10-30. calculateTiers Step Configuration with ItemReader
<beans:bean id="accountTransactionQtyItemReader"
class="org.springframework.batch.item.database.JdbcCursorItemReader">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="sql"
value="select a.accountNumber, count(*) as qty from account a inner join transaction t on
t.account_id = a.id group by a.accountNumber"/>
<beans:property name="rowMapper" ref="accountTransactionQtyRowMapper"/>
</beans:bean>
<beans:bean id="accountTransactionQtyRowMapper"
class="com.apress.springbatch.statement.reader.AccountTransactionQuantityRowMapper"/>
<step id="calculateTiers">
<tasklet>
<chunk reader="accountTransactionQtyItemReader" processor="pricingTiersItemProcessor"
writer="tiersUpdateWriter" commit-interval="10"/>
</tasklet>
</step>
 
Search WWH ::




Custom Search