@Override
 public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
   Map<String, Match> matches = new HashMap<String, Match>();
   Match match = null;
   String key = null;
   while (rs.next()) {
     match = new Match();
     match.setMatchId(rs.getInt("MATCH_ID"));
     match.setLeagueName(rs.getString("LEAGUE_NAME").trim());
     match.setLeagueId(rs.getInt("LEAGUE_ID"));
     match.setHomeTeamName(rs.getString("HOME_TEAM_NAME").trim());
     match.setAwayTeamName(rs.getString("AWAY_TEAM_NAME").trim());
     match.setHomeScore(rs.getInt("HOME_SCORE"));
     match.setAwayScore(rs.getInt("AWAY_SCORE"));
     match.setHomeTeamId(rs.getInt("HOME_TEAM_ID"));
     match.setAwayTeamId(rs.getInt("AWAY_TEAM_ID"));
     match.setFeedTypeId(rs.getInt("FEED_TYPE_ID"));
     match.setMatchTime(rs.getString("MATCH_TIME").trim());
     match.setRunningIndicator(rs.getInt("RUNNING_INDICATOR"));
     match.setTimeGameLive(rs.getString("TIME_GAME_LIVE").trim());
     match.setKoAwayPrice(rs.getDouble("KICK_OFF_AWAY_PRICE"));
     match.setKoDrawPrice(rs.getDouble("KICK_OFF_DRAW_PRICE"));
     match.setKoHomePrice(rs.getDouble("KICK_OFF_HOME_PRICE"));
     match.setKoOuHfPrice(rs.getDouble("KICK_OFF_OU_HF_PRICE"));
     match.setTimeFirstGoal(rs.getInt("TIME_FIRST_GOAL"));
     match.setMatchDate(new DateTime(rs.getDate("MATCH_DATE")));
     match.setBookieId(rs.getInt("BOOKIE_ID"));
     key = String.valueOf(match.getMatchId()) + "|" + rs.getString("NAME").trim();
     matches.put(key, match);
   }
   return matches;
 }
 private Match exists(Match match) {
   try {
     Map<String, Object> paramMap = new HashMap<String, Object>();
     paramMap.put("matchId", match.getMatchId());
     paramMap.put("bookieId", match.getBookieId());
     paramMap.put("feedTypeId", match.getFeedTypeId());
     return jdbcTemplate.queryForObject(READ_EXISTS_SQL, paramMap, matchRowMapper);
   } catch (EmptyResultDataAccessException e) {
     return null;
   }
 }
  @Override
  public void createMatch(Match match) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(String.format("createMatch(match=%s)", match.toString()));
    }
    Match dbMatch = exists(match);
    if (dbMatch == null) {
      if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Creating Match key - " + match.toString());
      }
      try {
        /** Create match. */
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("matchId", match.getMatchId());
        paramMap.put("leagueName", match.getLeagueName());
        paramMap.put("homeTeamName", match.getHomeTeamName());
        paramMap.put("awayTeamName", match.getAwayTeamName());
        paramMap.put("matchTime", match.getMatchTime());
        paramMap.put("runningInd", match.getRunningIndicator());
        paramMap.put("homeScore", match.getHomeScore());
        paramMap.put("awayScore", match.getAwayScore());
        paramMap.put("timeGameLive", match.getTimeGameLive());
        paramMap.put("leagueId", match.getLeagueId());
        paramMap.put("homeTeamId", match.getHomeTeamId());
        paramMap.put("awayTeamId", match.getAwayTeamId());
        paramMap.put("feedTypeId", match.getFeedTypeId());
        paramMap.put("timeFirstGoal", match.getTimeFirstGoal());
        paramMap.put("kickOffHomePrice", match.getKoHomePrice());
        paramMap.put("kickOffAwayPrice", match.getKoAwayPrice());
        paramMap.put("kickOffOuHfPrice", match.getKoOuHfPrice());
        paramMap.put("kickOffDrawPrice", match.getKoDrawPrice());
        paramMap.put("matchDate", new java.sql.Date(match.getMatchDate().getMillis()));
        paramMap.put("bookieId", match.getBookieId());
        paramMap.put("ouHfHandicap", match.getOuHandicapValue());

        jdbcTemplate.update(INSERT_SQL, paramMap);

        /** Create match minutes for each bookie with odds on the match. */
        matchTimeDao.createMatchTime(
            match.getMatchId(), match.getFeedTypeId(), match.getBookieId());
      } catch (Exception e) {
        LOGGER.info("Exception=" + e.getMessage());
      }
    } else {
      /** Has match started? */
      if (dbMatch.getRunningIndicator().intValue() == 0) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("matchId", match.getMatchId());
        paramMap.put("feedTypeId", match.getFeedTypeId());
        paramMap.put("bookieId", match.getBookieId());

        if (hasPriceChanged(match.getKoHomePrice(), dbMatch.getKoHomePrice())) {
          if (LOGGER.isInfoEnabled()) {
            LOGGER.info(
                "Update Home Price "
                    + dbMatch.getKoHomePrice()
                    + " for Match - "
                    + match.toString());
          }
          paramMap.put("homePrice", match.getKoHomePrice());
          jdbcTemplate.update(UPDATE_KO_HOME_PRICE_SQL, paramMap);
        }
        if (hasPriceChanged(match.getKoAwayPrice(), dbMatch.getKoAwayPrice())) {
          if (LOGGER.isInfoEnabled()) {
            LOGGER.info(
                "Update Away Price "
                    + dbMatch.getKoAwayPrice()
                    + " for Match - "
                    + match.toString());
          }
          paramMap.put("awayPrice", match.getKoAwayPrice());
          jdbcTemplate.update(UPDATE_KO_AWAY_PRICE_SQL, paramMap);
        }
        if (hasPriceChanged(match.getKoDrawPrice(), dbMatch.getKoDrawPrice())) {
          if (LOGGER.isInfoEnabled()) {
            LOGGER.info(
                "Update Draw Price "
                    + dbMatch.getKoDrawPrice()
                    + " for Match - "
                    + match.toString());
          }
          paramMap.put("drawPrice", match.getKoDrawPrice());
          jdbcTemplate.update(UPDATE_KO_DRAW_PRICE_SQL, paramMap);
        }
        if (hasPriceChanged(match.getKoOuHfPrice(), dbMatch.getKoOuHfPrice())) {
          if (LOGGER.isInfoEnabled()) {
            LOGGER.info(
                "Update OU HT 0.5 Price "
                    + dbMatch.getKoOuHfPrice()
                    + " for Match - "
                    + match.toString());
          }
          paramMap.put("ouHfPrice", match.getKoOuHfPrice());
          jdbcTemplate.update(UPDATE_KO_UOHT_PRICE_SQL, paramMap);
        }
      }
    }
  }