Java Reference
In-Depth Information
public Object mapRow(ResultSet rs, int arg1) throws SQLException {
Ticker ticker = new Ticker();
ticker.setId(rs.getLong("id"));
ticker.setPrice(rs.getBigDecimal("currentPrice"));
ticker.setTicker(rs.getString("ticker"));
return ticker;
}
});
if(tickers != null && tickers.size() > 0) {
return tickers.get(0);
} else {
return null;
}
}
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);
}
}
The new method getTickersPaged returns a list of stock tickers. Notice that you're paginating the
results. The reason is that the web service you use can't take large numbers of stock tickers at once, so
you break up the list.
After you can get the stock tickers from the Transactions table, you can create your web service call.
In this case, you don't need to use a web service client. All you need to do is make a simple HTTP GET
request and get the String response. For this, you use Apache Commons' HttpClient. To use it, you have
to add the library to your POM file. Listing 10-20 lists the dependency required.
Listing 10-20. HttpClient Dependency
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.1</version>
</dependency>
With the dependency addressed, you can write your reader. This reader consists of formatting the
URL, making the request to obtain the stock prices, and returning the String response. The only logic
you need to be concerned with is storing the results before you return them the first time, because you
 
Search WWH ::




Custom Search