IN PROGRESS - BATCH-672: modified advice and dao tests. Modified AbstractBatchLauncherTests base class to use JUnit4

This commit is contained in:
trisberg
2008-07-22 18:01:43 +00:00
parent f777e62736
commit 4f55f8d970
43 changed files with 774 additions and 399 deletions

View File

@@ -18,6 +18,11 @@ package org.springframework.batch.sample.dao;
import org.springframework.batch.sample.domain.CustomerDebit;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.simple.SimpleJdbcOperations;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import javax.sql.DataSource;
/**
@@ -29,15 +34,15 @@ public class JdbcCustomerDebitDao implements CustomerDebitDao {
private static final String UPDATE_CREDIT = "UPDATE customer SET credit= credit-? WHERE name=?";
private JdbcOperations jdbcTemplate;
private SimpleJdbcOperations simpleJdbcTemplate;
public void write(CustomerDebit customerDebit) {
jdbcTemplate.update(UPDATE_CREDIT,
new Object[] { customerDebit.getDebit(), customerDebit.getName() });
simpleJdbcTemplate.update(UPDATE_CREDIT, customerDebit.getDebit(), customerDebit.getName());
}
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
}
}

View File

@@ -4,31 +4,45 @@ import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.sample.domain.Game;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
public class JdbcGameDao extends JdbcDaoSupport implements ItemWriter<Game> {
public class JdbcGameDao extends SimpleJdbcDaoSupport implements ItemWriter<Game> {
private static final String INSERT_GAME = "INSERT into GAMES(player_id,year_no,team,week,opponent,"
+ "completes,attempts,passing_yards,passing_td,interceptions,rushes,rush_yards,"
+ "receptions,receptions_yards,total_td) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
private SimpleJdbcInsert insertGame;
protected void initDao() throws Exception {
super.initDao();
insertGame = new SimpleJdbcInsert(getDataSource())
.withTableName("GAMES")
.usingColumns("player_id", "year_no", "team", "week", "opponent", " completes", "attempts",
"passing_yards", "passing_td", "interceptions", "rushes", "rush_yards", "receptions",
"receptions_yards", "total_td");
}
public void write(Game game) {
SqlParameterSource values = new MapSqlParameterSource()
.addValue("player_id", game.getId())
.addValue("year_no", game.getYear())
.addValue("team", game.getTeam())
.addValue("week", game.getWeek())
.addValue("opponent", game.getOpponent())
.addValue("completes", game.getCompletes())
.addValue("attempts", game.getAttempts())
.addValue("passing_yards", game.getPassingYards())
.addValue("passing_td", game.getPassingTd())
.addValue("interceptions", game.getInterceptions())
.addValue("rushes", game.getRushes())
.addValue("rush_yards", game.getRushYards())
.addValue("receptions", game.getReceptions())
.addValue("receptions_yards", game.getReceptionYards())
.addValue("total_td", game.getTotalTd());
this.insertGame.execute(values);
Object[] args = new Object[] { game.getId(),
new Integer(game.getYear()), game.getTeam(),
new Integer(game.getWeek()), game.getOpponent(),
new Integer(game.getCompletes()),
new Integer(game.getAttempts()),
new Integer(game.getPassingYards()),
new Integer(game.getPassingTd()),
new Integer(game.getInterceptions()),
new Integer(game.getRushes()),
new Integer(game.getRushYards()),
new Integer(game.getReceptions()),
new Integer(game.getReceptionYards()),
new Integer(game.getTotalTd()) };
this.getJdbcTemplate().update(INSERT_GAME, args);
}
public void clear() throws ClearFailedException {

View File

@@ -18,7 +18,6 @@ package org.springframework.batch.sample.item.writer;
import org.springframework.batch.item.support.AbstractItemWriter;
import org.springframework.batch.sample.dao.CustomerDebitDao;
import org.springframework.batch.sample.dao.JdbcCustomerDebitDao;
import org.springframework.batch.sample.domain.CustomerDebit;
import org.springframework.batch.sample.domain.Trade;
@@ -29,7 +28,8 @@ import org.springframework.batch.sample.domain.Trade;
* @author Robert Kasanicky
*/
public class CustomerUpdateWriter extends AbstractItemWriter {
private CustomerDebitDao dao;
private CustomerDebitDao dao;
public void write(Object data) {
Trade trade = (Trade) data;
@@ -39,7 +39,7 @@ public class CustomerUpdateWriter extends AbstractItemWriter {
dao.write(customerDebit);
}
public void setDao(JdbcCustomerDebitDao outputSource) {
public void setDao(CustomerDebitDao outputSource) {
this.dao = outputSource;
}
}