Java Reference
In-Depth Information
Listing 10-36. AccountTransactionRowMapper
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.AccountTransaction;
import com.apress.springbatch.statement.domain.PricingTier;
public class AccountTransactionRowMapper implements RowMapper {
public Object mapRow(ResultSet resultSet, int arg1) throws SQLException {
AccountTransaction accountTransaction = new AccountTransaction();
accountTransaction.setAccountId(resultSet.getLong("accountId"));
accountTransaction.setAccountNumber(resultSet.getString("accountNumber"));
accountTransaction.setId(resultSet.getLong("transactionId"));
accountTransaction.setQuantity(resultSet.getLong("qty"));
accountTransaction.setTicker(resultSet.getString("ticker"));
accountTransaction.setTier(PricingTier.convert(resultSet.getInt("tier")));
accountTransaction.setTradeTimestamp(resultSet.getDate("executedTime"));
accountTransaction.setPrice(resultSet.getBigDecimal("dollarAmount"));
return accountTransaction;
}
}
With the domain object defined and the RowMapper written, all that is left is to configure the
ItemReader and the step of the job used to calculate transaction fees. For the configuration, you use
almost the exact same configuration as in the previous step. The only difference is the SQL statement
and the ItemReader's reference to the RowMapper implementation. Listing 10-37 shows the configured
step with the ItemReader.
Listing 10-37. Configuring the calculateTransactionFees Step and Dependencies
...
<beans:bean id="transactionPricingItemReader"
class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="sql"
value="select a.id as accountId, a.accountNumber, t.id as transactionId, t.qty, tk.ticker,
a.tier, t.executedTime, t.dollarAmount from account a inner join transaction t on a.id =
t.account_id inner join ticker tk on t.tickerId = tk.id and t.processed = false and t.jobId =
#{jobParameters[run.id]} order by t.executedTime"/>
<beans:property name="rowMapper" ref="transactionPricingRowMapper"/>
</beans:bean>
 
Search WWH ::




Custom Search