From c5ca72e80bf66260e872737957fdaf14a04b638e Mon Sep 17 00:00:00 2001
From: Mic <misvy@vmware.com>
Date: Wed, 13 Feb 2013 09:37:42 +0800
Subject: [PATCH] made sure @Transactional is not set on the Repository layer

---
 .../repository/jdbc/JdbcOwnerRepositoryImpl.java      | 11 -----------
 .../repository/jdbc/JdbcVetRepositoryImpl.java        |  2 --
 .../samples/petclinic/service/ClinicServiceImpl.java  |  2 --
 .../petclinic/AbstractOwnerRepositoryTests.java       |  6 ++----
 .../samples/petclinic/AbstractPetRepositoryTests.java |  4 ++--
 .../springframework/samples/petclinic/OwnerTests.java |  3 ++-
 6 files changed, 6 insertions(+), 22 deletions(-)

diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java
index 2714759..32ad210 100644
--- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java
+++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java
@@ -23,7 +23,6 @@ import org.springframework.samples.petclinic.repository.OwnerRepository;
 import org.springframework.samples.petclinic.repository.VisitRepository;
 import org.springframework.samples.petclinic.util.EntityUtils;
 import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
 
 /**
  * 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
 	 * owners, if not already loaded.
 	 */
-	@Transactional(readOnly = true)
 	public Collection<Owner> findByLastName(String lastName) throws DataAccessException {
 		Map<String, Object> params = new HashMap<String, Object>();
 		params.put("lastName", lastName+"%");
@@ -85,7 +83,6 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
 	 * the {@link Pet Pets} and {@link Visit Visits} for the corresponding
 	 * owner, if not already loaded.
 	 */
-	@Transactional(readOnly = true)
 	public Owner findById(int id) throws DataAccessException {
 		Owner owner;
 		try {
@@ -122,9 +119,6 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
 		}
 	}
 
-	
-
-	@Transactional
 	public void save(Owner owner) throws DataAccessException {
 		BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(owner);
 		if (owner.isNew()) {
@@ -139,11 +133,6 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
 		}
 	}
 
-	
-
-
-	
-	@Transactional(readOnly = true)
 	public Collection<PetType> getPetTypes() throws DataAccessException {
 		return this.namedParameterJdbcTemplate.query(
 				"SELECT id, name FROM types ORDER BY name", new HashMap<String,Object>(),
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java
index 1afaf8f..d97f484 100644
--- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java
+++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java
@@ -19,7 +19,6 @@ import org.springframework.samples.petclinic.model.Vet;
 import org.springframework.samples.petclinic.repository.VetRepository;
 import org.springframework.samples.petclinic.util.EntityUtils;
 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()
 	 */
 	@ManagedOperation
-	@Transactional(readOnly = true)
 	public void refreshVetsCache() throws DataAccessException {
 		synchronized (this.vets) {
 			this.logger.info("Refreshing vets cache");
diff --git a/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java b/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java
index 3cee859..aa08a83 100644
--- a/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java
+++ b/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java
@@ -42,13 +42,11 @@ public class ClinicServiceImpl implements ClinicService {
 		return ownerRepository.findById(id);
 	}
 	
-	@Override
 	@Transactional(readOnly=true)
 	public Collection<Owner> findOwnerByLastName(String lastName) throws DataAccessException {
 		return ownerRepository.findByLastName(lastName);
 	}
 
-	@Override
 	@Transactional
 	public void saveOwner(Owner owner) throws DataAccessException {
 		ownerRepository.save(owner);
diff --git a/src/test/java/org/springframework/samples/petclinic/AbstractOwnerRepositoryTests.java b/src/test/java/org/springframework/samples/petclinic/AbstractOwnerRepositoryTests.java
index c3e4c65..e274d38 100644
--- a/src/test/java/org/springframework/samples/petclinic/AbstractOwnerRepositoryTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/AbstractOwnerRepositoryTests.java
@@ -80,16 +80,14 @@ import org.springframework.transaction.annotation.Transactional;
  * @author Rod Johnson
  * @author Juergen Hoeller
  * @author Sam Brannen
+ *  * @author Michael Isvy
  */
 public abstract class AbstractOwnerRepositoryTests {
 
 	@Autowired
 	protected OwnerRepository ownerRepository;
 
-
-
-
-	@Test
+	@Test @Transactional
 	public void findOwners() {
 		Collection<Owner> owners = this.ownerRepository.findByLastName("Davis");
 		assertEquals(2, owners.size());
diff --git a/src/test/java/org/springframework/samples/petclinic/AbstractPetRepositoryTests.java b/src/test/java/org/springframework/samples/petclinic/AbstractPetRepositoryTests.java
index c9920d5..fce671d 100644
--- a/src/test/java/org/springframework/samples/petclinic/AbstractPetRepositoryTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/AbstractPetRepositoryTests.java
@@ -96,7 +96,7 @@ public abstract class AbstractPetRepositoryTests {
 	protected OwnerRepository ownerRepository;
 
 
-	@Test
+	@Test  @Transactional
 	public void getPetTypes() {
 		Collection<PetType> petTypes = this.petRepository.findPetTypes();
 		
@@ -106,7 +106,7 @@ public abstract class AbstractPetRepositoryTests {
 		assertEquals("snake", petType4.getName());
 	}
 
-	@Test
+	@Test  @Transactional
 	public void findPet() {
 		Collection<PetType> types = this.petRepository.findPetTypes();
 		Pet pet7 = this.petRepository.findById(7);
diff --git a/src/test/java/org/springframework/samples/petclinic/OwnerTests.java b/src/test/java/org/springframework/samples/petclinic/OwnerTests.java
index 5fc0d95..c49c200 100644
--- a/src/test/java/org/springframework/samples/petclinic/OwnerTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/OwnerTests.java
@@ -6,6 +6,7 @@ import static org.junit.Assert.assertNull;
 import org.junit.Test;
 import org.springframework.samples.petclinic.model.Owner;
 import org.springframework.samples.petclinic.model.Pet;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * JUnit test for the {@link Owner} class.
@@ -14,7 +15,7 @@ import org.springframework.samples.petclinic.model.Pet;
  */
 public class OwnerTests {
 
-	@Test
+	@Test @Transactional
 	public void testHasPet() {
 		Owner owner = new Owner();
 		Pet fido = new Pet();
-- 
GitLab