mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:35:49 +00:00
removed Autowiring at the field level
(feedback from Oliver Gierke)
This commit is contained in:
parent
74eb3e72fe
commit
e97c9a45d4
5 changed files with 23 additions and 16 deletions
|
@ -41,8 +41,6 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
|||
|
||||
private VisitRepository visitRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||
|
||||
private SimpleJdbcInsert insertOwner;
|
||||
|
@ -72,9 +70,9 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
|||
@Transactional(readOnly = true)
|
||||
public Collection<Owner> findByLastName(String lastName) throws DataAccessException {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("lastName", lastName + "%");
|
||||
params.put("lastName", lastName);
|
||||
List<Owner> owners = this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName",
|
||||
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName%",
|
||||
params,
|
||||
ParameterizedBeanPropertyRowMapper.newInstance(Owner.class)
|
||||
);
|
||||
|
|
|
@ -35,12 +35,14 @@ public class JdbcVetRepositoryImpl implements VetRepository {
|
|||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private final List<Vet> vets = new ArrayList<Vet>();
|
||||
|
||||
|
||||
@Autowired
|
||||
public JdbcVetRepositoryImpl(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the cache of Vets that the ClinicService is holding.
|
||||
|
|
|
@ -6,7 +6,6 @@ import javax.persistence.EntityManager;
|
|||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.samples.petclinic.Owner;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
@ -29,7 +28,7 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository {
|
|||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<Owner> findByLastName(String lastName) {
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package org.springframework.samples.petclinic.repository.springdatajpa;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.samples.petclinic.Owner;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
|
@ -10,4 +14,7 @@ import org.springframework.samples.petclinic.repository.OwnerRepository;
|
|||
* @since 15.1.2013
|
||||
*/
|
||||
public interface SpringDataOwnerRepository extends OwnerRepository, Repository<Owner, Integer> {
|
||||
|
||||
@Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%")
|
||||
Collection<Owner> findByLastName(String lastName) throws DataAccessException;
|
||||
}
|
||||
|
|
|
@ -19,17 +19,18 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
@Service
|
||||
public class ClinicServiceImpl implements ClinicService {
|
||||
|
||||
@Autowired
|
||||
private PetRepository petRepository;
|
||||
|
||||
@Autowired
|
||||
private VetRepository vetRepository;
|
||||
|
||||
private OwnerRepository ownerRepository;
|
||||
private VisitRepository visitRepository;
|
||||
|
||||
@Autowired
|
||||
private OwnerRepository ownerRepository;
|
||||
|
||||
@Autowired
|
||||
private VisitRepository visitRepository;
|
||||
public ClinicServiceImpl(PetRepository petRepository, VetRepository vetRepository, OwnerRepository ownerRepository, VisitRepository visitRepository) {
|
||||
this.petRepository = petRepository;
|
||||
this.vetRepository = vetRepository;
|
||||
this.ownerRepository = ownerRepository;
|
||||
this.visitRepository = visitRepository;
|
||||
}
|
||||
|
||||
@Transactional(readOnly=true)
|
||||
public Collection<PetType> findPetTypes() throws DataAccessException {
|
||||
|
|
Loading…
Reference in a new issue