/** 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); } }
@Transactional public void storeOwner(Owner owner) throws DataAccessException { if (owner.isNew()) { Number newKey = this.insertOwner.executeAndReturnKey(new BeanPropertySqlParameterSource(owner)); owner.setId(newKey.intValue()); } else { this.simpleJdbcTemplate.update( "UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " + "city=:city, telephone=:telephone WHERE id=:id", new BeanPropertySqlParameterSource(owner)); } }
@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; }