Пример #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());
  }
Пример #2
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);
    }
  }
Пример #3
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()));
   }
 }