Example #1
0
  @Override
  public void delete(Long id) {
    // delete associated entries from TEAM and TEAM_PERSON tables, but not from the PERSON table
    Team team = get(id);
    if (team == null) return;

    for (Person p : team.getMembers()) {
      teamPersonDao.delete(new TeamPerson(team.getId(), p.getId()));
    }
    teamDao.delete(team.getId());
  }
Example #2
0
 @Override
 public Team save(final Team team) {
   long id;
   if (team.getId() == null) {
     id = insertWithTxCallback(team);
   } else {
     id = update(team);
   }
   return get(id);
 }
Example #3
0
  public Team insertWithTxHandle(final Team team) {
    // in this case we use an explicit handle, and attach the dao's to the same handle (connection)
    try (Handle handle = jdbiHelper.getTxHandle()) {
      handle.begin();
      TeamDao teamDao = handle.attach(TeamDao.class);
      TeamPersonDao teamPersonDao =
          handle.attach(TeamPersonDao.class); // team->person mapping table

      long teamId;
      if (team.getPointOfContact() != null) {
        teamId = teamDao.insertWithPoC(team);
      } else {
        teamId = teamDao.insertWithoutPoC(team);
      }
      for (Person p : team.getMembers()) {
        // update the team->person mapping table
        teamPersonDao.insert(new TeamPerson(teamId, p.getId()));
      }
      // add test code for checking that TX is handled correctly
      checkIfTxShouldBeRolledBack(team);
      handle.commit();
      return get(teamId);
    }
  }
Example #4
0
 private void getTeamMembers(Team team, TeamPersonDao teamPersonDao, PersonDao personDao) {
   List<TeamPerson> teamPersonList = teamPersonDao.findByTeamId(team.getId());
   for (TeamPerson tp : teamPersonList) {
     team.addMember(personDao.get(tp.getPersonId()));
   }
 }
Example #5
0
 static void checkIfTxShouldBeRolledBack(Team team) {
   if (team.getName().equals("FAIL")) {
     throw new IllegalStateException("Name of team was FAIL");
   }
 }