public Object process(InvocableMap.Entry entry) {
   Vet vet = (Vet) entry.getValue();
   if (vet.getSpecialties().contains(specialty)) {
     return false;
   }
   vet.addSpecialty(specialty);
   return true;
 }
Пример #2
0
  /**
   * Refresh the cache of Vets that the Clinic is holding.
   *
   * @see org.springframework.samples.petclinic.Clinic#getVets()
   */
  @ManagedOperation
  @Transactional(readOnly = true)
  public void refreshVetsCache() throws DataAccessException {
    synchronized (this.vets) {
      this.logger.info("Refreshing vets cache");

      // Retrieve the list of all vets.
      this.vets.clear();
      this.vets.addAll(
          this.simpleJdbcTemplate.query(
              "SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
              ParameterizedBeanPropertyRowMapper.newInstance(Vet.class)));

      // Retrieve the list of all possible specialties.
      final List<Specialty> specialties =
          this.simpleJdbcTemplate.query(
              "SELECT id, name FROM specialties",
              ParameterizedBeanPropertyRowMapper.newInstance(Specialty.class));

      // Build each vet's list of specialties.
      for (Vet vet : this.vets) {
        final List<Integer> vetSpecialtiesIds =
            this.simpleJdbcTemplate.query(
                "SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
                new ParameterizedRowMapper<Integer>() {
                  public Integer mapRow(ResultSet rs, int row) throws SQLException {
                    return Integer.valueOf(rs.getInt(1));
                  }
                },
                vet.getId().intValue());
        for (int specialtyId : vetSpecialtiesIds) {
          Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
          vet.addSpecialty(specialty);
        }
      }
    }
  }