1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.batch.sample.domain.football.internal;
18
19 import java.util.List;
20
21 import org.springframework.batch.item.ItemWriter;
22 import org.springframework.batch.sample.domain.football.Game;
23 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
24 import org.springframework.jdbc.core.namedparam.SqlParameterSource;
25 import org.springframework.jdbc.core.support.JdbcDaoSupport;
26 import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
27
28 public class JdbcGameDao extends JdbcDaoSupport implements ItemWriter<Game> {
29
30 private SimpleJdbcInsert insertGame;
31
32 protected void initDao() throws Exception {
33 super.initDao();
34 insertGame = new SimpleJdbcInsert(getDataSource()).withTableName("GAMES").usingColumns("player_id", "year_no",
35 "team", "week", "opponent", " completes", "attempts", "passing_yards", "passing_td", "interceptions",
36 "rushes", "rush_yards", "receptions", "receptions_yards", "total_td");
37 }
38
39 public void write(List<? extends Game> games) {
40
41 for (Game game : games) {
42
43 SqlParameterSource values = new MapSqlParameterSource().addValue("player_id", game.getId()).addValue(
44 "year_no", game.getYear()).addValue("team", game.getTeam()).addValue("week", game.getWeek())
45 .addValue("opponent", game.getOpponent()).addValue("completes", game.getCompletes()).addValue(
46 "attempts", game.getAttempts()).addValue("passing_yards", game.getPassingYards()).addValue(
47 "passing_td", game.getPassingTd()).addValue("interceptions", game.getInterceptions())
48 .addValue("rushes", game.getRushes()).addValue("rush_yards", game.getRushYards()).addValue(
49 "receptions", game.getReceptions()).addValue("receptions_yards", game.getReceptionYards())
50 .addValue("total_td", game.getTotalTd());
51 this.insertGame.execute(values);
52
53 }
54
55 }
56
57 }