Skip to content
Snippets Groups Projects
Commit e97c9a45 authored by Mic's avatar Mic
Browse files

removed Autowiring at the field level

(feedback from Oliver Gierke)
parent 74eb3e72
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
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;
@Autowired
private OwnerRepository ownerRepository;
private OwnerRepository ownerRepository;
private VisitRepository visitRepository;
@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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment