mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-16 12:55:50 +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;
|
private VisitRepository visitRepository;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||||
|
|
||||||
private SimpleJdbcInsert insertOwner;
|
private SimpleJdbcInsert insertOwner;
|
||||||
|
@ -72,9 +70,9 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public Collection<Owner> findByLastName(String lastName) throws DataAccessException {
|
public Collection<Owner> findByLastName(String lastName) throws DataAccessException {
|
||||||
Map<String, Object> params = new HashMap<String, Object>();
|
Map<String, Object> params = new HashMap<String, Object>();
|
||||||
params.put("lastName", lastName + "%");
|
params.put("lastName", lastName);
|
||||||
List<Owner> owners = this.namedParameterJdbcTemplate.query(
|
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,
|
params,
|
||||||
ParameterizedBeanPropertyRowMapper.newInstance(Owner.class)
|
ParameterizedBeanPropertyRowMapper.newInstance(Owner.class)
|
||||||
);
|
);
|
||||||
|
|
|
@ -35,12 +35,14 @@ public class JdbcVetRepositoryImpl implements VetRepository {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JdbcTemplate jdbcTemplate;
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
private final List<Vet> vets = new ArrayList<Vet>();
|
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.
|
* 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.PersistenceContext;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
|
||||||
import org.springframework.samples.petclinic.Owner;
|
import org.springframework.samples.petclinic.Owner;
|
||||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package org.springframework.samples.petclinic.repository.springdatajpa;
|
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.data.repository.Repository;
|
||||||
import org.springframework.samples.petclinic.Owner;
|
import org.springframework.samples.petclinic.Owner;
|
||||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||||
|
@ -10,4 +14,7 @@ import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||||
* @since 15.1.2013
|
* @since 15.1.2013
|
||||||
*/
|
*/
|
||||||
public interface SpringDataOwnerRepository extends OwnerRepository, Repository<Owner, Integer> {
|
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
|
@Service
|
||||||
public class ClinicServiceImpl implements ClinicService {
|
public class ClinicServiceImpl implements ClinicService {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PetRepository petRepository;
|
private PetRepository petRepository;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private VetRepository vetRepository;
|
private VetRepository vetRepository;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private OwnerRepository ownerRepository;
|
private OwnerRepository ownerRepository;
|
||||||
|
private VisitRepository visitRepository;
|
||||||
|
|
||||||
@Autowired
|
@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)
|
@Transactional(readOnly=true)
|
||||||
public Collection<PetType> findPetTypes() throws DataAccessException {
|
public Collection<PetType> findPetTypes() throws DataAccessException {
|
||||||
|
|
Loading…
Reference in a new issue