mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-16 04:35:49 +00:00
added a Spring Data implementation
- there are now 3 data access implementations (jdbc, jpa and spring-data-jpa) - added corresponding bean profiles - JUnit tests are now successful
This commit is contained in:
parent
c9c8c4e085
commit
97aba3f4e6
50 changed files with 368 additions and 426 deletions
|
@ -2,7 +2,6 @@ package org.springframework.samples.petclinic;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.samples.petclinic;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.aspects;
|
|
||||||
|
|
||||||
import org.aspectj.lang.JoinPoint;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
|
||||||
import org.aspectj.lang.annotation.Before;
|
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aspect to illustrate Spring-driven load-time weaving.
|
|
||||||
*
|
|
||||||
* @author Ramnivas Laddad
|
|
||||||
* @since 2.5
|
|
||||||
*/
|
|
||||||
@Aspect
|
|
||||||
public abstract class AbstractTraceAspect {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AbstractTraceAspect.class);
|
|
||||||
|
|
||||||
@Pointcut
|
|
||||||
public abstract void traced();
|
|
||||||
|
|
||||||
@Before("traced()")
|
|
||||||
public void trace(JoinPoint.StaticPart jpsp) {
|
|
||||||
if (logger.isTraceEnabled()) {
|
|
||||||
logger.trace("Entering " + jpsp.getSignature().toLongString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -2,11 +2,8 @@ package org.springframework.samples.petclinic.aspects;
|
||||||
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
|
||||||
|
|
||||||
import org.springframework.jmx.export.annotation.ManagedAttribute;
|
import org.springframework.jmx.export.annotation.ManagedAttribute;
|
||||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
|
||||||
import org.springframework.util.StopWatch;
|
import org.springframework.util.StopWatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,8 +14,8 @@ import org.springframework.util.StopWatch;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
*/
|
*/
|
||||||
@ManagedResource("petclinic:type=CallMonitor")
|
//@ManagedResource("petclinic:type=CallMonitor")
|
||||||
@Aspect
|
//@Aspect
|
||||||
public class CallMonitoringAspect {
|
public class CallMonitoringAspect {
|
||||||
|
|
||||||
private boolean isEnabled = true;
|
private boolean isEnabled = true;
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class UsageLogAspect {
|
||||||
this.namesRequested = new ArrayList<String>(historySize);
|
this.namesRequested = new ArrayList<String>(historySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before("execution(* *.findOwners(String)) && args(name)")
|
@Before("execution(* *.find*(String)) && args(name)")
|
||||||
public synchronized void logNameRequest(String name) {
|
public synchronized void logNameRequest(String name) {
|
||||||
// Not the most efficient implementation,
|
// Not the most efficient implementation,
|
||||||
// but we're aiming to illustrate the power of
|
// but we're aiming to illustrate the power of
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
package org.springframework.samples.petclinic.repository;
|
package org.springframework.samples.petclinic.repository;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.samples.petclinic.BaseEntity;
|
import org.springframework.samples.petclinic.BaseEntity;
|
||||||
import org.springframework.samples.petclinic.Owner;
|
|
||||||
import org.springframework.samples.petclinic.Pet;
|
import org.springframework.samples.petclinic.Pet;
|
||||||
import org.springframework.samples.petclinic.PetType;
|
import org.springframework.samples.petclinic.PetType;
|
||||||
import org.springframework.samples.petclinic.Vet;
|
|
||||||
import org.springframework.samples.petclinic.Visit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The high-level PetClinic business interface.
|
* The high-level PetClinic business interface.
|
||||||
|
@ -26,7 +23,7 @@ public interface PetRepository {
|
||||||
* Retrieve all <code>PetType</code>s from the data store.
|
* Retrieve all <code>PetType</code>s from the data store.
|
||||||
* @return a <code>Collection</code> of <code>PetType</code>s
|
* @return a <code>Collection</code> of <code>PetType</code>s
|
||||||
*/
|
*/
|
||||||
Collection<PetType> getPetTypes() throws DataAccessException;
|
List<PetType> findPetTypes() throws DataAccessException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a <code>Pet</code> from the data store by id.
|
* Retrieve a <code>Pet</code> from the data store by id.
|
||||||
|
@ -41,11 +38,6 @@ public interface PetRepository {
|
||||||
* @param pet the <code>Pet</code> to save
|
* @param pet the <code>Pet</code> to save
|
||||||
* @see BaseEntity#isNew
|
* @see BaseEntity#isNew
|
||||||
*/
|
*/
|
||||||
void storePet(Pet pet) throws DataAccessException;
|
void save(Pet pet) throws DataAccessException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes a <code>Pet</code> from the data store.
|
|
||||||
*/
|
|
||||||
void deletePet(int id) throws DataAccessException;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public interface VetRepository {
|
||||||
* Retrieve all <code>Vet</code>s from the data store.
|
* Retrieve all <code>Vet</code>s from the data store.
|
||||||
* @return a <code>Collection</code> of <code>Vet</code>s
|
* @return a <code>Collection</code> of <code>Vet</code>s
|
||||||
*/
|
*/
|
||||||
Collection<Vet> getVets() throws DataAccessException;
|
Collection<Vet> findAll() throws DataAccessException;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ public interface VisitRepository {
|
||||||
* @param visit the <code>Visit</code> to save
|
* @param visit the <code>Visit</code> to save
|
||||||
* @see BaseEntity#isNew
|
* @see BaseEntity#isNew
|
||||||
*/
|
*/
|
||||||
void storeVisit(Visit visit) throws DataAccessException;
|
void save(Visit visit) throws DataAccessException;
|
||||||
|
|
||||||
List<Visit> findByPetId(Integer petId);
|
List<Visit> findByPetId(Integer petId);
|
||||||
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.repository.jdbc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface that defines a cache refresh operation.
|
|
||||||
* To be exposed for management via JMX.
|
|
||||||
*
|
|
||||||
* @author Rob Harrop
|
|
||||||
* @author Juergen Hoeller
|
|
||||||
* @see JdbcClinicImpl
|
|
||||||
*/
|
|
||||||
public interface JdbcClinicImplMBean {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Refresh the cache of Vets that the ClinicService is holding.
|
|
||||||
* @see org.springframework.samples.petclinic.service.ClinicService#getVets()
|
|
||||||
* @see JdbcClinicImpl#refreshVetsCache()
|
|
||||||
*/
|
|
||||||
void refreshVetsCache();
|
|
||||||
|
|
||||||
}
|
|
|
@ -5,8 +5,6 @@ import java.util.List;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.EmptyResultDataAccessException;
|
import org.springframework.dao.EmptyResultDataAccessException;
|
||||||
|
@ -15,7 +13,6 @@ import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
|
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
|
||||||
import org.springframework.orm.ObjectRetrievalFailureException;
|
import org.springframework.orm.ObjectRetrievalFailureException;
|
||||||
import org.springframework.samples.petclinic.Owner;
|
import org.springframework.samples.petclinic.Owner;
|
||||||
import org.springframework.samples.petclinic.Pet;
|
import org.springframework.samples.petclinic.Pet;
|
||||||
|
@ -24,22 +21,13 @@ import org.springframework.samples.petclinic.Visit;
|
||||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
|
||||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
import org.springframework.samples.petclinic.util.EntityUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple JDBC-based implementation of the {@link ClinicService} interface.
|
* A simple JDBC-based implementation of the {@link OwnerRepository} interface.
|
||||||
*
|
*
|
||||||
* <p>This class uses Java 5 language features and the {@link SimpleJdbcTemplate}
|
|
||||||
* plus {@link SimpleJdbcInsert}. It also takes advantage of classes like
|
|
||||||
* {@link BeanPropertySqlParameterSource} and
|
|
||||||
* {@link ParameterizedBeanPropertyRowMapper} which provide automatic mapping
|
|
||||||
* between JavaBean properties and JDBC parameters or query results.
|
|
||||||
*
|
|
||||||
* <p>JdbcClinicImpl is a rewrite of the AbstractJdbcClinic which was the base
|
|
||||||
* class for JDBC implementations of the ClinicService interface for Spring 2.0.
|
|
||||||
*
|
*
|
||||||
* @author Ken Krebs
|
* @author Ken Krebs
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
|
@ -1,54 +1,29 @@
|
||||||
package org.springframework.samples.petclinic.repository.jdbc;
|
package org.springframework.samples.petclinic.repository.jdbc;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.EmptyResultDataAccessException;
|
import org.springframework.dao.EmptyResultDataAccessException;
|
||||||
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
|
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
|
||||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
|
||||||
import org.springframework.orm.ObjectRetrievalFailureException;
|
import org.springframework.orm.ObjectRetrievalFailureException;
|
||||||
import org.springframework.samples.petclinic.Owner;
|
import org.springframework.samples.petclinic.Owner;
|
||||||
import org.springframework.samples.petclinic.Pet;
|
import org.springframework.samples.petclinic.Pet;
|
||||||
import org.springframework.samples.petclinic.PetType;
|
import org.springframework.samples.petclinic.PetType;
|
||||||
import org.springframework.samples.petclinic.Specialty;
|
|
||||||
import org.springframework.samples.petclinic.Vet;
|
|
||||||
import org.springframework.samples.petclinic.Visit;
|
import org.springframework.samples.petclinic.Visit;
|
||||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
|
||||||
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.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple JDBC-based implementation of the {@link ClinicService} interface.
|
|
||||||
*
|
|
||||||
* <p>This class uses Java 5 language features and the {@link SimpleJdbcTemplate}
|
|
||||||
* plus {@link SimpleJdbcInsert}. It also takes advantage of classes like
|
|
||||||
* {@link BeanPropertySqlParameterSource} and
|
|
||||||
* {@link ParameterizedBeanPropertyRowMapper} which provide automatic mapping
|
|
||||||
* between JavaBean properties and JDBC parameters or query results.
|
|
||||||
*
|
|
||||||
* <p>JdbcClinicImpl is a rewrite of the AbstractJdbcClinic which was the base
|
|
||||||
* class for JDBC implementations of the ClinicService interface for Spring 2.0.
|
|
||||||
*
|
*
|
||||||
* @author Ken Krebs
|
* @author Ken Krebs
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
@ -71,9 +46,6 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
||||||
@Autowired
|
@Autowired
|
||||||
private VisitRepository visitRepository;
|
private VisitRepository visitRepository;
|
||||||
|
|
||||||
private final List<Vet> vets = new ArrayList<Vet>();
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void init(DataSource dataSource) {
|
public void init(DataSource dataSource) {
|
||||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
|
@ -84,14 +56,12 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
||||||
.usingGeneratedKeyColumns("id");
|
.usingGeneratedKeyColumns("id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
public List<PetType> findPetTypes() throws DataAccessException {
|
||||||
public Collection<PetType> getPetTypes() throws DataAccessException {
|
|
||||||
return this.jdbcTemplate.query(
|
return this.jdbcTemplate.query(
|
||||||
"SELECT id, name FROM types ORDER BY name",
|
"SELECT id, name FROM types ORDER BY name",
|
||||||
ParameterizedBeanPropertyRowMapper.newInstance(PetType.class));
|
ParameterizedBeanPropertyRowMapper.newInstance(PetType.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public Pet findById(int id) throws DataAccessException {
|
public Pet findById(int id) throws DataAccessException {
|
||||||
JdbcPet pet;
|
JdbcPet pet;
|
||||||
try {
|
try {
|
||||||
|
@ -105,7 +75,7 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
||||||
}
|
}
|
||||||
Owner owner = this.ownerRepository.findById(pet.getOwnerId());
|
Owner owner = this.ownerRepository.findById(pet.getOwnerId());
|
||||||
owner.addPet(pet);
|
owner.addPet(pet);
|
||||||
pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId()));
|
pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));
|
||||||
|
|
||||||
List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
|
List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
|
||||||
for (Visit visit : visits) {
|
for (Visit visit : visits) {
|
||||||
|
@ -114,8 +84,7 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
||||||
return pet;
|
return pet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
public void save(Pet pet) throws DataAccessException {
|
||||||
public void storePet(Pet pet) throws DataAccessException {
|
|
||||||
if (pet.isNew()) {
|
if (pet.isNew()) {
|
||||||
Number newKey = this.insertPet.executeAndReturnKey(
|
Number newKey = this.insertPet.executeAndReturnKey(
|
||||||
createPetParameterSource(pet));
|
createPetParameterSource(pet));
|
||||||
|
@ -142,19 +111,4 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
||||||
.addValue("owner_id", pet.getOwner().getId());
|
.addValue("owner_id", pet.getOwner().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deletePet(int id) throws DataAccessException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the {@link Pet} and {@link Visit} data for the supplied
|
|
||||||
* {@link Owner}.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,46 +6,22 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.EmptyResultDataAccessException;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
|
||||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
||||||
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
|
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
|
||||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
|
||||||
import org.springframework.orm.ObjectRetrievalFailureException;
|
|
||||||
import org.springframework.samples.petclinic.Owner;
|
|
||||||
import org.springframework.samples.petclinic.Pet;
|
|
||||||
import org.springframework.samples.petclinic.PetType;
|
|
||||||
import org.springframework.samples.petclinic.Specialty;
|
import org.springframework.samples.petclinic.Specialty;
|
||||||
import org.springframework.samples.petclinic.Vet;
|
import org.springframework.samples.petclinic.Vet;
|
||||||
import org.springframework.samples.petclinic.Visit;
|
|
||||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
|
||||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
import org.springframework.samples.petclinic.util.EntityUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple JDBC-based implementation of the {@link ClinicService} interface.
|
|
||||||
*
|
|
||||||
* <p>This class uses Java 5 language features and the {@link SimpleJdbcTemplate}
|
|
||||||
* plus {@link SimpleJdbcInsert}. It also takes advantage of classes like
|
|
||||||
* {@link BeanPropertySqlParameterSource} and
|
|
||||||
* {@link ParameterizedBeanPropertyRowMapper} which provide automatic mapping
|
|
||||||
* between JavaBean properties and JDBC parameters or query results.
|
|
||||||
*
|
|
||||||
* <p>JdbcClinicImpl is a rewrite of the AbstractJdbcClinic which was the base
|
|
||||||
* class for JDBC implementations of the ClinicService interface for Spring 2.0.
|
|
||||||
*
|
*
|
||||||
* @author Ken Krebs
|
* @author Ken Krebs
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
@ -68,7 +44,7 @@ public class JdbcVetRepositoryImpl implements VetRepository {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refresh the cache of Vets that the ClinicService is holding.
|
* Refresh the cache of Vets that the ClinicService is holding.
|
||||||
* @see org.springframework.samples.petclinic.service.ClinicService#getVets()
|
* @see org.springframework.samples.petclinic.service.ClinicService#findVets()
|
||||||
*/
|
*/
|
||||||
@ManagedOperation
|
@ManagedOperation
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
|
@ -104,8 +80,7 @@ public class JdbcVetRepositoryImpl implements VetRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
public Collection<Vet> findAll() throws DataAccessException {
|
||||||
public Collection<Vet> getVets() throws DataAccessException {
|
|
||||||
synchronized (this.vets) {
|
synchronized (this.vets) {
|
||||||
if (this.vets.isEmpty()) {
|
if (this.vets.isEmpty()) {
|
||||||
refreshVetsCache();
|
refreshVetsCache();
|
||||||
|
|
|
@ -6,34 +6,20 @@ import java.util.List;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
|
||||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||||
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
|
|
||||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||||
import org.springframework.samples.petclinic.Pet;
|
|
||||||
import org.springframework.samples.petclinic.Visit;
|
import org.springframework.samples.petclinic.Visit;
|
||||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
import org.springframework.samples.petclinic.service.ClinicService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple JDBC-based implementation of the {@link ClinicService} interface.
|
* A simple JDBC-based implementation of the {@link ClinicService} interface.
|
||||||
*
|
*
|
||||||
* <p>This class uses Java 5 language features and the {@link SimpleJdbcTemplate}
|
|
||||||
* plus {@link SimpleJdbcInsert}. It also takes advantage of classes like
|
|
||||||
* {@link BeanPropertySqlParameterSource} and
|
|
||||||
* {@link ParameterizedBeanPropertyRowMapper} which provide automatic mapping
|
|
||||||
* between JavaBean properties and JDBC parameters or query results.
|
|
||||||
*
|
|
||||||
* <p>JdbcClinicImpl is a rewrite of the AbstractJdbcClinic which was the base
|
|
||||||
* class for JDBC implementations of the ClinicService interface for Spring 2.0.
|
|
||||||
*
|
*
|
||||||
* @author Ken Krebs
|
* @author Ken Krebs
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
@ -41,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
|
* @author Michael Isvy
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class JdbcVisitRepositoryImpl implements VisitRepository {
|
public class JdbcVisitRepositoryImpl implements VisitRepository {
|
||||||
|
@ -59,8 +46,7 @@ public class JdbcVisitRepositoryImpl implements VisitRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
public void save(Visit visit) throws DataAccessException {
|
||||||
public void storeVisit(Visit visit) throws DataAccessException {
|
|
||||||
if (visit.isNew()) {
|
if (visit.isNew()) {
|
||||||
Number newKey = this.insertVisit.executeAndReturnKey(
|
Number newKey = this.insertVisit.executeAndReturnKey(
|
||||||
createVisitParameterSource(visit));
|
createVisitParameterSource(visit));
|
||||||
|
@ -75,8 +61,6 @@ public class JdbcVisitRepositoryImpl implements VisitRepository {
|
||||||
this.jdbcTemplate.update("DELETE FROM pets WHERE id=?", id);
|
this.jdbcTemplate.update("DELETE FROM pets WHERE id=?", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// END of ClinicService implementation section ************************************
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link MapSqlParameterSource} based on data values from the
|
* Creates a {@link MapSqlParameterSource} based on data values from the
|
||||||
|
@ -109,23 +93,4 @@ public class JdbcVisitRepositoryImpl implements VisitRepository {
|
||||||
return visits;
|
return visits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link ParameterizedRowMapper} implementation mapping data from a
|
|
||||||
* {@link ResultSet} to the corresponding properties of the {@link JdbcPet} class.
|
|
||||||
*/
|
|
||||||
private class JdbcPetRowMapper implements ParameterizedRowMapper<JdbcPet> {
|
|
||||||
|
|
||||||
public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException {
|
|
||||||
JdbcPet pet = new JdbcPet();
|
|
||||||
pet.setId(rs.getInt("id"));
|
|
||||||
pet.setName(rs.getString("name"));
|
|
||||||
pet.setBirthDate(rs.getDate("birth_date"));
|
|
||||||
pet.setTypeId(rs.getInt("type_id"));
|
|
||||||
pet.setOwnerId(rs.getInt("owner_id"));
|
|
||||||
return pet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.repository.jpa;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.PersistenceContext;
|
|
||||||
import javax.persistence.Query;
|
|
||||||
|
|
||||||
import org.springframework.samples.petclinic.Owner;
|
|
||||||
import org.springframework.samples.petclinic.Pet;
|
|
||||||
import org.springframework.samples.petclinic.PetType;
|
|
||||||
import org.springframework.samples.petclinic.Vet;
|
|
||||||
import org.springframework.samples.petclinic.Visit;
|
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JPA implementation of the ClinicService interface using EntityManager.
|
|
||||||
*
|
|
||||||
* <p>The mappings are defined in "orm.xml" located in the META-INF directory.
|
|
||||||
*
|
|
||||||
* @author Mike Keith
|
|
||||||
* @author Rod Johnson
|
|
||||||
* @author Sam Brannen
|
|
||||||
* @author Michael Isvy
|
|
||||||
* @since 22.4.2006
|
|
||||||
*/
|
|
||||||
@Repository
|
|
||||||
@Transactional
|
|
||||||
public class JpaClinicImpl implements ClinicService {
|
|
||||||
|
|
||||||
@PersistenceContext
|
|
||||||
private EntityManager em;
|
|
||||||
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Collection<Vet> getVets() {
|
|
||||||
return this.em.createQuery("SELECT vet FROM Vet vet ORDER BY vet.lastName, vet.firstName").getResultList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Collection<PetType> getPetTypes() {
|
|
||||||
return this.em.createQuery("SELECT ptype FROM PetType ptype ORDER BY ptype.name").getResultList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Collection<Owner> findOwners(String lastName) {
|
|
||||||
Query query = this.em.createQuery("SELECT owner FROM Owner owner WHERE owner.lastName LIKE :lastName");
|
|
||||||
query.setParameter("lastName", lastName + "%");
|
|
||||||
return query.getResultList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public Owner findOwner(int id) {
|
|
||||||
return this.em.find(Owner.class, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public Pet findPet(int id) {
|
|
||||||
return this.em.find(Pet.class, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void storeOwner(Owner owner) {
|
|
||||||
this.em.merge(owner);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void storePet(Pet pet) {
|
|
||||||
this.em.merge(pet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void storeVisit(Visit visit) {
|
|
||||||
this.em.merge(visit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deletePet(int id) throws DataAccessException {
|
|
||||||
Pet pet = findPet(id);
|
|
||||||
this.em.remove(pet);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -6,12 +6,7 @@ import javax.persistence.EntityManager;
|
||||||
import javax.persistence.PersistenceContext;
|
import javax.persistence.PersistenceContext;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
import org.springframework.samples.petclinic.Owner;
|
import org.springframework.samples.petclinic.Owner;
|
||||||
import org.springframework.samples.petclinic.Pet;
|
|
||||||
import org.springframework.samples.petclinic.PetType;
|
|
||||||
import org.springframework.samples.petclinic.Vet;
|
|
||||||
import org.springframework.samples.petclinic.Visit;
|
|
||||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -35,7 +30,6 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository {
|
||||||
private EntityManager em;
|
private EntityManager em;
|
||||||
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Collection<Owner> findByLastName(String lastName) {
|
public Collection<Owner> findByLastName(String lastName) {
|
||||||
Query query = this.em.createQuery("SELECT owner FROM Owner owner WHERE owner.lastName LIKE :lastName");
|
Query query = this.em.createQuery("SELECT owner FROM Owner owner WHERE owner.lastName LIKE :lastName");
|
||||||
|
@ -43,7 +37,6 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository {
|
||||||
return query.getResultList();
|
return query.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public Owner findById(int id) {
|
public Owner findById(int id) {
|
||||||
return this.em.find(Owner.class, id);
|
return this.em.find(Owner.class, id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package org.springframework.samples.petclinic.repository.jpa;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
|
||||||
|
import org.springframework.samples.petclinic.Pet;
|
||||||
|
import org.springframework.samples.petclinic.PetType;
|
||||||
|
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JPA implementation of the ClinicService interface using EntityManager.
|
||||||
|
*
|
||||||
|
* <p>The mappings are defined in "orm.xml" located in the META-INF directory.
|
||||||
|
*
|
||||||
|
* @author Mike Keith
|
||||||
|
* @author Rod Johnson
|
||||||
|
* @author Sam Brannen
|
||||||
|
* @author Michael Isvy
|
||||||
|
* @since 22.4.2006
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public class JpaPetRepositoryImpl implements PetRepository {
|
||||||
|
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager em;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<PetType> findPetTypes() {
|
||||||
|
return this.em.createQuery("SELECT ptype FROM PetType ptype ORDER BY ptype.name").getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pet findById(int id) {
|
||||||
|
return this.em.find(Pet.class, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(Pet pet) {
|
||||||
|
this.em.merge(pet);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package org.springframework.samples.petclinic.repository.jpa;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
|
||||||
|
import org.springframework.samples.petclinic.Vet;
|
||||||
|
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JPA implementation of the ClinicService interface using EntityManager.
|
||||||
|
*
|
||||||
|
* <p>The mappings are defined in "orm.xml" located in the META-INF directory.
|
||||||
|
*
|
||||||
|
* @author Mike Keith
|
||||||
|
* @author Rod Johnson
|
||||||
|
* @author Sam Brannen
|
||||||
|
* @author Michael Isvy
|
||||||
|
* @since 22.4.2006
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public class JpaVetRepositoryImpl implements VetRepository {
|
||||||
|
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager em;
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Collection<Vet> findAll() {
|
||||||
|
return this.em.createQuery("SELECT vet FROM Vet vet ORDER BY vet.lastName, vet.firstName").getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package org.springframework.samples.petclinic.repository.jpa;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
|
||||||
|
import org.springframework.samples.petclinic.Visit;
|
||||||
|
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JPA implementation of the ClinicService interface using EntityManager.
|
||||||
|
*
|
||||||
|
* <p>The mappings are defined in "orm.xml" located in the META-INF directory.
|
||||||
|
*
|
||||||
|
* @author Mike Keith
|
||||||
|
* @author Rod Johnson
|
||||||
|
* @author Sam Brannen
|
||||||
|
* @author Michael Isvy
|
||||||
|
* @since 22.4.2006
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public class JpaVisitRepositoryImpl implements VisitRepository {
|
||||||
|
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager em;
|
||||||
|
|
||||||
|
|
||||||
|
public void save(Visit visit) {
|
||||||
|
this.em.merge(visit);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<Visit> findByPetId(Integer petId) {
|
||||||
|
Query query = this.em.createQuery("SELECT visit FROM Visit v where v.pets.id= :id");
|
||||||
|
query.setParameter("id", petId);
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,45 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.repository.jpa;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import org.springframework.data.repository.Repository;
|
|
||||||
import org.springframework.samples.petclinic.Owner;
|
|
||||||
import org.springframework.samples.petclinic.Pet;
|
|
||||||
import org.springframework.samples.petclinic.PetType;
|
|
||||||
import org.springframework.samples.petclinic.Vet;
|
|
||||||
import org.springframework.samples.petclinic.Visit;
|
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Michael Isvy
|
|
||||||
* @since 15.1.2013
|
|
||||||
*/
|
|
||||||
public interface SpringDataClinic extends ClinicService, Repository {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Query("SELECT vet FROM Vet vet ORDER BY vet.lastName, vet.firstName")
|
|
||||||
public Collection<Vet> getVets();
|
|
||||||
|
|
||||||
@Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
|
|
||||||
public Collection<PetType> getPetTypes();
|
|
||||||
|
|
||||||
@Query("SELECT owner FROM Owner owner WHERE owner.lastName LIKE :lastName")
|
|
||||||
public Collection<Owner> findOwners(String lastName);
|
|
||||||
|
|
||||||
|
|
||||||
public Owner findOwner(int id);
|
|
||||||
|
|
||||||
public Pet findPet(int id);
|
|
||||||
|
|
||||||
public void storeOwner(Owner owner);
|
|
||||||
|
|
||||||
public void storePet(Pet pet);
|
|
||||||
|
|
||||||
public void storeVisit(Visit visit);
|
|
||||||
|
|
||||||
public void deletePet(int id);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.springframework.samples.petclinic.repository.jpa;
|
package org.springframework.samples.petclinic.repository.springdatajpa;
|
||||||
|
|
||||||
import org.springframework.data.repository.Repository;
|
import org.springframework.data.repository.Repository;
|
||||||
import org.springframework.samples.petclinic.Owner;
|
import org.springframework.samples.petclinic.Owner;
|
|
@ -0,0 +1,21 @@
|
||||||
|
package org.springframework.samples.petclinic.repository.springdatajpa;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.Repository;
|
||||||
|
import org.springframework.samples.petclinic.Pet;
|
||||||
|
import org.springframework.samples.petclinic.PetType;
|
||||||
|
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Michael Isvy
|
||||||
|
* @since 15.1.2013
|
||||||
|
*/
|
||||||
|
public interface SpringDataPetRepository extends PetRepository, Repository<Pet, Integer> {
|
||||||
|
|
||||||
|
@Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
|
||||||
|
List<PetType> findPetTypes() throws DataAccessException;
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.springframework.samples.petclinic.repository.springdatajpa;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.Repository;
|
||||||
|
import org.springframework.samples.petclinic.Vet;
|
||||||
|
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Michael Isvy
|
||||||
|
* @since 15.1.2013
|
||||||
|
*/
|
||||||
|
public interface SpringDataVetRepository extends VetRepository, Repository<Vet, Integer> {
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.springframework.samples.petclinic.repository.springdatajpa;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.Repository;
|
||||||
|
import org.springframework.samples.petclinic.Visit;
|
||||||
|
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Michael Isvy
|
||||||
|
* @since 15.1.2013
|
||||||
|
*/
|
||||||
|
public interface SpringDataVisitRepository extends VisitRepository, Repository<Visit, Integer> {
|
||||||
|
}
|
|
@ -22,18 +22,16 @@ import org.springframework.samples.petclinic.Visit;
|
||||||
*/
|
*/
|
||||||
public interface ClinicService {
|
public interface ClinicService {
|
||||||
|
|
||||||
public Collection<PetType> getPetTypes() throws DataAccessException;
|
public Collection<PetType> findPetTypes() throws DataAccessException;
|
||||||
|
|
||||||
public Owner findOwnerById(int id) throws DataAccessException;
|
public Owner findOwnerById(int id) throws DataAccessException;
|
||||||
|
|
||||||
public Pet findPetById(int id) throws DataAccessException;
|
public Pet findPetById(int id) throws DataAccessException;
|
||||||
|
|
||||||
public void storePet(Pet pet) throws DataAccessException;
|
public void savePet(Pet pet) throws DataAccessException;
|
||||||
|
|
||||||
public void deletePet(int id) throws DataAccessException;
|
public void saveVisit(Visit visit) throws DataAccessException;
|
||||||
|
|
||||||
public void storeVisit(Visit visit) throws DataAccessException;
|
public Collection<Vet> findVets() throws DataAccessException;
|
||||||
|
|
||||||
public Collection<Vet> getVets() throws DataAccessException;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.springframework.samples.petclinic.repository.PetRepository;
|
||||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ClinicServiceImpl implements ClinicService {
|
public class ClinicServiceImpl implements ClinicService {
|
||||||
|
@ -30,32 +31,34 @@ public class ClinicServiceImpl implements ClinicService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private VisitRepository visitRepository;
|
private VisitRepository visitRepository;
|
||||||
|
|
||||||
public Collection<PetType> getPetTypes() throws DataAccessException {
|
@Transactional(readOnly=true)
|
||||||
return petRepository.getPetTypes();
|
public Collection<PetType> findPetTypes() throws DataAccessException {
|
||||||
|
return petRepository.findPetTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly=true)
|
||||||
public Owner findOwnerById(int id) throws DataAccessException {
|
public Owner findOwnerById(int id) throws DataAccessException {
|
||||||
return ownerRepository.findById(id);
|
return ownerRepository.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void storeVisit(Visit visit) throws DataAccessException {
|
@Transactional
|
||||||
visitRepository.storeVisit(visit);
|
public void saveVisit(Visit visit) throws DataAccessException {
|
||||||
|
visitRepository.save(visit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly=true)
|
||||||
public Pet findPetById(int id) throws DataAccessException {
|
public Pet findPetById(int id) throws DataAccessException {
|
||||||
return petRepository.findById(id);
|
return petRepository.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void storePet(Pet pet) throws DataAccessException {
|
@Transactional
|
||||||
petRepository.storePet(pet);
|
public void savePet(Pet pet) throws DataAccessException {
|
||||||
|
petRepository.save(pet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deletePet(int id) throws DataAccessException {
|
@Transactional(readOnly=true)
|
||||||
petRepository.deletePet(id);
|
public Collection<Vet> findVets() throws DataAccessException {
|
||||||
}
|
return vetRepository.findAll();
|
||||||
|
|
||||||
public Collection<Vet> getVets() throws DataAccessException {
|
|
||||||
return vetRepository.getVets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class PetController {
|
||||||
|
|
||||||
@ModelAttribute("types")
|
@ModelAttribute("types")
|
||||||
public Collection<PetType> populatePetTypes() {
|
public Collection<PetType> populatePetTypes() {
|
||||||
return this.clinicService.getPetTypes();
|
return this.clinicService.findPetTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@InitBinder
|
@InitBinder
|
||||||
|
@ -67,7 +67,7 @@ public class PetController {
|
||||||
return "pets/createOrUpdatePetForm";
|
return "pets/createOrUpdatePetForm";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.clinicService.storePet(pet);
|
this.clinicService.savePet(pet);
|
||||||
status.setComplete();
|
status.setComplete();
|
||||||
return "redirect:/owners/" + pet.getOwner().getId();
|
return "redirect:/owners/" + pet.getOwner().getId();
|
||||||
}
|
}
|
||||||
|
@ -88,17 +88,10 @@ public class PetController {
|
||||||
return "pets/createOrUpdatePetForm";
|
return "pets/createOrUpdatePetForm";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.clinicService.storePet(pet);
|
this.clinicService.savePet(pet);
|
||||||
status.setComplete();
|
status.setComplete();
|
||||||
return "redirect:/owners/" + pet.getOwner().getId();
|
return "redirect:/owners/" + pet.getOwner().getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value="/owners/*/pets/{petId}/edit", method = RequestMethod.DELETE)
|
|
||||||
public String deletePet(@PathVariable("petId") int petId) {
|
|
||||||
Pet pet = this.clinicService.findPetById(petId);
|
|
||||||
this.clinicService.deletePet(petId);
|
|
||||||
return "redirect:/owners/" + pet.getOwner().getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class PetTypeEditor extends PropertyEditorSupport {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAsText(String text) throws IllegalArgumentException {
|
public void setAsText(String text) throws IllegalArgumentException {
|
||||||
for (PetType type : this.clinicService.getPetTypes()) {
|
for (PetType type : this.clinicService.findPetTypes()) {
|
||||||
if (type.getName().equals(text)) {
|
if (type.getName().equals(text)) {
|
||||||
setValue(type);
|
setValue(type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class VetController {
|
||||||
@RequestMapping("/vets")
|
@RequestMapping("/vets")
|
||||||
public String showVetList(Model model) {
|
public String showVetList(Model model) {
|
||||||
Vets vets = new Vets();
|
Vets vets = new Vets();
|
||||||
vets.getVetList().addAll(this.clinicService.getVets());
|
vets.getVetList().addAll(this.clinicService.findVets());
|
||||||
model.addAttribute("vets", vets);
|
model.addAttribute("vets", vets);
|
||||||
return "vetsList";
|
return "vetsList";
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class VisitController {
|
||||||
return "pets/createOrUpdateVisitForm";
|
return "pets/createOrUpdateVisitForm";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.clinicService.storeVisit(visit);
|
this.clinicService.saveVisit(visit);
|
||||||
status.setComplete();
|
status.setComplete();
|
||||||
return "redirect:/owners/" + visit.getPet().getOwner().getId();
|
return "redirect:/owners/" + visit.getPet().getOwner().getId();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,16 +20,17 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.springframework.samples.petclinic.Visit;
|
||||||
|
import org.springframework.web.servlet.view.feed.AbstractAtomFeedView;
|
||||||
|
|
||||||
import com.sun.syndication.feed.atom.Content;
|
import com.sun.syndication.feed.atom.Content;
|
||||||
import com.sun.syndication.feed.atom.Entry;
|
import com.sun.syndication.feed.atom.Entry;
|
||||||
import com.sun.syndication.feed.atom.Feed;
|
import com.sun.syndication.feed.atom.Feed;
|
||||||
|
|
||||||
import org.springframework.samples.petclinic.Visit;
|
|
||||||
import org.springframework.web.servlet.view.feed.AbstractAtomFeedView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A view creating a Atom representation from a list of Visit objects.
|
* A view creating a Atom representation from a list of Visit objects.
|
||||||
*
|
*
|
||||||
|
|
|
@ -11,10 +11,6 @@
|
||||||
</layout>
|
</layout>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<logger name="org.springframework.samples.petclinic.aspects">
|
|
||||||
<level value="info" />
|
|
||||||
</logger>
|
|
||||||
|
|
||||||
<logger name="org.springframework.web">
|
<logger name="org.springframework.web">
|
||||||
<level value="info" />
|
<level value="info" />
|
||||||
</logger>
|
</logger>
|
||||||
|
@ -23,8 +19,6 @@
|
||||||
<level value="info" />
|
<level value="info" />
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Root Logger -->
|
<!-- Root Logger -->
|
||||||
<root>
|
<root>
|
||||||
<priority value="info" /><!--
|
<priority value="info" /><!--
|
||||||
|
|
|
@ -120,7 +120,7 @@
|
||||||
</beans>
|
</beans>
|
||||||
|
|
||||||
<beans profile="spring-data-jpa">
|
<beans profile="spring-data-jpa">
|
||||||
<jpa:repositories base-package="org.springframework.samples.petclinic.repository.jpa"/>
|
<jpa:repositories base-package="org.springframework.samples.petclinic.repository.springdatajpa"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
</beans>
|
</beans>
|
|
@ -55,9 +55,6 @@
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form:form>
|
</form:form>
|
||||||
<c:if test="${!pet['new']}">
|
<c:if test="${!pet['new']}">
|
||||||
<form:form method="delete">
|
|
||||||
<p class="submit"><input type="submit" value="Delete Pet"/></p>
|
|
||||||
</form:form>
|
|
||||||
</c:if>
|
</c:if>
|
||||||
<jsp:include page="../footer.jsp"/>
|
<jsp:include page="../footer.jsp"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
package org.springframework.samples.petclinic;
|
package org.springframework.samples.petclinic;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -117,7 +115,7 @@ public abstract class AbstractOwnerRepositoryTests {
|
||||||
o1.getPets();
|
o1.getPets();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test @Transactional
|
||||||
public void insertOwner() {
|
public void insertOwner() {
|
||||||
Collection<Owner> owners = this.ownerRepository.findByLastName("Schultz");
|
Collection<Owner> owners = this.ownerRepository.findByLastName("Schultz");
|
||||||
int found = owners.size();
|
int found = owners.size();
|
||||||
|
@ -132,7 +130,7 @@ public abstract class AbstractOwnerRepositoryTests {
|
||||||
assertEquals("Verifying number of owners after inserting a new one.", found + 1, owners.size());
|
assertEquals("Verifying number of owners after inserting a new one.", found + 1, owners.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test @Transactional
|
||||||
public void updateOwner() throws Exception {
|
public void updateOwner() throws Exception {
|
||||||
Owner o1 = this.ownerRepository.findById(1);
|
Owner o1 = this.ownerRepository.findById(1);
|
||||||
String old = o1.getLastName();
|
String old = o1.getLastName();
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package org.springframework.samples.petclinic;
|
package org.springframework.samples.petclinic;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||||
|
@ -95,7 +95,7 @@ public abstract class AbstractPetRepositoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPetTypes() {
|
public void getPetTypes() {
|
||||||
Collection<PetType> petTypes = this.petRepository.getPetTypes();
|
Collection<PetType> petTypes = this.petRepository.findPetTypes();
|
||||||
|
|
||||||
PetType t1 = EntityUtils.getById(petTypes, PetType.class, 1);
|
PetType t1 = EntityUtils.getById(petTypes, PetType.class, 1);
|
||||||
assertEquals("cat", t1.getName());
|
assertEquals("cat", t1.getName());
|
||||||
|
@ -105,7 +105,7 @@ public abstract class AbstractPetRepositoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findPet() {
|
public void findPet() {
|
||||||
Collection<PetType> types = this.petRepository.getPetTypes();
|
Collection<PetType> types = this.petRepository.findPetTypes();
|
||||||
Pet p7 = this.petRepository.findById(7);
|
Pet p7 = this.petRepository.findById(7);
|
||||||
assertTrue(p7.getName().startsWith("Samantha"));
|
assertTrue(p7.getName().startsWith("Samantha"));
|
||||||
assertEquals(EntityUtils.getById(types, PetType.class, 1).getId(), p7.getType().getId());
|
assertEquals(EntityUtils.getById(types, PetType.class, 1).getId(), p7.getType().getId());
|
||||||
|
@ -122,24 +122,24 @@ public abstract class AbstractPetRepositoryTests {
|
||||||
int found = o6.getPets().size();
|
int found = o6.getPets().size();
|
||||||
Pet pet = new Pet();
|
Pet pet = new Pet();
|
||||||
pet.setName("bowser");
|
pet.setName("bowser");
|
||||||
Collection<PetType> types = this.petRepository.getPetTypes();
|
Collection<PetType> types = this.petRepository.findPetTypes();
|
||||||
pet.setType(EntityUtils.getById(types, PetType.class, 2));
|
pet.setType(EntityUtils.getById(types, PetType.class, 2));
|
||||||
pet.setBirthDate(new Date());
|
pet.setBirthDate(new Date());
|
||||||
o6.addPet(pet);
|
o6.addPet(pet);
|
||||||
assertEquals(found + 1, o6.getPets().size());
|
assertEquals(found + 1, o6.getPets().size());
|
||||||
// both storePet and storeOwner are necessary to cover all ORM tools
|
// both storePet and storeOwner are necessary to cover all ORM tools
|
||||||
this.petRepository.storePet(pet);
|
this.petRepository.save(pet);
|
||||||
this.ownerRepository.save(o6);
|
this.ownerRepository.save(o6);
|
||||||
o6 = this.ownerRepository.findById(6);
|
o6 = this.ownerRepository.findById(6);
|
||||||
assertEquals(found + 1, o6.getPets().size());
|
assertEquals(found + 1, o6.getPets().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test @Transactional
|
||||||
public void updatePet() throws Exception {
|
public void updatePet() throws Exception {
|
||||||
Pet p7 = this.petRepository.findById(7);
|
Pet p7 = this.petRepository.findById(7);
|
||||||
String old = p7.getName();
|
String old = p7.getName();
|
||||||
p7.setName(old + "X");
|
p7.setName(old + "X");
|
||||||
this.petRepository.storePet(p7);
|
this.petRepository.save(p7);
|
||||||
p7 = this.petRepository.findById(7);
|
p7 = this.petRepository.findById(7);
|
||||||
assertEquals(old + "X", p7.getName());
|
assertEquals(old + "X", p7.getName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package org.springframework.samples.petclinic;
|
package org.springframework.samples.petclinic;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
import org.springframework.samples.petclinic.service.ClinicService;
|
||||||
|
@ -90,8 +88,8 @@ public abstract class AbstractVetRepositoryTests {
|
||||||
|
|
||||||
|
|
||||||
@Test @Transactional
|
@Test @Transactional
|
||||||
public void getVets() {
|
public void findVets() {
|
||||||
Collection<Vet> vets = this.vetRepository.getVets();
|
Collection<Vet> vets = this.vetRepository.findAll();
|
||||||
|
|
||||||
Vet v1 = EntityUtils.getById(vets, Vet.class, 2);
|
Vet v1 = EntityUtils.getById(vets, Vet.class, 2);
|
||||||
assertEquals("Leary", v1.getLastName());
|
assertEquals("Leary", v1.getLastName());
|
||||||
|
|
|
@ -1,17 +1,12 @@
|
||||||
package org.springframework.samples.petclinic;
|
package org.springframework.samples.petclinic;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
import org.springframework.samples.petclinic.service.ClinicService;
|
||||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -101,8 +96,8 @@ public abstract class AbstractVisitRepositoryTests {
|
||||||
p7.addVisit(visit);
|
p7.addVisit(visit);
|
||||||
visit.setDescription("test");
|
visit.setDescription("test");
|
||||||
// both storeVisit and storePet are necessary to cover all ORM tools
|
// both storeVisit and storePet are necessary to cover all ORM tools
|
||||||
this.visitRepository.storeVisit(visit);
|
this.visitRepository.save(visit);
|
||||||
this.petRepository.storePet(p7);
|
this.petRepository.save(p7);
|
||||||
// assertTrue(!visit.isNew()); -- NOT TRUE FOR TOPLINK (before commit)
|
// assertTrue(!visit.isNew()); -- NOT TRUE FOR TOPLINK (before commit)
|
||||||
p7 = this.petRepository.findById(7);
|
p7 = this.petRepository.findById(7);
|
||||||
assertEquals(found + 1, p7.getVisits().size());
|
assertEquals(found + 1, p7.getVisits().size());
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.springframework.samples.petclinic.jdbc;
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.samples.petclinic.AbstractOwnerRepositoryTests;
|
import org.springframework.samples.petclinic.AbstractOwnerRepositoryTests;
|
||||||
import org.springframework.samples.petclinic.repository.jdbc.JdbcClinicImpl;
|
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.springframework.samples.petclinic.jdbc;
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.samples.petclinic.AbstractPetRepositoryTests;
|
import org.springframework.samples.petclinic.AbstractPetRepositoryTests;
|
||||||
import org.springframework.samples.petclinic.repository.jdbc.JdbcClinicImpl;
|
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.springframework.samples.petclinic.jdbc;
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.samples.petclinic.AbstractVetRepositoryTests;
|
import org.springframework.samples.petclinic.AbstractVetRepositoryTests;
|
||||||
import org.springframework.samples.petclinic.repository.jdbc.JdbcClinicImpl;
|
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.springframework.samples.petclinic.jdbc;
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.samples.petclinic.AbstractVisitRepositoryTests;
|
import org.springframework.samples.petclinic.AbstractVisitRepositoryTests;
|
||||||
import org.springframework.samples.petclinic.repository.jdbc.JdbcClinicImpl;
|
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.springframework.samples.petclinic.jpa;
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.samples.petclinic.AbstractPetRepositoryTests;
|
import org.springframework.samples.petclinic.AbstractPetRepositoryTests;
|
||||||
import org.springframework.samples.petclinic.repository.jdbc.JdbcClinicImpl;
|
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.springframework.samples.petclinic.jpa;
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.samples.petclinic.AbstractVetRepositoryTests;
|
import org.springframework.samples.petclinic.AbstractVetRepositoryTests;
|
||||||
import org.springframework.samples.petclinic.repository.jdbc.JdbcClinicImpl;
|
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.springframework.samples.petclinic.jpa;
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.samples.petclinic.AbstractVisitRepositoryTests;
|
import org.springframework.samples.petclinic.AbstractVisitRepositoryTests;
|
||||||
import org.springframework.samples.petclinic.repository.jdbc.JdbcClinicImpl;
|
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
|
||||||
|
package org.springframework.samples.petclinic.springdatajpa;
|
||||||
|
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.samples.petclinic.AbstractOwnerRepositoryTests;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Provides the following services:
|
||||||
|
* <ul>
|
||||||
|
* <li>Injects test dependencies, meaning that we don't need to perform
|
||||||
|
* application context lookups. See the setClinic() method. Injection uses
|
||||||
|
* autowiring by type.</li>
|
||||||
|
* <li>Executes each test method in its own transaction, which is automatically
|
||||||
|
* rolled back by default. This means that even if tests insert or otherwise
|
||||||
|
* change database state, there is no need for a teardown or cleanup script.</li>
|
||||||
|
* </ul>
|
||||||
|
* <p>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Rod Johnson
|
||||||
|
* @author Sam Brannen
|
||||||
|
* @author Michael Isvy
|
||||||
|
*/
|
||||||
|
|
||||||
|
@ContextConfiguration(locations={"classpath:spring/applicationContext-dao.xml"})
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ActiveProfiles({"jpa","spring-data-jpa"})
|
||||||
|
public class JpaOwnerRepositoryImplTests extends AbstractOwnerRepositoryTests {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package org.springframework.samples.petclinic.springdatajpa;
|
||||||
|
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.samples.petclinic.AbstractPetRepositoryTests;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Integration tests for the {@link JdbcClinicImpl} implementation.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Thomas Risberg
|
||||||
|
* @author Michael Isvy
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(locations={"classpath:spring/applicationContext-dao.xml"})
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@DirtiesContext
|
||||||
|
@ActiveProfiles({"jpa","spring-data-jpa"})
|
||||||
|
public class JpaPetRepositoryImplTests extends AbstractPetRepositoryTests {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package org.springframework.samples.petclinic.springdatajpa;
|
||||||
|
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.samples.petclinic.AbstractVetRepositoryTests;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Integration tests for the {@link JdbcClinicImpl} implementation.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Thomas Risberg
|
||||||
|
* @author Michael Isvy
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(locations={"classpath:spring/applicationContext-dao.xml"})
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@DirtiesContext
|
||||||
|
@ActiveProfiles({"jpa","spring-data-jpa"})
|
||||||
|
public class JpaVetRepositoryImplTests extends AbstractVetRepositoryTests {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package org.springframework.samples.petclinic.springdatajpa;
|
||||||
|
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.samples.petclinic.AbstractVisitRepositoryTests;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Integration tests for the {@link JdbcClinicImpl} implementation.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Thomas Risberg
|
||||||
|
* @author Michael Isvy
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(locations={"classpath:spring/applicationContext-dao.xml"})
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@DirtiesContext
|
||||||
|
@ActiveProfiles({"jpa","spring-data-jpa"})
|
||||||
|
public class JpaVisitRepositoryImplTests extends AbstractVisitRepositoryTests {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
package org.springframework.samples.petclinic.jpa;
|
package org.springframework.samples.petclinic.springdatajpa;
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.samples.petclinic.AbstractOwnerRepositoryTests;
|
import org.springframework.samples.petclinic.AbstractOwnerRepositoryTests;
|
|
@ -16,23 +16,24 @@
|
||||||
|
|
||||||
package org.springframework.samples.petclinic.web;
|
package org.springframework.samples.petclinic.web;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.sun.syndication.feed.atom.Entry;
|
|
||||||
import com.sun.syndication.feed.atom.Feed;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.samples.petclinic.Pet;
|
import org.springframework.samples.petclinic.Pet;
|
||||||
import org.springframework.samples.petclinic.PetType;
|
import org.springframework.samples.petclinic.PetType;
|
||||||
import org.springframework.samples.petclinic.Visit;
|
import org.springframework.samples.petclinic.Visit;
|
||||||
|
|
||||||
|
import com.sun.syndication.feed.atom.Entry;
|
||||||
|
import com.sun.syndication.feed.atom.Feed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue