コード例 #1
0
 /** Loads the {@link Pet} and {@link Visit} data for the supplied {@link Owner}. */
 private void loadPetsAndVisits(final Owner owner) {
   final List<JdbcPet> pets =
       this.simpleJdbcTemplate.query(
           "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE owner_id=?",
           new JdbcPetRowMapper(),
           owner.getId().intValue());
   for (JdbcPet pet : pets) {
     owner.addPet(pet);
     pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId()));
     loadVisits(pet);
   }
 }
コード例 #2
0
 public void loadPetsAndVisits(final Owner owner) {
   Map<String, Object> params = new HashMap<String, Object>();
   params.put("id", owner.getId().intValue());
   final List<JdbcPet> pets =
       this.namedParameterJdbcTemplate.query(
           "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE owner_id=:id",
           params,
           new JdbcPetRowMapper());
   for (JdbcPet pet : pets) {
     owner.addPet(pet);
     pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId()));
     //            List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
     //            for (Visit visit : visits) {
     //                pet.addVisit(visit);
     //            }
   }
 }
コード例 #3
0
 /** Loads the {@link Visit} data for the supplied {@link Pet}. */
 private void loadVisits(JdbcPet pet) {
   final List<Visit> visits =
       this.simpleJdbcTemplate.query(
           "SELECT id, visit_date, description FROM visits WHERE pet_id=?",
           new ParameterizedRowMapper<Visit>() {
             public Visit mapRow(ResultSet rs, int row) throws SQLException {
               Visit visit = new Visit();
               visit.setId(rs.getInt("id"));
               visit.setDate(rs.getTimestamp("visit_date"));
               visit.setDescription(rs.getString("description"));
               return visit;
             }
           },
           pet.getId().intValue());
   for (Visit visit : visits) {
     pet.addVisit(visit);
   }
 }
コード例 #4
0
 @Transactional(readOnly = true)
 public Pet loadPet(int id) throws DataAccessException {
   JdbcPet pet;
   try {
     pet =
         this.simpleJdbcTemplate.queryForObject(
             "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=?",
             new JdbcPetRowMapper(),
             id);
   } catch (EmptyResultDataAccessException ex) {
     throw new ObjectRetrievalFailureException(Pet.class, new Integer(id));
   }
   Owner owner = loadOwner(pet.getOwnerId());
   owner.addPet(pet);
   pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId()));
   loadVisits(pet);
   return pet;
 }
コード例 #5
0
 public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException {
   JdbcPet pet = new JdbcPet();
   pet.setId(rs.getInt("id"));
   pet.setName(rs.getString("name"));
   pet.setBirthDate(rs.getDate("birth_date"));
   pet.setTypeId(rs.getInt("type_id"));
   pet.setOwnerId(rs.getInt("owner_id"));
   return pet;
 }
コード例 #6
0
  public Pet findById(int id) throws DataAccessException {
    JdbcPet pet;
    try {
      Map<String, Object> params = new HashMap<String, Object>();
      params.put("id", id);
      pet =
          this.namedParameterJdbcTemplate.queryForObject(
              "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
              params,
              new JdbcPetRowMapper());
    } catch (EmptyResultDataAccessException ex) {
      throw new ObjectRetrievalFailureException(Pet.class, new Integer(id));
    }
    Owner owner = this.ownerRepository.findById(pet.getOwnerId());
    owner.addPet(pet);
    pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));

    List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
    for (Visit visit : visits) {
      pet.addVisit(visit);
    }
    return pet;
  }