public void updateFantasyTeam(FantasyTeam fantasyTeam) {
    // Go through each team reg and update in db.
    Map<Integer, Pair<Integer, Integer>> players = fantasyTeam.getPlayers();

    for (Map.Entry<Integer, Pair<Integer, Integer>> entry : players.entrySet()) {
      int numOfPlayer = entry.getKey();
      int playerId = entry.getValue().getKey();
      int playerPos = entry.getValue().getValue();

      FantasyTeamReg ftr =
          new FantasyTeamReg(fantasyTeam.getFantasyTeamId(), playerId, playerPos, numOfPlayer);

      fantasyTeamRegServiceData.updateFantasyTeamReg(ftr);
    }
  }
  public void addFantasyTeam(FantasyTeam fantasyTeam) {
    JdbcTemplate queryFantasyTeams = new JdbcTemplate(this.getDataSource());
    int userId = fantasyTeam.getUserId();
    String sql1 = "SELECT * FROM fantasyteams WHERE userid = ?";
    boolean hasTeam = true;

    try {
      queryFantasyTeams.queryForObject(sql1, new Object[] {userId}, new FantasyTeamRowMapper());
    } catch (EmptyResultDataAccessException e) {
      hasTeam = false;
    }

    if (!hasTeam) {
      SimpleJdbcInsert insertToFantasyTeams =
          (new SimpleJdbcInsert(this.getDataSource())).withTableName("fantasyteams");

      String sql2 = "SELECT MAX(fantasyteamid) FROM fantasyteams";

      int nextId = 1;
      try {
        nextId += queryFantasyTeams.queryForObject(sql2, Integer.class);
      } catch (NullPointerException ignored) {
      }

      Map<String, Object> fantasyteamsParameters = new HashMap<String, Object>(2);
      fantasyteamsParameters.put("fantasyteamid", nextId);
      fantasyteamsParameters.put("userid", fantasyTeam.getUserId());

      try {
        insertToFantasyTeams.execute(fantasyteamsParameters);
      } catch (DataIntegrityViolationException dive) {
        this.log.warning(dive.getMessage());
      }

      for (int i = 1; i <= 11; ++i) {
        FantasyTeamReg reg = new FantasyTeamReg(nextId, 0, 0, i);
        fantasyTeamRegServiceData.addFantasyTeamReg(reg);
      }
    }
  }