IN PROGRESS - BATCH-672: updated tests to use SimpleJdbcTemplate
This commit is contained in:
@@ -100,7 +100,9 @@ public class PlayerSummary {
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "Player Summary: ID=" + id + " Year=" + year;
|
||||
return "Player Summary: ID=" + id + " Year=" + year + "[" + completes + ";" + attempts + ";" + passingYards +
|
||||
";" + passingTd + ";" + interceptions + ";" + rushes + ";" + rushYards + ";" + receptions +
|
||||
";" + receptionYards + ";" + totalTd;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
@@ -5,24 +5,29 @@ package org.springframework.batch.sample.domain.football.internal;
|
||||
|
||||
import org.springframework.batch.sample.domain.football.Player;
|
||||
import org.springframework.batch.sample.domain.football.PlayerDao;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class JdbcPlayerDao extends JdbcDaoSupport implements PlayerDao {
|
||||
public class JdbcPlayerDao extends SimpleJdbcDaoSupport implements PlayerDao {
|
||||
|
||||
public static final String INSERT_PLAYER = "INSERT into players(player_id, " +
|
||||
"last_name, first_name, pos, year_of_birth, year_drafted)" +
|
||||
" values (?,?,?,?,?,?)";
|
||||
public static final String INSERT_PLAYER =
|
||||
"INSERT into players(player_id, last_name, first_name, pos, year_of_birth, year_drafted)" +
|
||||
" values (:id, :lastName, :firstName, :position, :birthYear, :debutYear)";
|
||||
|
||||
public void savePlayer(Player player) {
|
||||
|
||||
getJdbcTemplate().update(INSERT_PLAYER,
|
||||
new Object[]{player.getID(),player.getLastName(),
|
||||
player.getFirstName(), player.getPosition(),
|
||||
new Integer(player.getBirthYear()),
|
||||
new Integer(player.getDebutYear())});
|
||||
getSimpleJdbcTemplate().update(INSERT_PLAYER,
|
||||
// ToDo: new BeanPropertySqlParameterSource(player));
|
||||
new MapSqlParameterSource()
|
||||
.addValue("id", player.getID())
|
||||
.addValue("lastName", player.getLastName())
|
||||
.addValue("firstName",player.getFirstName())
|
||||
.addValue("position", player.getPosition())
|
||||
.addValue("birthYear", player.getBirthYear())
|
||||
.addValue("debutYear", player.getDebutYear()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,24 +4,35 @@ import org.springframework.batch.item.ClearFailedException;
|
||||
import org.springframework.batch.item.FlushFailedException;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.football.PlayerSummary;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
|
||||
public class JdbcPlayerSummaryDao extends JdbcDaoSupport implements ItemWriter<PlayerSummary> {
|
||||
public class JdbcPlayerSummaryDao extends SimpleJdbcDaoSupport implements ItemWriter<PlayerSummary> {
|
||||
|
||||
private static final String INSERT_SUMMARY = "INSERT into PLAYER_SUMMARY(ID,YEAR_NO,COMPLETES,ATTEMPTS," +
|
||||
"PASSING_YARDS,PASSING_TD,INTERCEPTIONS,RUSHES,RUSH_YARDS,RECEPTIONS,RECEPTIONS_YARDS," +
|
||||
"TOTAL_TD) values(?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
private static final String INSERT_SUMMARY =
|
||||
"INSERT into PLAYER_SUMMARY(ID, YEAR_NO, COMPLETES, ATTEMPTS, PASSING_YARDS, PASSING_TD, " +
|
||||
"INTERCEPTIONS, RUSHES, RUSH_YARDS, RECEPTIONS, RECEPTIONS_YARDS, TOTAL_TD) " +
|
||||
"values(:id, :year, :completes, :attempts, :passingYards, :passingTd, " +
|
||||
":interceptions, :rushes, :rushYards, :receptions, :receptionYards, :totalTd)";
|
||||
|
||||
public void write(PlayerSummary summary) {
|
||||
|
||||
Object[] args = new Object[]{summary.getId(), new Integer(summary.getYear()),
|
||||
new Integer(summary.getCompletes()), new Integer(summary.getAttempts()),
|
||||
new Integer(summary.getPassingYards()), new Integer(summary.getPassingTd()),
|
||||
new Integer(summary.getInterceptions()), new Integer(summary.getRushes()),
|
||||
new Integer(summary.getRushYards()), new Integer(summary.getReceptions()),
|
||||
new Integer(summary.getReceptionYards()), new Integer(summary.getTotalTd()) };
|
||||
MapSqlParameterSource args = new MapSqlParameterSource()
|
||||
.addValue("id", summary.getId())
|
||||
.addValue("year", summary.getYear())
|
||||
.addValue("completes", summary.getCompletes())
|
||||
.addValue("attempts", summary.getAttempts())
|
||||
.addValue("passingYards", summary.getPassingYards())
|
||||
.addValue("passingTd", summary.getPassingTd())
|
||||
.addValue("interceptions", summary.getInterceptions())
|
||||
.addValue("rushes", summary.getRushes())
|
||||
.addValue("rushYards", summary.getRushYards())
|
||||
.addValue("receptions", summary.getReceptions())
|
||||
.addValue("receptionYards", summary.getReceptionYards())
|
||||
.addValue("totalTd", summary.getTotalTd());
|
||||
|
||||
getSimpleJdbcTemplate().update(INSERT_SUMMARY, args);
|
||||
|
||||
getJdbcTemplate().update(INSERT_SUMMARY, args);
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.football.PlayerSummary;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
|
||||
/**
|
||||
* RowMapper used to map a ResultSet to a (@link PlayerSummary)
|
||||
@@ -27,12 +27,12 @@ import org.springframework.jdbc.core.RowMapper;
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class PlayerSummaryMapper implements RowMapper {
|
||||
public class PlayerSummaryMapper implements ParameterizedRowMapper<PlayerSummary> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
|
||||
*/
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
public PlayerSummary mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
|
||||
PlayerSummary summary = new PlayerSummary();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user