diff --git a/org.springframework.samples.petclinic/build.xml b/org.springframework.samples.petclinic/build.xml
new file mode 100644
index 00000000000..75ee8575f1f
--- /dev/null
+++ b/org.springframework.samples.petclinic/build.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/org.springframework.samples.petclinic/ivy.xml b/org.springframework.samples.petclinic/ivy.xml
new file mode 100644
index 00000000000..8dd6cef2e3f
--- /dev/null
+++ b/org.springframework.samples.petclinic/ivy.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/org.springframework.samples.petclinic/petclinic.iml b/org.springframework.samples.petclinic/petclinic.iml
new file mode 100644
index 00000000000..57ef73fd8d6
--- /dev/null
+++ b/org.springframework.samples.petclinic/petclinic.iml
@@ -0,0 +1,141 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/BaseEntity.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/BaseEntity.java
new file mode 100644
index 00000000000..bb68af4fc01
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/BaseEntity.java
@@ -0,0 +1,27 @@
+package org.springframework.samples.petclinic;
+
+/**
+ * Simple JavaBean domain object with an id property.
+ * Used as a base class for objects needing this property.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ */
+public class BaseEntity {
+
+ private Integer id;
+
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public boolean isNew() {
+ return (this.id == null);
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Clinic.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Clinic.java
new file mode 100644
index 00000000000..872bd457c29
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Clinic.java
@@ -0,0 +1,77 @@
+package org.springframework.samples.petclinic;
+
+import java.util.Collection;
+
+import org.springframework.dao.DataAccessException;
+
+/**
+ * The high-level PetClinic business interface.
+ *
+ *
This is basically a data access object.
+ * PetClinic doesn't have a dedicated business facade.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ */
+public interface Clinic {
+
+ /**
+ * Retrieve all Vets from the data store.
+ * @return a Collection of Vets
+ */
+ Collection getVets() throws DataAccessException;
+
+ /**
+ * Retrieve all PetTypes from the data store.
+ * @return a Collection of PetTypes
+ */
+ Collection getPetTypes() throws DataAccessException;
+
+ /**
+ * Retrieve Owners from the data store by last name,
+ * returning all owners whose last name starts with the given name.
+ * @param lastName Value to search for
+ * @return a Collection of matching Owners
+ * (or an empty Collection if none found)
+ */
+ Collection findOwners(String lastName) throws DataAccessException;
+
+ /**
+ * Retrieve an Owner from the data store by id.
+ * @param id the id to search for
+ * @return the Owner if found
+ * @throws org.springframework.dao.DataRetrievalFailureException if not found
+ */
+ Owner loadOwner(int id) throws DataAccessException;
+
+ /**
+ * Retrieve a Pet from the data store by id.
+ * @param id the id to search for
+ * @return the Pet if found
+ * @throws org.springframework.dao.DataRetrievalFailureException if not found
+ */
+ Pet loadPet(int id) throws DataAccessException;
+
+ /**
+ * Save an Owner to the data store, either inserting or updating it.
+ * @param owner the Owner to save
+ * @see BaseEntity#isNew
+ */
+ void storeOwner(Owner owner) throws DataAccessException;
+
+ /**
+ * Save a Pet to the data store, either inserting or updating it.
+ * @param pet the Pet to save
+ * @see BaseEntity#isNew
+ */
+ void storePet(Pet pet) throws DataAccessException;
+
+ /**
+ * Save a Visit to the data store, either inserting or updating it.
+ * @param visit the Visit to save
+ * @see BaseEntity#isNew
+ */
+ void storeVisit(Visit visit) throws DataAccessException;
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/NamedEntity.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/NamedEntity.java
new file mode 100644
index 00000000000..40c5931d86d
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/NamedEntity.java
@@ -0,0 +1,28 @@
+package org.springframework.samples.petclinic;
+
+/**
+ * Simple JavaBean domain object adds a name property to BaseEntity.
+ * Used as a base class for objects needing these properties.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ */
+public class NamedEntity extends BaseEntity {
+
+ private String name;
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ @Override
+ public String toString() {
+ return this.getName();
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Owner.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Owner.java
new file mode 100644
index 00000000000..75ea3bc064c
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Owner.java
@@ -0,0 +1,127 @@
+package org.springframework.samples.petclinic;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.springframework.beans.support.MutableSortDefinition;
+import org.springframework.beans.support.PropertyComparator;
+import org.springframework.core.style.ToStringCreator;
+
+/**
+ * Simple JavaBean domain object representing an owner.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ */
+public class Owner extends Person {
+
+ private String address;
+
+ private String city;
+
+ private String telephone;
+
+ private Set pets;
+
+
+ public String getAddress() {
+ return this.address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public String getCity() {
+ return this.city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getTelephone() {
+ return this.telephone;
+ }
+
+ public void setTelephone(String telephone) {
+ this.telephone = telephone;
+ }
+
+ protected void setPetsInternal(Set pets) {
+ this.pets = pets;
+ }
+
+ protected Set getPetsInternal() {
+ if (this.pets == null) {
+ this.pets = new HashSet();
+ }
+ return this.pets;
+ }
+
+ public List getPets() {
+ List sortedPets = new ArrayList(getPetsInternal());
+ PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true));
+ return Collections.unmodifiableList(sortedPets);
+ }
+
+ public void addPet(Pet pet) {
+ getPetsInternal().add(pet);
+ pet.setOwner(this);
+ }
+
+ /**
+ * Return the Pet with the given name, or null if none found for this Owner.
+ *
+ * @param name to test
+ * @return true if pet name is already in use
+ */
+ public Pet getPet(String name) {
+ return getPet(name, false);
+ }
+
+ /**
+ * Return the Pet with the given name, or null if none found for this Owner.
+ *
+ * @param name to test
+ * @return true if pet name is already in use
+ */
+ public Pet getPet(String name, boolean ignoreNew) {
+ name = name.toLowerCase();
+ for (Pet pet : getPetsInternal()) {
+ if (!ignoreNew || !pet.isNew()) {
+ String compName = pet.getName();
+ compName = compName.toLowerCase();
+ if (compName.equals(name)) {
+ return pet;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringCreator(this)
+
+ .append("id", this.getId())
+
+ .append("new", this.isNew())
+
+ .append("lastName", this.getLastName())
+
+ .append("firstName", this.getFirstName())
+
+ .append("address", this.address)
+
+ .append("city", this.city)
+
+ .append("telephone", this.telephone)
+
+ .toString();
+ }
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Person.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Person.java
new file mode 100644
index 00000000000..da7974a7de7
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Person.java
@@ -0,0 +1,32 @@
+package org.springframework.samples.petclinic;
+
+/**
+ * Simple JavaBean domain object representing an person.
+ *
+ * @author Ken Krebs
+ */
+public class Person extends BaseEntity {
+
+ private String firstName;
+
+ private String lastName;
+
+ public String getFirstName() {
+ return this.firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return this.lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Pet.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Pet.java
new file mode 100644
index 00000000000..f5294b5ca9f
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Pet.java
@@ -0,0 +1,77 @@
+package org.springframework.samples.petclinic;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.springframework.beans.support.MutableSortDefinition;
+import org.springframework.beans.support.PropertyComparator;
+
+/**
+ * Simple JavaBean business object representing a pet.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ */
+public class Pet extends NamedEntity {
+
+ private Date birthDate;
+
+ private PetType type;
+
+ private Owner owner;
+
+ private Set visits;
+
+
+ public void setBirthDate(Date birthDate) {
+ this.birthDate = birthDate;
+ }
+
+ public Date getBirthDate() {
+ return this.birthDate;
+ }
+
+ public void setType(PetType type) {
+ this.type = type;
+ }
+
+ public PetType getType() {
+ return this.type;
+ }
+
+ protected void setOwner(Owner owner) {
+ this.owner = owner;
+ }
+
+ public Owner getOwner() {
+ return this.owner;
+ }
+
+ protected void setVisitsInternal(Set visits) {
+ this.visits = visits;
+ }
+
+ protected Set getVisitsInternal() {
+ if (this.visits == null) {
+ this.visits = new HashSet();
+ }
+ return this.visits;
+ }
+
+ public List getVisits() {
+ List sortedVisits = new ArrayList(getVisitsInternal());
+ PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false));
+ return Collections.unmodifiableList(sortedVisits);
+ }
+
+ public void addVisit(Visit visit) {
+ getVisitsInternal().add(visit);
+ visit.setPet(this);
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/PetType.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/PetType.java
new file mode 100644
index 00000000000..aaadc5c44d0
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/PetType.java
@@ -0,0 +1,8 @@
+package org.springframework.samples.petclinic;
+
+/**
+ * @author Juergen Hoeller
+ */
+public class PetType extends NamedEntity {
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Specialty.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Specialty.java
new file mode 100644
index 00000000000..d19ccaba96e
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Specialty.java
@@ -0,0 +1,10 @@
+package org.springframework.samples.petclinic;
+
+/**
+ * Models a {@link Vet Vet's} specialty (for example, dentistry).
+ *
+ * @author Juergen Hoeller
+ */
+public class Specialty extends NamedEntity {
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Vet.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Vet.java
new file mode 100644
index 00000000000..53d0b5c49f3
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Vet.java
@@ -0,0 +1,49 @@
+package org.springframework.samples.petclinic;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.springframework.beans.support.MutableSortDefinition;
+import org.springframework.beans.support.PropertyComparator;
+
+/**
+ * Simple JavaBean domain object representing a veterinarian.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ */
+public class Vet extends Person {
+
+ private Set specialties;
+
+
+ protected void setSpecialtiesInternal(Set specialties) {
+ this.specialties = specialties;
+ }
+
+ protected Set getSpecialtiesInternal() {
+ if (this.specialties == null) {
+ this.specialties = new HashSet();
+ }
+ return this.specialties;
+ }
+
+ public List getSpecialties() {
+ List sortedSpecs = new ArrayList(getSpecialtiesInternal());
+ PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true));
+ return Collections.unmodifiableList(sortedSpecs);
+ }
+
+ public int getNrOfSpecialties() {
+ return getSpecialtiesInternal().size();
+ }
+
+ public void addSpecialty(Specialty specialty) {
+ getSpecialtiesInternal().add(specialty);
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Visit.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Visit.java
new file mode 100644
index 00000000000..e1eb90ab232
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/Visit.java
@@ -0,0 +1,70 @@
+package org.springframework.samples.petclinic;
+
+import java.util.Date;
+
+/**
+ * Simple JavaBean domain object representing a visit.
+ *
+ * @author Ken Krebs
+ */
+public class Visit extends BaseEntity {
+
+ /** Holds value of property date. */
+ private Date date;
+
+ /** Holds value of property description. */
+ private String description;
+
+ /** Holds value of property pet. */
+ private Pet pet;
+
+
+ /** Creates a new instance of Visit for the current date */
+ public Visit() {
+ this.date = new Date();
+ }
+
+
+ /** Getter for property date.
+ * @return Value of property date.
+ */
+ public Date getDate() {
+ return this.date;
+ }
+
+ /** Setter for property date.
+ * @param date New value of property date.
+ */
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ /** Getter for property description.
+ * @return Value of property description.
+ */
+ public String getDescription() {
+ return this.description;
+ }
+
+ /** Setter for property description.
+ * @param description New value of property description.
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /** Getter for property pet.
+ * @return Value of property pet.
+ */
+ public Pet getPet() {
+ return this.pet;
+ }
+
+ /** Setter for property pet.
+ * @param pet New value of property pet.
+ */
+ protected void setPet(Pet pet) {
+ this.pet = pet;
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/aspects/AbstractTraceAspect.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/aspects/AbstractTraceAspect.java
new file mode 100644
index 00000000000..26d32359fc4
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/aspects/AbstractTraceAspect.java
@@ -0,0 +1,31 @@
+package org.springframework.samples.petclinic.aspects;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+
+/**
+ * Aspect to illustrate Spring-driven load-time weaving.
+ *
+ * @author Ramnivas Laddad
+ * @since 2.5
+ */
+@Aspect
+public abstract class AbstractTraceAspect {
+
+ private static final Log logger = LogFactory.getLog(AbstractTraceAspect.class);
+
+ @Pointcut
+ public abstract void traced();
+
+ @Before("traced()")
+ public void trace(JoinPoint.StaticPart jpsp) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering " + jpsp.getSignature().toLongString());
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/aspects/CallMonitoringAspect.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/aspects/CallMonitoringAspect.java
new file mode 100644
index 00000000000..2de4cb41d0a
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/aspects/CallMonitoringAspect.java
@@ -0,0 +1,81 @@
+package org.springframework.samples.petclinic.aspects;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+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.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedResource;
+import org.springframework.util.StopWatch;
+
+/**
+ * Simple AspectJ aspect that monitors call count and call invocation time.
+ * Implements the CallMonitor management interface.
+ *
+ * @author Rob Harrop
+ * @author Juergen Hoeller
+ * @since 2.5
+ */
+@ManagedResource("petclinic:type=CallMonitor")
+@Aspect
+public class CallMonitoringAspect {
+
+ private boolean isEnabled = true;
+
+ private int callCount = 0;
+
+ private long accumulatedCallTime = 0;
+
+
+ @ManagedAttribute
+ public void setEnabled(boolean enabled) {
+ isEnabled = enabled;
+ }
+
+ @ManagedAttribute
+ public boolean isEnabled() {
+ return isEnabled;
+ }
+
+ @ManagedOperation
+ public void reset() {
+ this.callCount = 0;
+ this.accumulatedCallTime = 0;
+ }
+
+ @ManagedAttribute
+ public int getCallCount() {
+ return callCount;
+ }
+
+ @ManagedAttribute
+ public long getCallTime() {
+ return (this.callCount > 0 ? this.accumulatedCallTime / this.callCount : 0);
+ }
+
+
+ @Around("within(@org.springframework.stereotype.Service *)")
+ public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
+ if (this.isEnabled) {
+ StopWatch sw = new StopWatch(joinPoint.toShortString());
+
+ sw.start("invoke");
+ try {
+ return joinPoint.proceed();
+ }
+ finally {
+ sw.stop();
+ synchronized (this) {
+ this.callCount++;
+ this.accumulatedCallTime += sw.getTotalTimeMillis();
+ }
+ }
+ }
+
+ else {
+ return joinPoint.proceed();
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/aspects/UsageLogAspect.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/aspects/UsageLogAspect.java
new file mode 100644
index 00000000000..e326abfb755
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/aspects/UsageLogAspect.java
@@ -0,0 +1,48 @@
+package org.springframework.samples.petclinic.aspects;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+
+/**
+ * Sample AspectJ annotation-style aspect that saves
+ * every owner name requested to the clinic.
+ *
+ * @author Rod Johnson
+ * @author Juergen Hoeller
+ * @since 2.0
+ */
+@Aspect
+public class UsageLogAspect {
+
+ private int historySize = 100;
+
+ // Of course saving all names is not suitable for
+ // production use, but this is a simple example.
+ private List namesRequested = new ArrayList(this.historySize);
+
+
+ public synchronized void setHistorySize(int historySize) {
+ this.historySize = historySize;
+ this.namesRequested = new ArrayList(historySize);
+ }
+
+ @Before("execution(* *.findOwners(String)) && args(name)")
+ public synchronized void logNameRequest(String name) {
+ // Not the most efficient implementation,
+ // but we're aiming to illustrate the power of
+ // @AspectJ AOP, not write perfect code here :-)
+ if (this.namesRequested.size() > this.historySize) {
+ this.namesRequested.remove(0);
+ }
+ this.namesRequested.add(name);
+ }
+
+ public synchronized List getNamesRequested() {
+ return Collections.unmodifiableList(this.namesRequested);
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/hibernate/HibernateClinic.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/hibernate/HibernateClinic.java
new file mode 100644
index 00000000000..89eda8522cf
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/hibernate/HibernateClinic.java
@@ -0,0 +1,89 @@
+package org.springframework.samples.petclinic.hibernate;
+
+import java.util.Collection;
+
+import org.hibernate.SessionFactory;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.samples.petclinic.Clinic;
+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.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Hibernate implementation of the Clinic interface.
+ *
+ * The mappings are defined in "petclinic.hbm.xml", located in the root of the
+ * class path.
+ *
+ *
Note that transactions are declared with annotations and that some methods
+ * contain "readOnly = true" which is an optimization that is particularly
+ * valuable when using Hibernate (to suppress unnecessary flush attempts for
+ * read-only operations).
+ *
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ * @author Mark Fisher
+ * @since 19.10.2003
+ */
+@Repository
+@Transactional
+public class HibernateClinic implements Clinic {
+
+ @Autowired
+ private SessionFactory sessionFactory;
+
+
+ @Transactional(readOnly = true)
+ @SuppressWarnings("unchecked")
+ public Collection getVets() {
+ return sessionFactory.getCurrentSession().createQuery("from Vet vet order by vet.lastName, vet.firstName").list();
+ }
+
+ @Transactional(readOnly = true)
+ @SuppressWarnings("unchecked")
+ public Collection getPetTypes() {
+ return sessionFactory.getCurrentSession().createQuery("from PetType type order by type.name").list();
+ }
+
+ @Transactional(readOnly = true)
+ @SuppressWarnings("unchecked")
+ public Collection findOwners(String lastName) {
+ return sessionFactory.getCurrentSession().createQuery("from Owner owner where owner.lastName like :lastName")
+ .setString("lastName", lastName + "%").list();
+ }
+
+ @Transactional(readOnly = true)
+ public Owner loadOwner(int id) {
+ return (Owner) sessionFactory.getCurrentSession().load(Owner.class, id);
+ }
+
+ @Transactional(readOnly = true)
+ public Pet loadPet(int id) {
+ return (Pet) sessionFactory.getCurrentSession().load(Pet.class, id);
+ }
+
+ public void storeOwner(Owner owner) {
+ // Note: Hibernate3's merge operation does not reassociate the object
+ // with the current Hibernate Session. Instead, it will always copy the
+ // state over to a registered representation of the entity. In case of a
+ // new entity, it will register a copy as well, but will not update the
+ // id of the passed-in object. To still update the ids of the original
+ // objects too, we need to register Spring's
+ // IdTransferringMergeEventListener on our SessionFactory.
+ sessionFactory.getCurrentSession().merge(owner);
+ }
+
+ public void storePet(Pet pet) {
+ sessionFactory.getCurrentSession().merge(pet);
+ }
+
+ public void storeVisit(Visit visit) {
+ sessionFactory.getCurrentSession().merge(visit);
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/hibernate/package.html b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/hibernate/package.html
new file mode 100644
index 00000000000..56c54c796a8
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/hibernate/package.html
@@ -0,0 +1,8 @@
+
+
+
+The classes in this package represent the Hibernate implementation
+of PetClinic's persistence layer.
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jdbc/JdbcPet.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jdbc/JdbcPet.java
new file mode 100644
index 00000000000..963ffdfe033
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jdbc/JdbcPet.java
@@ -0,0 +1,35 @@
+package org.springframework.samples.petclinic.jdbc;
+
+import org.springframework.samples.petclinic.Pet;
+
+/**
+ * Subclass of Pet that carries temporary id properties which
+ * are only relevant for a JDBC implmentation of the Clinic.
+ *
+ * @author Juergen Hoeller
+ * @see SimpleJdbcClinic
+ */
+class JdbcPet extends Pet {
+
+ private int typeId;
+
+ private int ownerId;
+
+
+ public void setTypeId(int typeId) {
+ this.typeId = typeId;
+ }
+
+ public int getTypeId() {
+ return this.typeId;
+ }
+
+ public void setOwnerId(int ownerId) {
+ this.ownerId = ownerId;
+ }
+
+ public int getOwnerId() {
+ return this.ownerId;
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jdbc/SimpleJdbcClinic.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jdbc/SimpleJdbcClinic.java
new file mode 100644
index 00000000000..6794c80ab56
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jdbc/SimpleJdbcClinic.java
@@ -0,0 +1,338 @@
+package org.springframework.samples.petclinic.jdbc;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataAccessException;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
+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.SimpleJdbcInsert;
+import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
+import org.springframework.jmx.export.annotation.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedResource;
+import org.springframework.orm.ObjectRetrievalFailureException;
+import org.springframework.samples.petclinic.Clinic;
+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.Vet;
+import org.springframework.samples.petclinic.Visit;
+import org.springframework.samples.petclinic.util.EntityUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * A simple JDBC-based implementation of the {@link Clinic} interface.
+ *
+ * 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.
+ *
+ *
SimpleJdbcClinic is a rewrite of the AbstractJdbcClinic which was the base
+ * class for JDBC implementations of the Clinic interface for Spring 2.0.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Rob Harrop
+ * @author Sam Brannen
+ * @author Thomas Risberg
+ * @author Mark Fisher
+ */
+@Service
+@ManagedResource("petclinic:type=Clinic")
+public class SimpleJdbcClinic implements Clinic, SimpleJdbcClinicMBean {
+
+ private final Log logger = LogFactory.getLog(getClass());
+
+ private SimpleJdbcTemplate simpleJdbcTemplate;
+
+ private SimpleJdbcInsert insertOwner;
+ private SimpleJdbcInsert insertPet;
+ private SimpleJdbcInsert insertVisit;
+
+ private final List vets = new ArrayList();
+
+
+ @Autowired
+ public void init(DataSource dataSource) {
+ this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
+
+ this.insertOwner = new SimpleJdbcInsert(dataSource)
+ .withTableName("owners")
+ .usingGeneratedKeyColumns("id");
+ this.insertPet = new SimpleJdbcInsert(dataSource)
+ .withTableName("pets")
+ .usingGeneratedKeyColumns("id");
+ this.insertVisit = new SimpleJdbcInsert(dataSource)
+ .withTableName("visits")
+ .usingGeneratedKeyColumns("id");
+ }
+
+
+ /**
+ * Refresh the cache of Vets that the Clinic is holding.
+ * @see org.springframework.samples.petclinic.Clinic#getVets()
+ */
+ @ManagedOperation
+ @Transactional(readOnly = true)
+ public void refreshVetsCache() throws DataAccessException {
+ synchronized (this.vets) {
+ this.logger.info("Refreshing vets cache");
+
+ // Retrieve the list of all vets.
+ this.vets.clear();
+ this.vets.addAll(this.simpleJdbcTemplate.query(
+ "SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
+ ParameterizedBeanPropertyRowMapper.newInstance(Vet.class)));
+
+ // Retrieve the list of all possible specialties.
+ final List specialties = this.simpleJdbcTemplate.query(
+ "SELECT id, name FROM specialties",
+ ParameterizedBeanPropertyRowMapper.newInstance(Specialty.class));
+
+ // Build each vet's list of specialties.
+ for (Vet vet : this.vets) {
+ final List vetSpecialtiesIds = this.simpleJdbcTemplate.query(
+ "SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
+ new ParameterizedRowMapper() {
+ public Integer mapRow(ResultSet rs, int row) throws SQLException {
+ return Integer.valueOf(rs.getInt(1));
+ }},
+ vet.getId().intValue());
+ for (int specialtyId : vetSpecialtiesIds) {
+ Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
+ vet.addSpecialty(specialty);
+ }
+ }
+ }
+ }
+
+
+ // START of Clinic implementation section *******************************
+
+ @Transactional(readOnly = true)
+ public Collection getVets() throws DataAccessException {
+ synchronized (this.vets) {
+ if (this.vets.isEmpty()) {
+ refreshVetsCache();
+ }
+ return this.vets;
+ }
+ }
+
+ @Transactional(readOnly = true)
+ public Collection getPetTypes() throws DataAccessException {
+ return this.simpleJdbcTemplate.query(
+ "SELECT id, name FROM types ORDER BY name",
+ ParameterizedBeanPropertyRowMapper.newInstance(PetType.class));
+ }
+
+ /**
+ * Loads {@link Owner Owners} from the data store by last name, returning
+ * all owners whose last name starts with the given name; also loads
+ * the {@link Pet Pets} and {@link Visit Visits} for the corresponding
+ * owners, if not already loaded.
+ */
+ @Transactional(readOnly = true)
+ public Collection findOwners(String lastName) throws DataAccessException {
+ List owners = this.simpleJdbcTemplate.query(
+ "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like ?",
+ ParameterizedBeanPropertyRowMapper.newInstance(Owner.class),
+ lastName + "%");
+ loadOwnersPetsAndVisits(owners);
+ return owners;
+ }
+
+ /**
+ * Loads the {@link Owner} with the supplied id; also loads
+ * the {@link Pet Pets} and {@link Visit Visits} for the corresponding
+ * owner, if not already loaded.
+ */
+ @Transactional(readOnly = true)
+ public Owner loadOwner(int id) throws DataAccessException {
+ Owner owner;
+ try {
+ owner = this.simpleJdbcTemplate.queryForObject(
+ "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id=?",
+ ParameterizedBeanPropertyRowMapper.newInstance(Owner.class),
+ id);
+ }
+ catch (EmptyResultDataAccessException ex) {
+ throw new ObjectRetrievalFailureException(Owner.class, new Integer(id));
+ }
+ loadPetsAndVisits(owner);
+ return owner;
+ }
+
+ @Transactional(readOnly = true)
+ public Pet loadPet(int id) throws DataAccessException {
+ JdbcPet pet;
+ try {
+ pet = this.simpleJdbcTemplate.queryForObject(
+ "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=?",
+ new JdbcPetRowMapper(),
+ id);
+ }
+ catch (EmptyResultDataAccessException ex) {
+ throw new ObjectRetrievalFailureException(Pet.class, new Integer(id));
+ }
+ Owner owner = loadOwner(pet.getOwnerId());
+ owner.addPet(pet);
+ pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId()));
+ loadVisits(pet);
+ return pet;
+ }
+
+ @Transactional
+ public void storeOwner(Owner owner) throws DataAccessException {
+ if (owner.isNew()) {
+ Number newKey = this.insertOwner.executeAndReturnKey(
+ new BeanPropertySqlParameterSource(owner));
+ owner.setId(newKey.intValue());
+ }
+ else {
+ this.simpleJdbcTemplate.update(
+ "UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " +
+ "city=:city, telephone=:telephone WHERE id=:id",
+ new BeanPropertySqlParameterSource(owner));
+ }
+ }
+
+ @Transactional
+ public void storePet(Pet pet) throws DataAccessException {
+ if (pet.isNew()) {
+ Number newKey = this.insertPet.executeAndReturnKey(
+ createPetParameterSource(pet));
+ pet.setId(newKey.intValue());
+ }
+ else {
+ this.simpleJdbcTemplate.update(
+ "UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " +
+ "owner_id=:owner_id WHERE id=:id",
+ createPetParameterSource(pet));
+ }
+ }
+
+ @Transactional
+ public void storeVisit(Visit visit) throws DataAccessException {
+ if (visit.isNew()) {
+ Number newKey = this.insertVisit.executeAndReturnKey(
+ createVisitParameterSource(visit));
+ visit.setId(newKey.intValue());
+ }
+ else {
+ throw new UnsupportedOperationException("Visit update not supported");
+ }
+ }
+
+ // END of Clinic implementation section ************************************
+
+
+ /**
+ * Creates a {@link MapSqlParameterSource} based on data values from the
+ * supplied {@link Pet} instance.
+ */
+ private MapSqlParameterSource createPetParameterSource(Pet pet) {
+ return new MapSqlParameterSource()
+ .addValue("id", pet.getId())
+ .addValue("name", pet.getName())
+ .addValue("birth_date", pet.getBirthDate())
+ .addValue("type_id", pet.getType().getId())
+ .addValue("owner_id", pet.getOwner().getId());
+ }
+
+ /**
+ * Creates a {@link MapSqlParameterSource} based on data values from the
+ * supplied {@link Visit} instance.
+ */
+ private MapSqlParameterSource createVisitParameterSource(Visit visit) {
+ return new MapSqlParameterSource()
+ .addValue("id", visit.getId())
+ .addValue("visit_date", visit.getDate())
+ .addValue("description", visit.getDescription())
+ .addValue("pet_id", visit.getPet().getId());
+ }
+
+ /**
+ * Loads the {@link Visit} data for the supplied {@link Pet}.
+ */
+ private void loadVisits(JdbcPet pet) {
+ final List visits = this.simpleJdbcTemplate.query(
+ "SELECT id, visit_date, description FROM visits WHERE pet_id=?",
+ new ParameterizedRowMapper() {
+ public Visit mapRow(ResultSet rs, int row) throws SQLException {
+ Visit visit = new Visit();
+ visit.setId(rs.getInt("id"));
+ visit.setDate(rs.getTimestamp("visit_date"));
+ visit.setDescription(rs.getString("description"));
+ return visit;
+ }
+ },
+ pet.getId().intValue());
+ for (Visit visit : visits) {
+ pet.addVisit(visit);
+ }
+ }
+
+ /**
+ * Loads the {@link Pet} and {@link Visit} data for the supplied
+ * {@link Owner}.
+ */
+ private void loadPetsAndVisits(final Owner owner) {
+ final List pets = this.simpleJdbcTemplate.query(
+ "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE owner_id=?",
+ new JdbcPetRowMapper(),
+ owner.getId().intValue());
+ for (JdbcPet pet : pets) {
+ owner.addPet(pet);
+ pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId()));
+ loadVisits(pet);
+ }
+ }
+
+ /**
+ * Loads the {@link Pet} and {@link Visit} data for the supplied
+ * {@link List} of {@link Owner Owners}.
+ *
+ * @param owners the list of owners for whom the pet and visit data should be loaded
+ * @see #loadPetsAndVisits(Owner)
+ */
+ private void loadOwnersPetsAndVisits(List owners) {
+ for (Owner owner : owners) {
+ loadPetsAndVisits(owner);
+ }
+ }
+
+ /**
+ * {@link ParameterizedRowMapper} implementation mapping data from a
+ * {@link ResultSet} to the corresponding properties of the {@link JdbcPet} class.
+ */
+ private class JdbcPetRowMapper implements ParameterizedRowMapper {
+
+ 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;
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jdbc/SimpleJdbcClinicMBean.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jdbc/SimpleJdbcClinicMBean.java
new file mode 100644
index 00000000000..c9a7a78478b
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jdbc/SimpleJdbcClinicMBean.java
@@ -0,0 +1,20 @@
+package org.springframework.samples.petclinic.jdbc;
+
+/**
+ * Interface that defines a cache refresh operation.
+ * To be exposed for management via JMX.
+ *
+ * @author Rob Harrop
+ * @author Juergen Hoeller
+ * @see SimpleJdbcClinic
+ */
+public interface SimpleJdbcClinicMBean {
+
+ /**
+ * Refresh the cache of Vets that the Clinic is holding.
+ * @see org.springframework.samples.petclinic.Clinic#getVets()
+ * @see SimpleJdbcClinic#refreshVetsCache()
+ */
+ void refreshVetsCache();
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jdbc/package.html b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jdbc/package.html
new file mode 100644
index 00000000000..f3159f6a149
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jdbc/package.html
@@ -0,0 +1,8 @@
+
+
+
+The classes in this package represent the JDBC implementation
+of PetClinic's persistence layer.
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jpa/EntityManagerClinic.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jpa/EntityManagerClinic.java
new file mode 100644
index 00000000000..ff6907094d4
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jpa/EntityManagerClinic.java
@@ -0,0 +1,90 @@
+package org.springframework.samples.petclinic.jpa;
+
+import java.util.Collection;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import org.springframework.samples.petclinic.Clinic;
+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.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * JPA implementation of the Clinic interface using EntityManager.
+ *
+ * The mappings are defined in "orm.xml" located in the META-INF directory.
+ *
+ * @author Mike Keith
+ * @author Rod Johnson
+ * @author Sam Brannen
+ * @since 22.4.2006
+ */
+@Repository
+@Transactional
+public class EntityManagerClinic implements Clinic {
+
+ @PersistenceContext
+ private EntityManager em;
+
+
+ @Transactional(readOnly = true)
+ @SuppressWarnings("unchecked")
+ public Collection getVets() {
+ return this.em.createQuery("SELECT vet FROM Vet vet ORDER BY vet.lastName, vet.firstName").getResultList();
+ }
+
+ @Transactional(readOnly = true)
+ @SuppressWarnings("unchecked")
+ public Collection getPetTypes() {
+ return this.em.createQuery("SELECT ptype FROM PetType ptype ORDER BY ptype.name").getResultList();
+ }
+
+ @Transactional(readOnly = true)
+ @SuppressWarnings("unchecked")
+ public Collection 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 loadOwner(int id) {
+ return this.em.find(Owner.class, id);
+ }
+
+ @Transactional(readOnly = true)
+ public Pet loadPet(int id) {
+ return this.em.find(Pet.class, id);
+ }
+
+ public void storeOwner(Owner owner) {
+ // Consider returning the persistent object here, for exposing
+ // a newly assigned id using any persistence provider...
+ Owner merged = this.em.merge(owner);
+ this.em.flush();
+ owner.setId(merged.getId());
+ }
+
+ public void storePet(Pet pet) {
+ // Consider returning the persistent object here, for exposing
+ // a newly assigned id using any persistence provider...
+ Pet merged = this.em.merge(pet);
+ this.em.flush();
+ pet.setId(merged.getId());
+ }
+
+ public void storeVisit(Visit visit) {
+ // Consider returning the persistent object here, for exposing
+ // a newly assigned id using any persistence provider...
+ Visit merged = this.em.merge(visit);
+ this.em.flush();
+ visit.setId(merged.getId());
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jpa/package.html b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jpa/package.html
new file mode 100644
index 00000000000..f83c3ff78a7
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/jpa/package.html
@@ -0,0 +1,8 @@
+
+
+
+The classes in this package represent the JPA implementation
+of PetClinic's persistence layer.
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/package.html b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/package.html
new file mode 100644
index 00000000000..5a705c8164c
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/package.html
@@ -0,0 +1,7 @@
+
+
+
+The classes in this package represent PetClinic's business layer.
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/toplink/EssentialsHSQLPlatformWithNativeSequence.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/toplink/EssentialsHSQLPlatformWithNativeSequence.java
new file mode 100644
index 00000000000..1086591decd
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/toplink/EssentialsHSQLPlatformWithNativeSequence.java
@@ -0,0 +1,56 @@
+package org.springframework.samples.petclinic.toplink;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import oracle.toplink.essentials.exceptions.ValidationException;
+import oracle.toplink.essentials.platform.database.HSQLPlatform;
+import oracle.toplink.essentials.queryframework.ValueReadQuery;
+
+/**
+ * Subclass of the TopLink Essentials default HSQLPlatform class, using native
+ * HSQLDB identity columns for id generation.
+ *
+ * Necessary for PetClinic's default data model, which relies on identity
+ * columns: this is uniformly used across all persistence layer implementations
+ * (JDBC, Hibernate, and JPA).
+ *
+ * @author Juergen Hoeller
+ * @author James Clark
+ * @since 1.2
+ */
+public class EssentialsHSQLPlatformWithNativeSequence extends HSQLPlatform {
+
+ private static final long serialVersionUID = -55658009691346735L;
+
+
+ public EssentialsHSQLPlatformWithNativeSequence() {
+ // setUsesNativeSequencing(true);
+ }
+
+ @Override
+ public boolean supportsNativeSequenceNumbers() {
+ return true;
+ }
+
+ @Override
+ public boolean shouldNativeSequenceAcquireValueAfterInsert() {
+ return true;
+ }
+
+ @Override
+ public ValueReadQuery buildSelectQueryForNativeSequence() {
+ return new ValueReadQuery("CALL IDENTITY()");
+ }
+
+ @Override
+ public void printFieldIdentityClause(Writer writer) throws ValidationException {
+ try {
+ writer.write(" IDENTITY");
+ }
+ catch (IOException ex) {
+ throw ValidationException.fileError(ex);
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/toplink/package.html b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/toplink/package.html
new file mode 100644
index 00000000000..2782b4ce906
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/toplink/package.html
@@ -0,0 +1,8 @@
+
+
+
+The classes in this package provide support for using the TopLink
+implementation with PetClinic's EntityManagerClinic.
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/util/EntityUtils.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/util/EntityUtils.java
new file mode 100644
index 00000000000..16df5fa9a91
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/util/EntityUtils.java
@@ -0,0 +1,41 @@
+
+package org.springframework.samples.petclinic.util;
+
+import java.util.Collection;
+
+import org.springframework.orm.ObjectRetrievalFailureException;
+import org.springframework.samples.petclinic.BaseEntity;
+
+/**
+ * Utility methods for handling entities. Separate from the BaseEntity class
+ * mainly because of dependency on the ORM-associated
+ * ObjectRetrievalFailureException.
+ *
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ * @since 29.10.2003
+ * @see org.springframework.samples.petclinic.BaseEntity
+ */
+public abstract class EntityUtils {
+
+ /**
+ * Look up the entity of the given class with the given id in the given
+ * collection.
+ *
+ * @param entities the collection to search
+ * @param entityClass the entity class to look up
+ * @param entityId the entity id to look up
+ * @return the found entity
+ * @throws ObjectRetrievalFailureException if the entity was not found
+ */
+ public static T getById(Collection entities, Class entityClass, int entityId)
+ throws ObjectRetrievalFailureException {
+ for (T entity : entities) {
+ if (entity.getId().intValue() == entityId && entityClass.isInstance(entity)) {
+ return entity;
+ }
+ }
+ throw new ObjectRetrievalFailureException(entityClass, new Integer(entityId));
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/validation/OwnerValidator.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/validation/OwnerValidator.java
new file mode 100644
index 00000000000..04b6b7d58af
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/validation/OwnerValidator.java
@@ -0,0 +1,43 @@
+package org.springframework.samples.petclinic.validation;
+
+import org.springframework.samples.petclinic.Owner;
+import org.springframework.util.StringUtils;
+import org.springframework.validation.Errors;
+
+/**
+ * Validator for Owner forms.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ */
+public class OwnerValidator {
+
+ public void validate(Owner owner, Errors errors) {
+ if (!StringUtils.hasLength(owner.getFirstName())) {
+ errors.rejectValue("firstName", "required", "required");
+ }
+ if (!StringUtils.hasLength(owner.getLastName())) {
+ errors.rejectValue("lastName", "required", "required");
+ }
+ if (!StringUtils.hasLength(owner.getAddress())) {
+ errors.rejectValue("address", "required", "required");
+ }
+ if (!StringUtils.hasLength(owner.getCity())) {
+ errors.rejectValue("city", "required", "required");
+ }
+
+ String telephone = owner.getTelephone();
+ if (!StringUtils.hasLength(telephone)) {
+ errors.rejectValue("telephone", "required", "required");
+ }
+ else {
+ for (int i = 0; i < telephone.length(); ++i) {
+ if ((Character.isDigit(telephone.charAt(i))) == false) {
+ errors.rejectValue("telephone", "nonNumeric", "non-numeric");
+ break;
+ }
+ }
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/validation/PetValidator.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/validation/PetValidator.java
new file mode 100644
index 00000000000..8ad6eb0ac03
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/validation/PetValidator.java
@@ -0,0 +1,25 @@
+package org.springframework.samples.petclinic.validation;
+
+import org.springframework.samples.petclinic.Pet;
+import org.springframework.util.StringUtils;
+import org.springframework.validation.Errors;
+
+/**
+ * Validator for Pet forms.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ */
+public class PetValidator {
+
+ public void validate(Pet pet, Errors errors) {
+ String name = pet.getName();
+ if (!StringUtils.hasLength(name)) {
+ errors.rejectValue("name", "required", "required");
+ }
+ else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) {
+ errors.rejectValue("name", "duplicate", "already exists");
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/validation/VisitValidator.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/validation/VisitValidator.java
new file mode 100644
index 00000000000..35c80bafa10
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/validation/VisitValidator.java
@@ -0,0 +1,21 @@
+package org.springframework.samples.petclinic.validation;
+
+import org.springframework.samples.petclinic.Visit;
+import org.springframework.util.StringUtils;
+import org.springframework.validation.Errors;
+
+/**
+ * Validator for Visit forms.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ */
+public class VisitValidator {
+
+ public void validate(Visit visit, Errors errors) {
+ if (!StringUtils.hasLength(visit.getDescription())) {
+ errors.rejectValue("description", "required", "required");
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/validation/package.html b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/validation/package.html
new file mode 100644
index 00000000000..f83530e221b
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/validation/package.html
@@ -0,0 +1,8 @@
+
+
+
+The classes in this package represent the set of Validator objects
+the Business Layer makes available to the Presentation Layer.
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/AddOwnerForm.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/AddOwnerForm.java
new file mode 100644
index 00000000000..4f05867d325
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/AddOwnerForm.java
@@ -0,0 +1,62 @@
+package org.springframework.samples.petclinic.web;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.samples.petclinic.Clinic;
+import org.springframework.samples.petclinic.Owner;
+import org.springframework.samples.petclinic.validation.OwnerValidator;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.SessionAttributes;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.support.SessionStatus;
+import org.springframework.web.bind.WebDataBinder;
+
+/**
+ * JavaBean form controller that is used to add a new Owner to
+ * the system.
+ *
+ * @author Juergen Hoeller
+ * @author Ken Krebs
+ */
+@Controller
+@RequestMapping("/addOwner.do")
+@SessionAttributes(types = Owner.class)
+public class AddOwnerForm {
+
+ private final Clinic clinic;
+
+ @Autowired
+ public AddOwnerForm(Clinic clinic) {
+ this.clinic = clinic;
+ }
+
+ @InitBinder
+ public void setAllowedFields(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields(new String[] {"id"});
+ }
+
+ @RequestMapping(method = RequestMethod.GET)
+ public String setupForm(Model model) {
+ Owner owner = new Owner();
+ model.addAttribute(owner);
+ return "ownerForm";
+ }
+
+ @RequestMapping(method = RequestMethod.POST)
+ public String processSubmit(@ModelAttribute Owner owner, BindingResult result, SessionStatus status) {
+ new OwnerValidator().validate(owner, result);
+ if (result.hasErrors()) {
+ return "ownerForm";
+ }
+ else {
+ this.clinic.storeOwner(owner);
+ status.setComplete();
+ return "redirect:owner.do?ownerId=" + owner.getId();
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/AddPetForm.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/AddPetForm.java
new file mode 100644
index 00000000000..62d72349796
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/AddPetForm.java
@@ -0,0 +1,74 @@
+package org.springframework.samples.petclinic.web;
+
+import java.util.Collection;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.samples.petclinic.Clinic;
+import org.springframework.samples.petclinic.Owner;
+import org.springframework.samples.petclinic.Pet;
+import org.springframework.samples.petclinic.PetType;
+import org.springframework.samples.petclinic.validation.PetValidator;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.SessionAttributes;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.support.SessionStatus;
+import org.springframework.web.bind.WebDataBinder;
+
+/**
+ * JavaBean form controller that is used to add a new Pet to the
+ * system.
+ *
+ * @author Juergen Hoeller
+ * @author Ken Krebs
+ */
+@Controller
+@RequestMapping("/addPet.do")
+@SessionAttributes("pet")
+public class AddPetForm {
+
+ private final Clinic clinic;
+
+ @Autowired
+ public AddPetForm(Clinic clinic) {
+ this.clinic = clinic;
+ }
+
+ @ModelAttribute("types")
+ public Collection populatePetTypes() {
+ return this.clinic.getPetTypes();
+ }
+
+ @InitBinder
+ public void setAllowedFields(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields(new String[] {"id"});
+ }
+
+ @RequestMapping(method = RequestMethod.GET)
+ public String setupForm(@RequestParam("ownerId") int ownerId, Model model) {
+ Owner owner = this.clinic.loadOwner(ownerId);
+ Pet pet = new Pet();
+ owner.addPet(pet);
+ model.addAttribute("pet", pet);
+ return "petForm";
+ }
+
+ @RequestMapping(method = RequestMethod.POST)
+ public String processSubmit(@ModelAttribute("pet") Pet pet, BindingResult result, SessionStatus status) {
+ new PetValidator().validate(pet, result);
+ if (result.hasErrors()) {
+ return "petForm";
+ }
+ else {
+ this.clinic.storePet(pet);
+ status.setComplete();
+ return "redirect:owner.do?ownerId=" + pet.getOwner().getId();
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/AddVisitForm.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/AddVisitForm.java
new file mode 100644
index 00000000000..10015e18bc5
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/AddVisitForm.java
@@ -0,0 +1,66 @@
+package org.springframework.samples.petclinic.web;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.samples.petclinic.Clinic;
+import org.springframework.samples.petclinic.Pet;
+import org.springframework.samples.petclinic.Visit;
+import org.springframework.samples.petclinic.validation.VisitValidator;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.SessionAttributes;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.support.SessionStatus;
+import org.springframework.web.bind.WebDataBinder;
+
+/**
+ * JavaBean form controller that is used to add a new Visit to
+ * the system.
+ *
+ * @author Juergen Hoeller
+ * @author Ken Krebs
+ */
+@Controller
+@RequestMapping("/addVisit.do")
+@SessionAttributes("visit")
+public class AddVisitForm {
+
+ private final Clinic clinic;
+
+ @Autowired
+ public AddVisitForm(Clinic clinic) {
+ this.clinic = clinic;
+ }
+
+ @InitBinder
+ public void setAllowedFields(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields(new String[] {"id"});
+ }
+
+ @RequestMapping(method = RequestMethod.GET)
+ public String setupForm(@RequestParam("petId") int petId, Model model) {
+ Pet pet = this.clinic.loadPet(petId);
+ Visit visit = new Visit();
+ pet.addVisit(visit);
+ model.addAttribute("visit", visit);
+ return "visitForm";
+ }
+
+ @RequestMapping(method = RequestMethod.POST)
+ public String processSubmit(@ModelAttribute("visit") Visit visit, BindingResult result, SessionStatus status) {
+ new VisitValidator().validate(visit, result);
+ if (result.hasErrors()) {
+ return "visitForm";
+ }
+ else {
+ this.clinic.storeVisit(visit);
+ status.setComplete();
+ return "redirect:owner.do?ownerId=" + visit.getPet().getOwner().getId();
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/ClinicBindingInitializer.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/ClinicBindingInitializer.java
new file mode 100644
index 00000000000..2d2a8bdc15f
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/ClinicBindingInitializer.java
@@ -0,0 +1,37 @@
+package org.springframework.samples.petclinic.web;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.propertyeditors.CustomDateEditor;
+import org.springframework.beans.propertyeditors.StringTrimmerEditor;
+import org.springframework.samples.petclinic.Clinic;
+import org.springframework.samples.petclinic.PetType;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.support.WebBindingInitializer;
+import org.springframework.web.context.request.WebRequest;
+
+/**
+ * Shared WebBindingInitializer for PetClinic's custom editors.
+ *
+ * Alternatively, such init-binder code may be put into
+ * {@link org.springframework.web.bind.annotation.InitBinder}
+ * annotated methods on the controller classes themselves.
+ *
+ * @author Juergen Hoeller
+ */
+public class ClinicBindingInitializer implements WebBindingInitializer {
+
+ @Autowired
+ private Clinic clinic;
+
+ public void initBinder(WebDataBinder binder, WebRequest request) {
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ dateFormat.setLenient(false);
+ binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
+ binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
+ binder.registerCustomEditor(PetType.class, new PetTypeEditor(this.clinic));
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/ClinicController.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/ClinicController.java
new file mode 100644
index 00000000000..5ac90f581ec
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/ClinicController.java
@@ -0,0 +1,72 @@
+
+package org.springframework.samples.petclinic.web;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.samples.petclinic.Clinic;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * Annotation-driven MultiActionController that handles all non-form
+ * URL's.
+ *
+ * @author Juergen Hoeller
+ * @author Mark Fisher
+ * @author Ken Krebs
+ */
+@Controller
+public class ClinicController {
+
+ private final Clinic clinic;
+
+
+ @Autowired
+ public ClinicController(Clinic clinic) {
+ this.clinic = clinic;
+ }
+
+ /**
+ * Custom handler for the welcome view.
+ *
+ * Note that this handler relies on the RequestToViewNameTranslator to
+ * determine the logical view name based on the request URL: "/welcome.do"
+ * -> "welcome".
+ */
+ @RequestMapping("/welcome.do")
+ public void welcomeHandler() {
+ }
+
+ /**
+ * Custom handler for displaying vets.
+ *
+ * Note that this handler returns a plain {@link ModelMap} object instead of
+ * a ModelAndView, thus leveraging convention-based model attribute names.
+ * It relies on the RequestToViewNameTranslator to determine the logical
+ * view name based on the request URL: "/vets.do" -> "vets".
+ *
+ * @return a ModelMap with the model attributes for the view
+ */
+ @RequestMapping("/vets.do")
+ public ModelMap vetsHandler() {
+ return new ModelMap(this.clinic.getVets());
+ }
+
+ /**
+ * Custom handler for displaying an owner.
+ *
+ * Note that this handler returns a plain {@link ModelMap} object instead of
+ * a ModelAndView, thus leveraging convention-based model attribute names.
+ * It relies on the RequestToViewNameTranslator to determine the logical
+ * view name based on the request URL: "/owner.do" -> "owner".
+ *
+ * @param ownerId the ID of the owner to display
+ * @return a ModelMap with the model attributes for the view
+ */
+ @RequestMapping("/owner.do")
+ public ModelMap ownerHandler(@RequestParam("ownerId") int ownerId) {
+ return new ModelMap(this.clinic.loadOwner(ownerId));
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/EditOwnerForm.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/EditOwnerForm.java
new file mode 100644
index 00000000000..424c184c54a
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/EditOwnerForm.java
@@ -0,0 +1,62 @@
+package org.springframework.samples.petclinic.web;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.samples.petclinic.Clinic;
+import org.springframework.samples.petclinic.Owner;
+import org.springframework.samples.petclinic.validation.OwnerValidator;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.SessionAttributes;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.support.SessionStatus;
+import org.springframework.web.bind.WebDataBinder;
+
+/**
+ * JavaBean Form controller that is used to edit an existing Owner.
+ *
+ * @author Juergen Hoeller
+ * @author Ken Krebs
+ */
+@Controller
+@RequestMapping("/editOwner.do")
+@SessionAttributes(types = Owner.class)
+public class EditOwnerForm {
+
+ private final Clinic clinic;
+
+ @Autowired
+ public EditOwnerForm(Clinic clinic) {
+ this.clinic = clinic;
+ }
+
+ @InitBinder
+ public void setAllowedFields(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields(new String[] {"id"});
+ }
+
+ @RequestMapping(method = RequestMethod.GET)
+ public String setupForm(@RequestParam("ownerId") int ownerId, Model model) {
+ Owner owner = this.clinic.loadOwner(ownerId);
+ model.addAttribute(owner);
+ return "ownerForm";
+ }
+
+ @RequestMapping(method = RequestMethod.POST)
+ public String processSubmit(@ModelAttribute Owner owner, BindingResult result, SessionStatus status) {
+ new OwnerValidator().validate(owner, result);
+ if (result.hasErrors()) {
+ return "ownerForm";
+ }
+ else {
+ this.clinic.storeOwner(owner);
+ status.setComplete();
+ return "redirect:owner.do?ownerId=" + owner.getId();
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/EditPetForm.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/EditPetForm.java
new file mode 100644
index 00000000000..0a1033e669f
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/EditPetForm.java
@@ -0,0 +1,70 @@
+package org.springframework.samples.petclinic.web;
+
+import java.util.Collection;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.samples.petclinic.Clinic;
+import org.springframework.samples.petclinic.Pet;
+import org.springframework.samples.petclinic.PetType;
+import org.springframework.samples.petclinic.validation.PetValidator;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.SessionAttributes;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.support.SessionStatus;
+import org.springframework.web.bind.WebDataBinder;
+
+/**
+ * JavaBean Form controller that is used to edit an existing Pet.
+ *
+ * @author Juergen Hoeller
+ * @author Ken Krebs
+ */
+@Controller
+@RequestMapping("/editPet.do")
+@SessionAttributes("pet")
+public class EditPetForm {
+
+ private final Clinic clinic;
+
+ @Autowired
+ public EditPetForm(Clinic clinic) {
+ this.clinic = clinic;
+ }
+
+ @ModelAttribute("types")
+ public Collection populatePetTypes() {
+ return this.clinic.getPetTypes();
+ }
+
+ @InitBinder
+ public void setAllowedFields(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields(new String[] {"id"});
+ }
+
+ @RequestMapping(method = RequestMethod.GET)
+ public String setupForm(@RequestParam("petId") int petId, Model model) {
+ Pet pet = this.clinic.loadPet(petId);
+ model.addAttribute("pet", pet);
+ return "petForm";
+ }
+
+ @RequestMapping(method = RequestMethod.POST)
+ public String processSubmit(@ModelAttribute("pet") Pet pet, BindingResult result, SessionStatus status) {
+ new PetValidator().validate(pet, result);
+ if (result.hasErrors()) {
+ return "petForm";
+ }
+ else {
+ this.clinic.storePet(pet);
+ status.setComplete();
+ return "redirect:owner.do?ownerId=" + pet.getOwner().getId();
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/FindOwnersForm.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/FindOwnersForm.java
new file mode 100644
index 00000000000..e0ea8efdf2f
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/FindOwnersForm.java
@@ -0,0 +1,66 @@
+package org.springframework.samples.petclinic.web;
+
+import java.util.Collection;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.samples.petclinic.Clinic;
+import org.springframework.samples.petclinic.Owner;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.WebDataBinder;
+
+/**
+ * JavaBean Form controller that is used to search for Owners by
+ * last name.
+ *
+ * @author Juergen Hoeller
+ * @author Ken Krebs
+ */
+@Controller
+@RequestMapping("/findOwners.do")
+public class FindOwnersForm {
+
+ private final Clinic clinic;
+
+ @Autowired
+ public FindOwnersForm(Clinic clinic) {
+ this.clinic = clinic;
+ }
+
+ @InitBinder
+ public void setAllowedFields(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields(new String[] {"id"});
+ }
+
+ @RequestMapping(method = RequestMethod.GET)
+ public String setupForm(Model model) {
+ model.addAttribute("owner", new Owner());
+ return "findOwners";
+ }
+
+ @RequestMapping(method = RequestMethod.POST)
+ public String processSubmit(Owner owner, BindingResult result, Model model) {
+ // find owners by last name
+ Collection results = this.clinic.findOwners(owner.getLastName());
+ if (results.size() < 1) {
+ // no owners found
+ result.rejectValue("lastName", "notFound", "not found");
+ return "findOwners";
+ }
+ if (results.size() > 1) {
+ // multiple owners found
+ model.addAttribute("selections", results);
+ return "owners";
+ }
+ else {
+ // 1 owner found
+ owner = results.iterator().next();
+ return "redirect:owner.do?ownerId=" + owner.getId();
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/PetTypeEditor.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/PetTypeEditor.java
new file mode 100644
index 00000000000..812b648d711
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/PetTypeEditor.java
@@ -0,0 +1,30 @@
+package org.springframework.samples.petclinic.web;
+
+import java.beans.PropertyEditorSupport;
+
+import org.springframework.samples.petclinic.Clinic;
+import org.springframework.samples.petclinic.PetType;
+
+/**
+ * @author Mark Fisher
+ * @author Juergen Hoeller
+ */
+public class PetTypeEditor extends PropertyEditorSupport {
+
+ private final Clinic clinic;
+
+
+ public PetTypeEditor(Clinic clinic) {
+ this.clinic = clinic;
+ }
+
+ @Override
+ public void setAsText(String text) throws IllegalArgumentException {
+ for (PetType type : this.clinic.getPetTypes()) {
+ if (type.getName().equals(text)) {
+ setValue(type);
+ }
+ }
+ }
+
+}
diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/package.html b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/package.html
new file mode 100644
index 00000000000..fe2089a3fcb
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/web/package.html
@@ -0,0 +1,7 @@
+
+
+
+The classes in this package represent PetClinic's web presentation layer.
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/java/overview.html b/org.springframework.samples.petclinic/src/main/java/overview.html
new file mode 100644
index 00000000000..1eb7a2e8c19
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/java/overview.html
@@ -0,0 +1,7 @@
+
+
+
+The Spring Data Binding framework, an internal library used by Spring Web Flow.
+
+
+
\ No newline at end of file
diff --git a/org.springframework.samples.petclinic/src/main/resources/META-INF/aop.xml b/org.springframework.samples.petclinic/src/main/resources/META-INF/aop.xml
new file mode 100644
index 00000000000..b49ffd8b19a
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/resources/META-INF/aop.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/resources/META-INF/orm.xml b/org.springframework.samples.petclinic/src/main/resources/META-INF/orm.xml
new file mode 100644
index 00000000000..d7c8f7040a1
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/resources/META-INF/orm.xml
@@ -0,0 +1,122 @@
+
+
+
+
+
+
+ PROPERTY
+
+
+
+ org.springframework.samples.petclinic
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ DATE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ DATE
+
+
+
+
+
+
+
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/resources/META-INF/persistence.xml b/org.springframework.samples.petclinic/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 00000000000..86bf7c115d8
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+ META-INF/orm.xml
+
+
+ true
+
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/resources/jdbc.properties b/org.springframework.samples.petclinic/src/main/resources/jdbc.properties
new file mode 100644
index 00000000000..4a05a4620e6
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/resources/jdbc.properties
@@ -0,0 +1,48 @@
+# Properties file with JDBC and JPA settings.
+#
+# Applied by from
+# various application context XML files (e.g., "applicationContext-*.xml").
+# Targeted at system administrators, to avoid touching the context XML files.
+
+#-------------------------------------------------------------------------------
+# Common Settings
+
+hibernate.generate_statistics=true
+hibernate.show_sql=true
+jpa.showSql=true
+
+#-------------------------------------------------------------------------------
+# HSQL Settings
+
+jdbc.driverClassName=org.hsqldb.jdbcDriver
+jdbc.url=jdbc:hsqldb:hsql://localhost:9001
+jdbc.username=sa
+jdbc.password=
+
+# Property that determines which Hibernate dialect to use
+# (only applied with "applicationContext-hibernate.xml")
+hibernate.dialect=org.hibernate.dialect.HSQLDialect
+
+# Property that determines which JPA DatabasePlatform to use with TopLink Essentials
+jpa.databasePlatform=org.springframework.samples.petclinic.toplink.EssentialsHSQLPlatformWithNativeSequence
+
+# Property that determines which database to use with an AbstractJpaVendorAdapter
+jpa.database=HSQL
+
+#-------------------------------------------------------------------------------
+# MySQL Settings
+
+#jdbc.driverClassName=com.mysql.jdbc.Driver
+#jdbc.url=jdbc:mysql://localhost:3306/petclinic
+#jdbc.username=pc
+#jdbc.password=pc
+
+# Property that determines which Hibernate dialect to use
+# (only applied with "applicationContext-hibernate.xml")
+#hibernate.dialect=org.hibernate.dialect.MySQLDialect
+
+# Property that determines which JPA DatabasePlatform to use with TopLink Essentials
+#jpa.databasePlatform=oracle.toplink.essentials.platform.database.MySQL4Platform
+
+# Property that determines which database to use with an AbstractJpaVendorAdapter
+#jpa.database=MYSQL
diff --git a/org.springframework.samples.petclinic/src/main/resources/petclinic.hbm.xml b/org.springframework.samples.petclinic/src/main/resources/petclinic.hbm.xml
new file mode 100644
index 00000000000..f9a993cf121
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/resources/petclinic.hbm.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/webapp/META-INF/context.xml b/org.springframework.samples.petclinic/src/main/webapp/META-INF/context.xml
new file mode 100644
index 00000000000..d5deabaf701
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/webapp/META-INF/context.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/applicationContext-hibernate.xml b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/applicationContext-hibernate.xml
new file mode 100644
index 00000000000..bfc166db625
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/applicationContext-hibernate.xml
@@ -0,0 +1,89 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ${hibernate.dialect}
+ ${hibernate.show_sql}
+ ${hibernate.generate_statistics}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/applicationContext-jdbc.xml b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/applicationContext-jdbc.xml
new file mode 100644
index 00000000000..2a50b4905b5
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/applicationContext-jdbc.xml
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/applicationContext-jpa.xml b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/applicationContext-jpa.xml
new file mode 100644
index 00000000000..25374e9abe2
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/applicationContext-jpa.xml
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/classes/log4j.properties b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/classes/log4j.properties
new file mode 100644
index 00000000000..ebee551aa88
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/classes/log4j.properties
@@ -0,0 +1,18 @@
+# For JBoss: Avoid to setup Log4J outside $JBOSS_HOME/server/default/deploy/log4j.xml!
+# For all other servers: Comment out the Log4J listener in web.xml to activate Log4J.
+log4j.rootLogger=INFO, stdout, logfile
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
+
+log4j.appender.logfile=org.apache.log4j.RollingFileAppender
+log4j.appender.logfile.File=${petclinic.root}/WEB-INF/petclinic.log
+log4j.appender.logfile.MaxFileSize=512KB
+# Keep three backup files.
+log4j.appender.logfile.MaxBackupIndex=3
+# Pattern to output: date priority [category] - message
+log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
+log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
+
+log4j.logger.org.springframework.samples.petclinic.aspects=DEBUG
diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/classes/messages.properties b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/classes/messages.properties
new file mode 100644
index 00000000000..173417a1014
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/classes/messages.properties
@@ -0,0 +1,8 @@
+welcome=Welcome
+required=is required
+notFound=has not been found
+duplicate=is already in use
+nonNumeric=must be all numeric
+duplicateFormSubmission=Duplicate form submission is not allowed
+typeMismatch.date=invalid date
+typeMismatch.birthDate=invalid date
diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/classes/messages_de.properties b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/classes/messages_de.properties
new file mode 100644
index 00000000000..124bee48b2c
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/classes/messages_de.properties
@@ -0,0 +1,8 @@
+welcome=Willkommen
+required=muss angegeben werden
+notFound=wurde nicht gefunden
+duplicate=ist bereits vergeben
+nonNumeric=darf nur numerisch sein
+duplicateFormSubmission=Wiederholtes Absenden des Formulars ist nicht erlaubt
+typeMismatch.date=ungültiges Datum
+typeMismatch.birthDate=ungültiges Datum
diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/classes/messages_en.properties b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/classes/messages_en.properties
new file mode 100644
index 00000000000..05d519bb86d
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/classes/messages_en.properties
@@ -0,0 +1 @@
+# This file is intentionally empty. Message look-ups will fall back to the default "messages.properties" file.
\ No newline at end of file
diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/geronimo-web.xml b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/geronimo-web.xml
new file mode 100644
index 00000000000..b5d88e1ecd2
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/geronimo-web.xml
@@ -0,0 +1,6 @@
+
+
+ /petclinic
+ true
+
\ No newline at end of file
diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/jsp/dataAccessFailure.jsp b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/jsp/dataAccessFailure.jsp
new file mode 100644
index 00000000000..1a2c758e899
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/jsp/dataAccessFailure.jsp
@@ -0,0 +1,19 @@
+<%@ include file="/WEB-INF/jsp/includes.jsp" %>
+<%@ include file="/WEB-INF/jsp/header.jsp" %>
+
+<%
+Exception ex = (Exception) request.getAttribute("exception");
+%>
+
+Data access failure: <%= ex.getMessage() %>
+
+
+<%
+ex.printStackTrace(new java.io.PrintWriter(out));
+%>
+
+
+
+">Home
+
+<%@ include file="/WEB-INF/jsp/footer.jsp" %>
diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/jsp/findOwners.jsp b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/jsp/findOwners.jsp
new file mode 100644
index 00000000000..c2c15e080ea
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/jsp/findOwners.jsp
@@ -0,0 +1,24 @@
+<%@ include file="/WEB-INF/jsp/includes.jsp" %>
+<%@ include file="/WEB-INF/jsp/header.jsp" %>
+
+Find Owners:
+
+
+
+
+
+
+">Add Owner
+
+<%@ include file="/WEB-INF/jsp/footer.jsp" %>
diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/jsp/footer.jsp b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/jsp/footer.jsp
new file mode 100644
index 00000000000..c9b0ac1b377
--- /dev/null
+++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/jsp/footer.jsp
@@ -0,0 +1,12 @@
+
+
+
+
+