Java Reference
In-Depth Information
public void saveTicker(Ticker ticker) {
update(SAVE_TICKER, new Object [] {ticker.getTicker(), ticker.getPrice()});
}
@SuppressWarnings("unchecked")
public List<String> getTickersPaged(int page, int pageSize) {
return queryForList(FIND_ALL,
new Object [] {(page * pageSize), pageSize},
String.class);
}
public BigDecimal getTotalValueForCustomer(long id) {
BigDecimal result = (BigDecimal) queryForObject(TOTAL_VALUE,
new Object [] {id},
BigDecimal.class);
if(result == null) {
result = new BigDecimal("0");
}
return result;
}
@SuppressWarnings("unchecked")
public List<Transaction> getStocksForCustomer(long id) {
return query(STOCKS_BY_CUSTOMER, new Object [] {id}, new RowMapper() {
public Object mapRow(ResultSet rs, int arg1) throws SQLException {
Transaction transaction = new Transaction();
transaction.setDollarAmount(rs.getBigDecimal("value"));
transaction.setQuantity(rs.getLong("qty"));
transaction.setTicker(rs.getString("ticker"));
return transaction;
}
});
}
}
The hard part in TickerDaoJdbc isn't the processing but is in the SQL. The execution of the SQL and
the mapping of the results to the objects is nothing more than standard uses of Spring's JdbcTemplate.
To make these three pieces work (the customer reader, CustomerStatementReader , and
TickerDaoJdbc , you need to update your configuration. Listing 10-44 shows the configuration for these
three components.
Listing 10-44. Configuring the generateMonthlyStatement Step
<beans:bean id="customerReader"
class="org.springframework.batch.item.database.JdbcCursorItemReader">
 
Search WWH ::




Custom Search