package org.td.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.td.common.beans.Trade;
public class TradeDao extends AbstractDao {
private static final String ALL_TRADES_SQL = "SELECT ticker, type, price, close_price, " +
"stop_loss, stop_profit, vol, open_signal, close_signal, entry_date, close_date " +
"FROM trades WHERE basket_id = ? ORDER BY entry_date DESC";
public Trade getTrades(final Integer basketId) {
ParameterizedRowMapper<Trade> mapper = new ParameterizedRowMapper<Trade>() {
public Trade mapRow(ResultSet rs, int rowNum) throws SQLException {
Trade trade = new Trade();
trade.setBasketId(basketId);
trade.setTicker(rs.getString("ticker"));
trade.setType((char) rs.getByte("type"));
trade.setPrice(rs.getDouble("price"));
trade.setClosePrice(rs.getDouble("close_price"));
trade.setStopLoss(rs.getDouble("stop_loss"));
trade.setStopProfit(rs.getDouble("stop_profit"));
trade.setVol(rs.getInt("vol"));
trade.setOpenSignal(rs.getString("open_signal"));
trade.setCloseSignal(rs.getString("close_signal"));
trade.setEntryDate(rs.getDate("entry_date"));
trade.setCloseDate(rs.getDate("close_date"));
return trade;
}
};
return getSimpleJdbcTemplate().queryForObject(ALL_TRADES_SQL, mapper,
new Object[] { basketId });
}
}