package org.td.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.td.common.beans.MarginRate;
public class MarginRateDao extends AbstractDao {
private static final String MARGIN_RATE_SQL = "SELECT broker_id, short_rate, long_rate " +
"FROM margin_rate WHERE broker_id = ?";
public MarginRate getMarginRateByBrokerId(final Integer brokerId) {
ParameterizedRowMapper<MarginRate> mapper = new ParameterizedRowMapper<MarginRate>() {
public MarginRate mapRow(ResultSet rs, int rowNum) throws SQLException {
MarginRate marginRate = new MarginRate();
// marginRate.setBrokerId(rs.getObject("broker_id") == null ? null
// : (Integer) rs.getObject("broker_id"));
// marginRate.setShortMargin(rs.getObject("short") == null ? null
// : (Double) rs.getObject("short"));
// marginRate.setLongMargin(rs.getObject("long") == null ? null
// : (Double) rs.getObject("long"));
marginRate.setBrokerId(brokerId);
marginRate.setShortRate(rs.getDouble("short_rate"));
marginRate.setLongRate(rs.getDouble("long_rate"));
return marginRate;
}
};
return getSimpleJdbcTemplate().queryForObject(MARGIN_RATE_SQL, mapper,
new Object[] { brokerId });
}
}