made sure @Transactional is not set on the Repository layer

This commit is contained in:
Mic 2013-02-13 09:37:42 +08:00
parent 4e91b4468e
commit c5ca72e80b
6 changed files with 6 additions and 22 deletions

View file

@ -23,7 +23,6 @@ import org.springframework.samples.petclinic.repository.OwnerRepository;
import org.springframework.samples.petclinic.repository.VisitRepository; import org.springframework.samples.petclinic.repository.VisitRepository;
import org.springframework.samples.petclinic.util.EntityUtils; import org.springframework.samples.petclinic.util.EntityUtils;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
/** /**
* A simple JDBC-based implementation of the {@link OwnerRepository} interface. * A simple JDBC-based implementation of the {@link OwnerRepository} interface.
@ -67,7 +66,6 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
* the {@link Pet Pets} and {@link Visit Visits} for the corresponding * the {@link Pet Pets} and {@link Visit Visits} for the corresponding
* owners, if not already loaded. * owners, if not already loaded.
*/ */
@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+"%");
@ -85,7 +83,6 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
* the {@link Pet Pets} and {@link Visit Visits} for the corresponding * the {@link Pet Pets} and {@link Visit Visits} for the corresponding
* owner, if not already loaded. * owner, if not already loaded.
*/ */
@Transactional(readOnly = true)
public Owner findById(int id) throws DataAccessException { public Owner findById(int id) throws DataAccessException {
Owner owner; Owner owner;
try { try {
@ -122,9 +119,6 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
} }
} }
@Transactional
public void save(Owner owner) throws DataAccessException { public void save(Owner owner) throws DataAccessException {
BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(owner); BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(owner);
if (owner.isNew()) { if (owner.isNew()) {
@ -139,11 +133,6 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
} }
} }
@Transactional(readOnly = true)
public Collection<PetType> getPetTypes() throws DataAccessException { public Collection<PetType> getPetTypes() throws DataAccessException {
return this.namedParameterJdbcTemplate.query( return this.namedParameterJdbcTemplate.query(
"SELECT id, name FROM types ORDER BY name", new HashMap<String,Object>(), "SELECT id, name FROM types ORDER BY name", new HashMap<String,Object>(),

View file

@ -19,7 +19,6 @@ import org.springframework.samples.petclinic.model.Vet;
import org.springframework.samples.petclinic.repository.VetRepository; import org.springframework.samples.petclinic.repository.VetRepository;
import org.springframework.samples.petclinic.util.EntityUtils; import org.springframework.samples.petclinic.util.EntityUtils;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
/** /**
* *
@ -49,7 +48,6 @@ public class JdbcVetRepositoryImpl implements VetRepository {
* @see org.springframework.samples.petclinic.model.service.ClinicService#findVets() * @see org.springframework.samples.petclinic.model.service.ClinicService#findVets()
*/ */
@ManagedOperation @ManagedOperation
@Transactional(readOnly = true)
public void refreshVetsCache() throws DataAccessException { public void refreshVetsCache() throws DataAccessException {
synchronized (this.vets) { synchronized (this.vets) {
this.logger.info("Refreshing vets cache"); this.logger.info("Refreshing vets cache");

View file

@ -42,13 +42,11 @@ public class ClinicServiceImpl implements ClinicService {
return ownerRepository.findById(id); return ownerRepository.findById(id);
} }
@Override
@Transactional(readOnly=true) @Transactional(readOnly=true)
public Collection<Owner> findOwnerByLastName(String lastName) throws DataAccessException { public Collection<Owner> findOwnerByLastName(String lastName) throws DataAccessException {
return ownerRepository.findByLastName(lastName); return ownerRepository.findByLastName(lastName);
} }
@Override
@Transactional @Transactional
public void saveOwner(Owner owner) throws DataAccessException { public void saveOwner(Owner owner) throws DataAccessException {
ownerRepository.save(owner); ownerRepository.save(owner);

View file

@ -80,16 +80,14 @@ import org.springframework.transaction.annotation.Transactional;
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen * @author Sam Brannen
* * @author Michael Isvy
*/ */
public abstract class AbstractOwnerRepositoryTests { public abstract class AbstractOwnerRepositoryTests {
@Autowired @Autowired
protected OwnerRepository ownerRepository; protected OwnerRepository ownerRepository;
@Test @Transactional
@Test
public void findOwners() { public void findOwners() {
Collection<Owner> owners = this.ownerRepository.findByLastName("Davis"); Collection<Owner> owners = this.ownerRepository.findByLastName("Davis");
assertEquals(2, owners.size()); assertEquals(2, owners.size());

View file

@ -96,7 +96,7 @@ public abstract class AbstractPetRepositoryTests {
protected OwnerRepository ownerRepository; protected OwnerRepository ownerRepository;
@Test @Test @Transactional
public void getPetTypes() { public void getPetTypes() {
Collection<PetType> petTypes = this.petRepository.findPetTypes(); Collection<PetType> petTypes = this.petRepository.findPetTypes();
@ -106,7 +106,7 @@ public abstract class AbstractPetRepositoryTests {
assertEquals("snake", petType4.getName()); assertEquals("snake", petType4.getName());
} }
@Test @Test @Transactional
public void findPet() { public void findPet() {
Collection<PetType> types = this.petRepository.findPetTypes(); Collection<PetType> types = this.petRepository.findPetTypes();
Pet pet7 = this.petRepository.findById(7); Pet pet7 = this.petRepository.findById(7);

View file

@ -6,6 +6,7 @@ import static org.junit.Assert.assertNull;
import org.junit.Test; import org.junit.Test;
import org.springframework.samples.petclinic.model.Owner; import org.springframework.samples.petclinic.model.Owner;
import org.springframework.samples.petclinic.model.Pet; import org.springframework.samples.petclinic.model.Pet;
import org.springframework.transaction.annotation.Transactional;
/** /**
* JUnit test for the {@link Owner} class. * JUnit test for the {@link Owner} class.
@ -14,7 +15,7 @@ import org.springframework.samples.petclinic.model.Pet;
*/ */
public class OwnerTests { public class OwnerTests {
@Test @Test @Transactional
public void testHasPet() { public void testHasPet() {
Owner owner = new Owner(); Owner owner = new Owner();
Pet fido = new Pet(); Pet fido = new Pet();