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

made sure @Transactional is not set on the Repository layer

parent 4e91b446
No related branches found
No related tags found
No related merge requests found
......@@ -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>(),
......
......@@ -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");
......
......@@ -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);
......
......@@ -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());
......
......@@ -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);
......
......@@ -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();
......
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