- Petclinic uses XML configuration by default. In case you'd like to use Java Config instead, there is a Java Config branch available here. Thanks to Antoine Rey for his contribution.
-
+The Spring Petclinic "main" branch in the [spring-projects](https://github.com/spring-projects/spring-petclinic)
+GitHub org is the "canonical" implementation based on Spring Boot and Thymeleaf. There are
+[quite a few forks](https://spring-petclinic.github.io/docs/forks.html) in the GitHub org
+[spring-petclinic](https://github.com/spring-petclinic). If you are interested in using a different technology stack to implement the Pet Clinic, please join the community there.
## Interaction with other open source projects
-One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found some bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days.
+One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days.
Here is a list of them:
-
-
-
Name
-
Issue
-
-
-
-
Spring JDBC: simplify usage of NamedParameterJdbcTemplate
+| Name | Issue |
+|------|-------|
+| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://jira.springsource.org/browse/SPR-10256) and [SPR-10257](https://jira.springsource.org/browse/SPR-10257) |
+| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility |[HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) |
+| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://jira.springsource.org/browse/DATAJPA-292) |
+# Contributing
+The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, features requests and submitting pull requests.
+
+For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at . If you have not previously done so, please fill out and submit the [Contributor License Agreement](https://cla.pivotal.io/sign/spring).
+
+# License
+
+The Spring PetClinic sample application is released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0).
+
+[spring-petclinic]: https://github.com/spring-projects/spring-petclinic
+[spring-framework-petclinic]: https://github.com/spring-petclinic/spring-framework-petclinic
+[spring-petclinic-angularjs]: https://github.com/spring-petclinic/spring-petclinic-angularjs
+[javaconfig branch]: https://github.com/spring-petclinic/spring-framework-petclinic/tree/javaconfig
+[spring-petclinic-angular]: https://github.com/spring-petclinic/spring-petclinic-angular
+[spring-petclinic-microservices]: https://github.com/spring-petclinic/spring-petclinic-microservices
+[spring-petclinic-reactjs]: https://github.com/spring-petclinic/spring-petclinic-reactjs
+[spring-petclinic-graphql]: https://github.com/spring-petclinic/spring-petclinic-graphql
+[spring-petclinic-kotlin]: https://github.com/spring-petclinic/spring-petclinic-kotlin
+[spring-petclinic-rest]: https://github.com/spring-petclinic/spring-petclinic-rest
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 000000000..e60ee14fa
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'spring-petclinic'
diff --git a/src/checkstyle/nohttp-checkstyle-suppressions.xml b/src/checkstyle/nohttp-checkstyle-suppressions.xml
new file mode 100644
index 000000000..58da146fa
--- /dev/null
+++ b/src/checkstyle/nohttp-checkstyle-suppressions.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/checkstyle/nohttp-checkstyle.xml b/src/checkstyle/nohttp-checkstyle.xml
new file mode 100644
index 000000000..e6205127b
--- /dev/null
+++ b/src/checkstyle/nohttp-checkstyle.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java b/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java
new file mode 100644
index 000000000..ac6e15030
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.samples.petclinic;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ImportRuntimeHints;
+
+/**
+ * PetClinic Spring Boot Application.
+ *
+ * @author Dave Syer
+ *
+ */
+@SpringBootApplication
+@ImportRuntimeHints(PetClinicRuntimeHints.class)
+public class PetClinicApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(PetClinicApplication.class, args);
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/PetClinicRuntimeHints.java b/src/main/java/org/springframework/samples/petclinic/PetClinicRuntimeHints.java
new file mode 100644
index 000000000..2ac7e02e9
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/PetClinicRuntimeHints.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.samples.petclinic;
+
+import org.springframework.aot.hint.RuntimeHints;
+import org.springframework.aot.hint.RuntimeHintsRegistrar;
+
+public class PetClinicRuntimeHints implements RuntimeHintsRegistrar {
+
+ @Override
+ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
+ hints.resources().registerPattern("db/*"); // https://github.com/spring-projects/spring-boot/issues/32654
+ hints.resources().registerPattern("messages/*");
+ hints.resources().registerPattern("META-INF/resources/webjars/*");
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java
index 55b470e1e..3038bce3a 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java
+++ b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,33 +15,37 @@
*/
package org.springframework.samples.petclinic.model;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.MappedSuperclass;
+import java.io.Serializable;
+
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.MappedSuperclass;
/**
- * Simple JavaBean domain object with an id property. Used as a base class for objects needing this property.
+ * Simple JavaBean domain object with an id property. Used as a base class for objects
+ * needing this property.
*
* @author Ken Krebs
* @author Juergen Hoeller
*/
@MappedSuperclass
-public class BaseEntity {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- protected Integer id;
+public class BaseEntity implements Serializable {
- public Integer getId() {
- return id;
- }
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id;
- public void setId(Integer id) {
- this.id = id;
- }
+ public Integer getId() {
+ return id;
+ }
- public boolean isNew() {
- return (this.id == null);
- }
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public boolean isNew() {
+ return this.id == null;
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java b/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java
index d66c97ae7..7c2ccb2d6 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java
+++ b/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,13 +15,12 @@
*/
package org.springframework.samples.petclinic.model;
-import javax.persistence.Column;
-import javax.persistence.MappedSuperclass;
-
+import jakarta.persistence.Column;
+import jakarta.persistence.MappedSuperclass;
/**
- * Simple JavaBean domain object adds a name property to BaseEntity. Used as a base class for objects
- * needing these properties.
+ * 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
@@ -29,20 +28,20 @@ import javax.persistence.MappedSuperclass;
@MappedSuperclass
public class NamedEntity extends BaseEntity {
- @Column(name = "name")
- private String name;
+ @Column(name = "name")
+ private String name;
- public String getName() {
- return this.name;
- }
+ public String getName() {
+ return this.name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- @Override
- public String toString() {
- return this.getName();
- }
+ @Override
+ public String toString() {
+ return this.getName();
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/Owner.java b/src/main/java/org/springframework/samples/petclinic/model/Owner.java
deleted file mode 100644
index d0158d907..000000000
--- a/src/main/java/org/springframework/samples/petclinic/model/Owner.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.model;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
-import javax.validation.constraints.Digits;
-
-import org.hibernate.validator.constraints.NotEmpty;
-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
- * @author Michael Isvy
- */
-@Entity
-@Table(name = "owners")
-public class Owner extends Person {
- @Column(name = "address")
- @NotEmpty
- private String address;
-
- @Column(name = "city")
- @NotEmpty
- private String city;
-
- @Column(name = "telephone")
- @NotEmpty
- @Digits(fraction = 0, integer = 10)
- private String telephone;
-
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
- 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 Set getPetsInternal() {
- if (this.pets == null) {
- this.pets = new HashSet<>();
- }
- return this.pets;
- }
-
- protected void setPetsInternal(Set pets) {
- this.pets = 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/src/main/java/org/springframework/samples/petclinic/model/Person.java b/src/main/java/org/springframework/samples/petclinic/model/Person.java
index d3e03c0dd..e41b6ba90 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/Person.java
+++ b/src/main/java/org/springframework/samples/petclinic/model/Person.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,10 +15,9 @@
*/
package org.springframework.samples.petclinic.model;
-import javax.persistence.Column;
-import javax.persistence.MappedSuperclass;
-
-import org.hibernate.validator.constraints.NotEmpty;
+import jakarta.persistence.Column;
+import jakarta.persistence.MappedSuperclass;
+import jakarta.validation.constraints.NotEmpty;
/**
* Simple JavaBean domain object representing an person.
@@ -28,29 +27,28 @@ import org.hibernate.validator.constraints.NotEmpty;
@MappedSuperclass
public class Person extends BaseEntity {
- @Column(name = "first_name")
- @NotEmpty
- protected String firstName;
+ @Column(name = "first_name")
+ @NotEmpty
+ private String firstName;
- @Column(name = "last_name")
- @NotEmpty
- protected String lastName;
+ @Column(name = "last_name")
+ @NotEmpty
+ private String lastName;
- public String getFirstName() {
- return this.firstName;
- }
+ public String getFirstName() {
+ return this.firstName;
+ }
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
- public String getLastName() {
- return this.lastName;
- }
-
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
+ public String getLastName() {
+ return this.lastName;
+ }
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/Pet.java b/src/main/java/org/springframework/samples/petclinic/model/Pet.java
deleted file mode 100644
index 09eeb769e..000000000
--- a/src/main/java/org/springframework/samples/petclinic/model/Pet.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.model;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
-
-import org.hibernate.annotations.Type;
-import org.joda.time.DateTime;
-import org.springframework.beans.support.MutableSortDefinition;
-import org.springframework.beans.support.PropertyComparator;
-import org.springframework.format.annotation.DateTimeFormat;
-
-/**
- * Simple business object representing a pet.
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Sam Brannen
- */
-@Entity
-@Table(name = "pets")
-public class Pet extends NamedEntity {
-
- @Column(name = "birth_date")
- @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
- @DateTimeFormat(pattern = "yyyy/MM/dd")
- private DateTime birthDate;
-
- @ManyToOne
- @JoinColumn(name = "type_id")
- private PetType type;
-
- @ManyToOne
- @JoinColumn(name = "owner_id")
- private Owner owner;
-
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "pet", fetch = FetchType.EAGER)
- private Set visits;
-
- public DateTime getBirthDate() {
- return this.birthDate;
- }
-
- public void setBirthDate(DateTime birthDate) {
- this.birthDate = birthDate;
- }
-
- public PetType getType() {
- return this.type;
- }
-
- public void setType(PetType type) {
- this.type = type;
- }
-
- public Owner getOwner() {
- return this.owner;
- }
-
- protected void setOwner(Owner owner) {
- this.owner = owner;
- }
-
- protected Set getVisitsInternal() {
- if (this.visits == null) {
- this.visits = new HashSet<>();
- }
- return this.visits;
- }
-
- protected void setVisitsInternal(Set visits) {
- this.visits = 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/src/main/java/org/springframework/samples/petclinic/model/Vet.java b/src/main/java/org/springframework/samples/petclinic/model/Vet.java
deleted file mode 100644
index d93e14c46..000000000
--- a/src/main/java/org/springframework/samples/petclinic/model/Vet.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.model;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
-import javax.persistence.ManyToMany;
-import javax.persistence.Table;
-import javax.xml.bind.annotation.XmlElement;
-
-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
- * @author Arjen Poutsma
- */
-@Entity
-@Table(name = "vets")
-public class Vet extends Person {
-
- @ManyToMany(fetch = FetchType.EAGER)
- @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"),
- inverseJoinColumns = @JoinColumn(name = "specialty_id"))
- private Set specialties;
-
- protected Set getSpecialtiesInternal() {
- if (this.specialties == null) {
- this.specialties = new HashSet<>();
- }
- return this.specialties;
- }
-
- protected void setSpecialtiesInternal(Set specialties) {
- this.specialties = specialties;
- }
-
- @XmlElement
- 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/src/main/java/org/springframework/samples/petclinic/model/Visit.java b/src/main/java/org/springframework/samples/petclinic/model/Visit.java
deleted file mode 100644
index ea03bde74..000000000
--- a/src/main/java/org/springframework/samples/petclinic/model/Visit.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.model;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-
-import org.hibernate.annotations.Type;
-import org.hibernate.validator.constraints.NotEmpty;
-import org.joda.time.DateTime;
-import org.springframework.format.annotation.DateTimeFormat;
-
-/**
- * Simple JavaBean domain object representing a visit.
- *
- * @author Ken Krebs
- */
-@Entity
-@Table(name = "visits")
-public class Visit extends BaseEntity {
-
- /**
- * Holds value of property date.
- */
- @Column(name = "visit_date")
- @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
- @DateTimeFormat(pattern = "yyyy/MM/dd")
- private DateTime date;
-
- /**
- * Holds value of property description.
- */
- @NotEmpty
- @Column(name = "description")
- private String description;
-
- /**
- * Holds value of property pet.
- */
- @ManyToOne
- @JoinColumn(name = "pet_id")
- private Pet pet;
-
-
- /**
- * Creates a new instance of Visit for the current date
- */
- public Visit() {
- this.date = new DateTime();
- }
-
-
- /**
- * Getter for property date.
- *
- * @return Value of property date.
- */
- public DateTime getDate() {
- return this.date;
- }
-
- /**
- * Setter for property date.
- *
- * @param date New value of property date.
- */
- public void setDate(DateTime 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.
- */
- public void setPet(Pet pet) {
- this.pet = pet;
- }
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/package-info.java b/src/main/java/org/springframework/samples/petclinic/model/package-info.java
index 2730958db..37d6295e8 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/package-info.java
+++ b/src/main/java/org/springframework/samples/petclinic/model/package-info.java
@@ -1,5 +1,20 @@
-/**
- * The classes in this package represent PetClinic's business layer.
- */
-package org.springframework.samples.petclinic.model;
-
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * The classes in this package represent utilities used by the domain.
+ */
+package org.springframework.samples.petclinic.model;
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java
new file mode 100644
index 000000000..ac556459d
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.petclinic.owner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.core.style.ToStringCreator;
+import org.springframework.samples.petclinic.model.Person;
+import org.springframework.util.Assert;
+
+import jakarta.persistence.CascadeType;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.FetchType;
+import jakarta.persistence.JoinColumn;
+import jakarta.persistence.OneToMany;
+import jakarta.persistence.OrderBy;
+import jakarta.persistence.Table;
+import jakarta.validation.constraints.Digits;
+import jakarta.validation.constraints.NotEmpty;
+
+/**
+ * Simple JavaBean domain object representing an owner.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ * @author Michael Isvy
+ * @author Oliver Drotbohm
+ */
+@Entity
+@Table(name = "owners")
+public class Owner extends Person {
+
+ @Column(name = "address")
+ @NotEmpty
+ private String address;
+
+ @Column(name = "city")
+ @NotEmpty
+ private String city;
+
+ @Column(name = "telephone")
+ @NotEmpty
+ @Digits(fraction = 0, integer = 10)
+ private String telephone;
+
+ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ @JoinColumn(name = "owner_id")
+ @OrderBy("name")
+ private List pets = new ArrayList<>();
+
+ 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;
+ }
+
+ public List getPets() {
+ return this.pets;
+ }
+
+ public void addPet(Pet pet) {
+ if (pet.isNew()) {
+ getPets().add(pet);
+ }
+ }
+
+ /**
+ * Return the Pet with the given name, or null if none found for this Owner.
+ * @param name to test
+ * @return a pet if pet name is already in use
+ */
+ public Pet getPet(String name) {
+ return getPet(name, false);
+ }
+
+ /**
+ * Return the Pet with the given id, or null if none found for this Owner.
+ * @param id to test
+ * @return a pet if pet id is already in use
+ */
+ public Pet getPet(Integer id) {
+ for (Pet pet : getPets()) {
+ if (!pet.isNew()) {
+ Integer compId = pet.getId();
+ if (compId.equals(id)) {
+ return pet;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the Pet with the given name, or null if none found for this Owner.
+ * @param name to test
+ * @return a pet if pet name is already in use
+ */
+ public Pet getPet(String name, boolean ignoreNew) {
+ name = name.toLowerCase();
+ for (Pet pet : getPets()) {
+ if (!ignoreNew || !pet.isNew()) {
+ String compName = pet.getName();
+ compName = compName == null ? "" : 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();
+ }
+
+ /**
+ * Adds the given {@link Visit} to the {@link Pet} with the given identifier.
+ * @param petId the identifier of the {@link Pet}, must not be {@literal null}.
+ * @param visit the visit to add, must not be {@literal null}.
+ */
+ public void addVisit(Integer petId, Visit visit) {
+
+ Assert.notNull(petId, "Pet identifier must not be null!");
+ Assert.notNull(visit, "Visit must not be null!");
+
+ Pet pet = getPet(petId);
+
+ Assert.notNull(pet, "Invalid Pet identifier!");
+
+ pet.addVisit(visit);
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java
new file mode 100644
index 000000000..c91a94c93
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.petclinic.owner;
+
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
+
+import jakarta.validation.Valid;
+
+/**
+ * @author Juergen Hoeller
+ * @author Ken Krebs
+ * @author Arjen Poutsma
+ * @author Michael Isvy
+ */
+@Controller
+class OwnerController {
+
+ private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
+
+ private final OwnerRepository owners;
+
+ public OwnerController(OwnerRepository clinicService) {
+ this.owners = clinicService;
+ }
+
+ @InitBinder
+ public void setAllowedFields(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields("id");
+ }
+
+ @ModelAttribute("owner")
+ public Owner findOwner(@PathVariable(name = "ownerId", required = false) Integer ownerId) {
+ return ownerId == null ? new Owner() : this.owners.findById(ownerId);
+ }
+
+ @GetMapping("/owners/new")
+ public String initCreationForm(Map model) {
+ Owner owner = new Owner();
+ model.put("owner", owner);
+ return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
+ }
+
+ @PostMapping("/owners/new")
+ public String processCreationForm(@Valid Owner owner, BindingResult result) {
+ if (result.hasErrors()) {
+ return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
+ }
+
+ this.owners.save(owner);
+ return "redirect:/owners/" + owner.getId();
+ }
+
+ @GetMapping("/owners/find")
+ public String initFindForm() {
+ return "owners/findOwners";
+ }
+
+ @GetMapping("/owners")
+ public String processFindForm(@RequestParam(defaultValue = "1") int page, Owner owner, BindingResult result,
+ Model model) {
+ // allow parameterless GET request for /owners to return all records
+ if (owner.getLastName() == null) {
+ owner.setLastName(""); // empty string signifies broadest possible search
+ }
+
+ // find owners by last name
+ Page ownersResults = findPaginatedForOwnersLastName(page, owner.getLastName());
+ if (ownersResults.isEmpty()) {
+ // no owners found
+ result.rejectValue("lastName", "notFound", "not found");
+ return "owners/findOwners";
+ }
+
+ if (ownersResults.getTotalElements() == 1) {
+ // 1 owner found
+ owner = ownersResults.iterator().next();
+ return "redirect:/owners/" + owner.getId();
+ }
+
+ // multiple owners found
+ return addPaginationModel(page, model, ownersResults);
+ }
+
+ private String addPaginationModel(int page, Model model, Page paginated) {
+ model.addAttribute("listOwners", paginated);
+ List listOwners = paginated.getContent();
+ model.addAttribute("currentPage", page);
+ model.addAttribute("totalPages", paginated.getTotalPages());
+ model.addAttribute("totalItems", paginated.getTotalElements());
+ model.addAttribute("listOwners", listOwners);
+ return "owners/ownersList";
+ }
+
+ private Page findPaginatedForOwnersLastName(int page, String lastname) {
+ int pageSize = 5;
+ Pageable pageable = PageRequest.of(page - 1, pageSize);
+ return owners.findByLastName(lastname, pageable);
+ }
+
+ @GetMapping("/owners/{ownerId}/edit")
+ public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
+ Owner owner = this.owners.findById(ownerId);
+ model.addAttribute(owner);
+ return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
+ }
+
+ @PostMapping("/owners/{ownerId}/edit")
+ public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result,
+ @PathVariable("ownerId") int ownerId) {
+ if (result.hasErrors()) {
+ return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
+ }
+
+ owner.setId(ownerId);
+ this.owners.save(owner);
+ return "redirect:/owners/{ownerId}";
+ }
+
+ /**
+ * Custom handler for displaying an owner.
+ * @param ownerId the ID of the owner to display
+ * @return a ModelMap with the model attributes for the view
+ */
+ @GetMapping("/owners/{ownerId}")
+ public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
+ ModelAndView mav = new ModelAndView("owners/ownerDetails");
+ Owner owner = this.owners.findById(ownerId);
+ mav.addObject(owner);
+ return mav;
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java
new file mode 100644
index 000000000..f44449439
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.petclinic.owner;
+
+import java.util.List;
+
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.Repository;
+import org.springframework.data.repository.query.Param;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Repository class for Owner domain objects All method names are compliant
+ * with Spring Data naming conventions so this interface can easily be extended for Spring
+ * Data. See:
+ * https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ * @author Michael Isvy
+ */
+public interface OwnerRepository extends Repository {
+
+ /**
+ * Retrieve all {@link PetType}s from the data store.
+ * @return a Collection of {@link PetType}s.
+ */
+ @Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
+ @Transactional(readOnly = true)
+ List findPetTypes();
+
+ /**
+ * Retrieve {@link Owner}s 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 {@link Owner}s (or an empty Collection if none
+ * found)
+ */
+
+ @Query("SELECT DISTINCT owner FROM Owner owner left join owner.pets WHERE owner.lastName LIKE :lastName% ")
+ @Transactional(readOnly = true)
+ Page findByLastName(@Param("lastName") String lastName, Pageable pageable);
+
+ /**
+ * Retrieve an {@link Owner} from the data store by id.
+ * @param id the id to search for
+ * @return the {@link Owner} if found
+ */
+ @Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
+ @Transactional(readOnly = true)
+ Owner findById(@Param("id") Integer id);
+
+ /**
+ * Save an {@link Owner} to the data store, either inserting or updating it.
+ * @param owner the {@link Owner} to save
+ */
+ void save(Owner owner);
+
+ /**
+ * Returns all the owners from data store
+ **/
+ @Query("SELECT owner FROM Owner owner")
+ @Transactional(readOnly = true)
+ Page findAll(Pageable pageable);
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java b/src/main/java/org/springframework/samples/petclinic/owner/Pet.java
new file mode 100755
index 000000000..0b0c08ac6
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/owner/Pet.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.petclinic.owner;
+
+import java.time.LocalDate;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.samples.petclinic.model.NamedEntity;
+
+import jakarta.persistence.CascadeType;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.FetchType;
+import jakarta.persistence.JoinColumn;
+import jakarta.persistence.ManyToOne;
+import jakarta.persistence.OneToMany;
+import jakarta.persistence.OrderBy;
+import jakarta.persistence.Table;
+
+/**
+ * Simple business object representing a pet.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ */
+@Entity
+@Table(name = "pets")
+public class Pet extends NamedEntity {
+
+ @Column(name = "birth_date")
+ @DateTimeFormat(pattern = "yyyy-MM-dd")
+ private LocalDate birthDate;
+
+ @ManyToOne
+ @JoinColumn(name = "type_id")
+ private PetType type;
+
+ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ @JoinColumn(name = "pet_id")
+ @OrderBy("visit_date ASC")
+ private Set visits = new LinkedHashSet<>();
+
+ public void setBirthDate(LocalDate birthDate) {
+ this.birthDate = birthDate;
+ }
+
+ public LocalDate getBirthDate() {
+ return this.birthDate;
+ }
+
+ public PetType getType() {
+ return this.type;
+ }
+
+ public void setType(PetType type) {
+ this.type = type;
+ }
+
+ public Collection getVisits() {
+ return this.visits;
+ }
+
+ public void addVisit(Visit visit) {
+ getVisits().add(visit);
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java
new file mode 100644
index 000000000..9d88f0399
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.petclinic.owner;
+
+import java.util.Collection;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.util.StringUtils;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import jakarta.validation.Valid;
+
+/**
+ * @author Juergen Hoeller
+ * @author Ken Krebs
+ * @author Arjen Poutsma
+ */
+@Controller
+@RequestMapping("/owners/{ownerId}")
+class PetController {
+
+ private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm";
+
+ private final OwnerRepository owners;
+
+ public PetController(OwnerRepository owners) {
+ this.owners = owners;
+ }
+
+ @ModelAttribute("types")
+ public Collection populatePetTypes() {
+ return this.owners.findPetTypes();
+ }
+
+ @ModelAttribute("owner")
+ public Owner findOwner(@PathVariable("ownerId") int ownerId) {
+ return this.owners.findById(ownerId);
+ }
+
+ @ModelAttribute("pet")
+ public Pet findPet(@PathVariable("ownerId") int ownerId,
+ @PathVariable(name = "petId", required = false) Integer petId) {
+ return petId == null ? new Pet() : this.owners.findById(ownerId).getPet(petId);
+ }
+
+ @InitBinder("owner")
+ public void initOwnerBinder(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields("id");
+ }
+
+ @InitBinder("pet")
+ public void initPetBinder(WebDataBinder dataBinder) {
+ dataBinder.setValidator(new PetValidator());
+ }
+
+ @GetMapping("/pets/new")
+ public String initCreationForm(Owner owner, ModelMap model) {
+ Pet pet = new Pet();
+ owner.addPet(pet);
+ model.put("pet", pet);
+ return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
+ }
+
+ @PostMapping("/pets/new")
+ public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model) {
+ if (StringUtils.hasLength(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null) {
+ result.rejectValue("name", "duplicate", "already exists");
+ }
+
+ owner.addPet(pet);
+ if (result.hasErrors()) {
+ model.put("pet", pet);
+ return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
+ }
+
+ this.owners.save(owner);
+ return "redirect:/owners/{ownerId}";
+ }
+
+ @GetMapping("/pets/{petId}/edit")
+ public String initUpdateForm(Owner owner, @PathVariable("petId") int petId, ModelMap model) {
+ Pet pet = owner.getPet(petId);
+ model.put("pet", pet);
+ return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
+ }
+
+ @PostMapping("/pets/{petId}/edit")
+ public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owner, ModelMap model) {
+ if (result.hasErrors()) {
+ model.put("pet", pet);
+ return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
+ }
+
+ owner.addPet(pet);
+ this.owners.save(owner);
+ return "redirect:/owners/{ownerId}";
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/PetType.java b/src/main/java/org/springframework/samples/petclinic/owner/PetType.java
similarity index 63%
rename from src/main/java/org/springframework/samples/petclinic/model/PetType.java
rename to src/main/java/org/springframework/samples/petclinic/owner/PetType.java
index f60a5cd27..eeea6a758 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/PetType.java
+++ b/src/main/java/org/springframework/samples/petclinic/owner/PetType.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.samples.petclinic.model;
+package org.springframework.samples.petclinic.owner;
-import javax.persistence.Entity;
-import javax.persistence.Table;
+import org.springframework.samples.petclinic.model.NamedEntity;
+
+import jakarta.persistence.Entity;
+import jakarta.persistence.Table;
/**
- * @author Juergen Hoeller
- * Can be Cat, Dog, Hamster...
+ * @author Juergen Hoeller Can be Cat, Dog, Hamster...
*/
@Entity
@Table(name = "types")
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetTypeFormatter.java b/src/main/java/org/springframework/samples/petclinic/owner/PetTypeFormatter.java
new file mode 100644
index 000000000..4fa18da91
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/owner/PetTypeFormatter.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.petclinic.owner;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.format.Formatter;
+import org.springframework.stereotype.Component;
+
+import java.text.ParseException;
+import java.util.Collection;
+import java.util.Locale;
+
+/**
+ * Instructs Spring MVC on how to parse and print elements of type 'PetType'. Starting
+ * from Spring 3.0, Formatters have come as an improvement in comparison to legacy
+ * PropertyEditors. See the following links for more details: - The Spring ref doc:
+ * https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#format
+ *
+ * @author Mark Fisher
+ * @author Juergen Hoeller
+ * @author Michael Isvy
+ */
+@Component
+public class PetTypeFormatter implements Formatter {
+
+ private final OwnerRepository owners;
+
+ @Autowired
+ public PetTypeFormatter(OwnerRepository owners) {
+ this.owners = owners;
+ }
+
+ @Override
+ public String print(PetType petType, Locale locale) {
+ return petType.getName();
+ }
+
+ @Override
+ public PetType parse(String text, Locale locale) throws ParseException {
+ Collection findPetTypes = this.owners.findPetTypes();
+ for (PetType type : findPetTypes) {
+ if (type.getName().equals(text)) {
+ return type;
+ }
+ }
+ throw new ParseException("type not found: " + text, 0);
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetValidator.java b/src/main/java/org/springframework/samples/petclinic/owner/PetValidator.java
new file mode 100644
index 000000000..e1370b428
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/owner/PetValidator.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.petclinic.owner;
+
+import org.springframework.util.StringUtils;
+import org.springframework.validation.Errors;
+import org.springframework.validation.Validator;
+
+/**
+ * Validator for Pet forms.
+ *
+ * We're not using Bean Validation annotations here because it is easier to define such
+ * validation rule in Java.
+ *
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ */
+public class PetValidator implements Validator {
+
+ private static final String REQUIRED = "required";
+
+ @Override
+ public void validate(Object obj, Errors errors) {
+ Pet pet = (Pet) obj;
+ String name = pet.getName();
+ // name validation
+ if (!StringUtils.hasLength(name)) {
+ errors.rejectValue("name", REQUIRED, REQUIRED);
+ }
+
+ // type validation
+ if (pet.isNew() && pet.getType() == null) {
+ errors.rejectValue("type", REQUIRED, REQUIRED);
+ }
+
+ // birth date validation
+ if (pet.getBirthDate() == null) {
+ errors.rejectValue("birthDate", REQUIRED, REQUIRED);
+ }
+ }
+
+ /**
+ * This Validator validates *just* Pet instances
+ */
+ @Override
+ public boolean supports(Class> clazz) {
+ return Pet.class.isAssignableFrom(clazz);
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Visit.java b/src/main/java/org/springframework/samples/petclinic/owner/Visit.java
new file mode 100755
index 000000000..d052a4e8d
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/owner/Visit.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.petclinic.owner;
+
+import java.time.LocalDate;
+
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.samples.petclinic.model.BaseEntity;
+
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Table;
+import jakarta.validation.constraints.NotEmpty;
+
+/**
+ * Simple JavaBean domain object representing a visit.
+ *
+ * @author Ken Krebs
+ * @author Dave Syer
+ */
+@Entity
+@Table(name = "visits")
+public class Visit extends BaseEntity {
+
+ @Column(name = "visit_date")
+ @DateTimeFormat(pattern = "yyyy-MM-dd")
+ private LocalDate date;
+
+ @NotEmpty
+ private String description;
+
+ /**
+ * Creates a new instance of Visit for the current date
+ */
+ public Visit() {
+ this.date = LocalDate.now();
+ }
+
+ public LocalDate getDate() {
+ return this.date;
+ }
+
+ public void setDate(LocalDate date) {
+ this.date = date;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java b/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java
new file mode 100644
index 000000000..c823d91f2
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.petclinic.owner;
+
+import java.util.Map;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import jakarta.validation.Valid;
+
+/**
+ * @author Juergen Hoeller
+ * @author Ken Krebs
+ * @author Arjen Poutsma
+ * @author Michael Isvy
+ * @author Dave Syer
+ */
+@Controller
+class VisitController {
+
+ private final OwnerRepository owners;
+
+ public VisitController(OwnerRepository owners) {
+ this.owners = owners;
+ }
+
+ @InitBinder
+ public void setAllowedFields(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields("id");
+ }
+
+ /**
+ * Called before each and every @RequestMapping annotated method. 2 goals: - Make sure
+ * we always have fresh data - Since we do not use the session scope, make sure that
+ * Pet object always has an id (Even though id is not part of the form fields)
+ * @param petId
+ * @return Pet
+ */
+ @ModelAttribute("visit")
+ public Visit loadPetWithVisit(@PathVariable("ownerId") int ownerId, @PathVariable("petId") int petId,
+ Map model) {
+ Owner owner = this.owners.findById(ownerId);
+
+ Pet pet = owner.getPet(petId);
+ model.put("pet", pet);
+ model.put("owner", owner);
+
+ Visit visit = new Visit();
+ pet.addVisit(visit);
+ return visit;
+ }
+
+ // Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is
+ // called
+ @GetMapping("/owners/{ownerId}/pets/{petId}/visits/new")
+ public String initNewVisitForm() {
+ return "pets/createOrUpdateVisitForm";
+ }
+
+ // Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is
+ // called
+ @PostMapping("/owners/{ownerId}/pets/{petId}/visits/new")
+ public String processNewVisitForm(@ModelAttribute Owner owner, @PathVariable int petId, @Valid Visit visit,
+ BindingResult result) {
+ if (result.hasErrors()) {
+ return "pets/createOrUpdateVisitForm";
+ }
+
+ owner.addVisit(petId, visit);
+ this.owners.save(owner);
+ return "redirect:/owners/{ownerId}";
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java
deleted file mode 100644
index a0869d1e3..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository;
-
-import java.util.Collection;
-
-import org.springframework.dao.DataAccessException;
-import org.springframework.samples.petclinic.model.BaseEntity;
-import org.springframework.samples.petclinic.model.Owner;
-
-/**
- * Repository class for Owner domain objects All method names are compliant with Spring Data naming
- * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Sam Brannen
- * @author Michael Isvy
- */
-public interface OwnerRepository {
-
- /**
- * 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 findByLastName(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 findById(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 save(Owner owner) throws DataAccessException;
-
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java
deleted file mode 100644
index 1770e8555..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository;
-
-import java.util.List;
-
-import org.springframework.dao.DataAccessException;
-import org.springframework.samples.petclinic.model.BaseEntity;
-import org.springframework.samples.petclinic.model.Pet;
-import org.springframework.samples.petclinic.model.PetType;
-
-/**
- * Repository class for Pet domain objects All method names are compliant with Spring Data naming
- * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Sam Brannen
- * @author Michael Isvy
- */
-public interface PetRepository {
-
- /**
- * Retrieve all PetTypes from the data store.
- *
- * @return a Collection of PetTypes
- */
- List findPetTypes() 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 findById(int id) throws DataAccessException;
-
- /**
- * Save a Pet to the data store, either inserting or updating it.
- *
- * @param pet the Pet to save
- * @see BaseEntity#isNew
- */
- void save(Pet pet) throws DataAccessException;
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/VetRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/VetRepository.java
deleted file mode 100644
index 923c3c23d..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/VetRepository.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository;
-
-import java.util.Collection;
-
-import org.springframework.dao.DataAccessException;
-import org.springframework.samples.petclinic.model.Vet;
-
-/**
- * Repository class for Vet domain objects All method names are compliant with Spring Data naming
- * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Sam Brannen
- * @author Michael Isvy
- */
-public interface VetRepository {
-
- /**
- * Retrieve all Vets from the data store.
- *
- * @return a Collection of Vets
- */
- Collection findAll() throws DataAccessException;
-
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/VisitRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/VisitRepository.java
deleted file mode 100644
index 96b7a208c..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/VisitRepository.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository;
-
-import java.util.List;
-
-import org.springframework.dao.DataAccessException;
-import org.springframework.samples.petclinic.model.BaseEntity;
-import org.springframework.samples.petclinic.model.Visit;
-
-/**
- * Repository class for Visit domain objects All method names are compliant with Spring Data naming
- * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Sam Brannen
- * @author Michael Isvy
- */
-public interface VisitRepository {
-
- /**
- * Save a Visit to the data store, either inserting or updating it.
- *
- * @param visit the Visit to save
- * @see BaseEntity#isNew
- */
- void save(Visit visit) throws DataAccessException;
-
- List findByPetId(Integer petId);
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java
deleted file mode 100644
index 45de1aee0..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository.jdbc;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.sql.DataSource;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.dao.DataAccessException;
-import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.jdbc.core.BeanPropertyRowMapper;
-import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
-import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
-import org.springframework.orm.ObjectRetrievalFailureException;
-import org.springframework.samples.petclinic.model.Owner;
-import org.springframework.samples.petclinic.model.Pet;
-import org.springframework.samples.petclinic.model.PetType;
-import org.springframework.samples.petclinic.model.Visit;
-import org.springframework.samples.petclinic.repository.OwnerRepository;
-import org.springframework.samples.petclinic.util.EntityUtils;
-import org.springframework.stereotype.Repository;
-
-/**
- * A simple JDBC-based implementation of the {@link OwnerRepository} interface.
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Rob Harrop
- * @author Sam Brannen
- * @author Thomas Risberg
- * @author Mark Fisher
- */
-@Repository
-public class JdbcOwnerRepositoryImpl implements OwnerRepository {
-
- private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
-
- private SimpleJdbcInsert insertOwner;
-
- @Autowired
- public JdbcOwnerRepositoryImpl(DataSource dataSource, NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
-
- this.insertOwner = new SimpleJdbcInsert(dataSource)
- .withTableName("owners")
- .usingGeneratedKeyColumns("id");
-
- this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
-
- }
-
-
- /**
- * 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.
- */
- @Override
- public Collection findByLastName(String lastName) throws DataAccessException {
- Map params = new HashMap<>();
- params.put("lastName", lastName + "%");
- List owners = this.namedParameterJdbcTemplate.query(
- "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName",
- params,
- BeanPropertyRowMapper.newInstance(Owner.class)
- );
- 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.
- */
- @Override
- public Owner findById(int id) throws DataAccessException {
- Owner owner;
- try {
- Map params = new HashMap<>();
- params.put("id", id);
- owner = this.namedParameterJdbcTemplate.queryForObject(
- "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
- params,
- BeanPropertyRowMapper.newInstance(Owner.class)
- );
- } catch (EmptyResultDataAccessException ex) {
- throw new ObjectRetrievalFailureException(Owner.class, id);
- }
- loadPetsAndVisits(owner);
- return owner;
- }
-
- public void loadPetsAndVisits(final Owner owner) {
- Map params = new HashMap<>();
- params.put("id", owner.getId());
- final List pets = this.namedParameterJdbcTemplate.query(
- "SELECT pets.id, name, birth_date, type_id, owner_id, visits.id as visit_id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id",
- params,
- new JdbcPetVisitExtractor()
- );
- Collection petTypes = getPetTypes();
- for (JdbcPet pet : pets) {
- pet.setType(EntityUtils.getById(petTypes, PetType.class, pet.getTypeId()));
- owner.addPet(pet);
- }
- }
-
- @Override
- public void save(Owner owner) throws DataAccessException {
- BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(owner);
- if (owner.isNew()) {
- Number newKey = this.insertOwner.executeAndReturnKey(parameterSource);
- owner.setId(newKey.intValue());
- } else {
- this.namedParameterJdbcTemplate.update(
- "UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " +
- "city=:city, telephone=:telephone WHERE id=:id",
- parameterSource);
- }
- }
-
- public Collection getPetTypes() throws DataAccessException {
- return this.namedParameterJdbcTemplate.query(
- "SELECT id, name FROM types ORDER BY name", new HashMap(),
- BeanPropertyRowMapper.newInstance(PetType.class));
- }
-
- /**
- * 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);
- }
- }
-
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPet.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPet.java
deleted file mode 100644
index 4c266b931..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPet.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository.jdbc;
-
-import org.springframework.samples.petclinic.model.Pet;
-
-/**
- * Subclass of Pet that carries temporary id properties which are only relevant for a JDBC implementation of the
- * PetRepository.
- *
- * @author Juergen Hoeller
- */
-class JdbcPet extends Pet {
-
- private int typeId;
-
- private int ownerId;
-
- public int getTypeId() {
- return this.typeId;
- }
-
- public void setTypeId(int typeId) {
- this.typeId = typeId;
- }
-
- public int getOwnerId() {
- return this.ownerId;
- }
-
- public void setOwnerId(int ownerId) {
- this.ownerId = ownerId;
- }
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java
deleted file mode 100644
index 885c2bc2f..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository.jdbc;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.sql.DataSource;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.dao.DataAccessException;
-import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.jdbc.core.BeanPropertyRowMapper;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
-import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
-import org.springframework.orm.ObjectRetrievalFailureException;
-import org.springframework.samples.petclinic.model.Owner;
-import org.springframework.samples.petclinic.model.Pet;
-import org.springframework.samples.petclinic.model.PetType;
-import org.springframework.samples.petclinic.model.Visit;
-import org.springframework.samples.petclinic.repository.OwnerRepository;
-import org.springframework.samples.petclinic.repository.PetRepository;
-import org.springframework.samples.petclinic.repository.VisitRepository;
-import org.springframework.samples.petclinic.util.EntityUtils;
-import org.springframework.stereotype.Repository;
-
-/**
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Rob Harrop
- * @author Sam Brannen
- * @author Thomas Risberg
- * @author Mark Fisher
- */
-@Repository
-public class JdbcPetRepositoryImpl implements PetRepository {
-
- private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
-
- private SimpleJdbcInsert insertPet;
-
- private OwnerRepository ownerRepository;
-
- private VisitRepository visitRepository;
-
-
- @Autowired
- public JdbcPetRepositoryImpl(DataSource dataSource, OwnerRepository ownerRepository, VisitRepository visitRepository) {
- this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
-
- this.insertPet = new SimpleJdbcInsert(dataSource)
- .withTableName("pets")
- .usingGeneratedKeyColumns("id");
-
- this.ownerRepository = ownerRepository;
- this.visitRepository = visitRepository;
- }
-
- @Override
- public List findPetTypes() throws DataAccessException {
- Map params = new HashMap<>();
- return this.namedParameterJdbcTemplate.query(
- "SELECT id, name FROM types ORDER BY name",
- params,
- BeanPropertyRowMapper.newInstance(PetType.class));
- }
-
- @Override
- public Pet findById(int id) throws DataAccessException {
- JdbcPet pet;
- try {
- Map params = new HashMap<>();
- params.put("id", id);
- pet = this.namedParameterJdbcTemplate.queryForObject(
- "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
- params,
- new JdbcPetRowMapper());
- } catch (EmptyResultDataAccessException ex) {
- throw new ObjectRetrievalFailureException(Pet.class, id);
- }
- Owner owner = this.ownerRepository.findById(pet.getOwnerId());
- owner.addPet(pet);
- pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));
-
- List visits = this.visitRepository.findByPetId(pet.getId());
- for (Visit visit : visits) {
- pet.addVisit(visit);
- }
- return pet;
- }
-
- @Override
- public void save(Pet pet) throws DataAccessException {
- if (pet.isNew()) {
- Number newKey = this.insertPet.executeAndReturnKey(
- createPetParameterSource(pet));
- pet.setId(newKey.intValue());
- } else {
- this.namedParameterJdbcTemplate.update(
- "UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " +
- "owner_id=:owner_id WHERE id=:id",
- createPetParameterSource(pet));
- }
- }
-
- /**
- * 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().toDate())
- .addValue("type_id", pet.getType().getId())
- .addValue("owner_id", pet.getOwner().getId());
- }
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java
deleted file mode 100644
index ad00a7163..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository.jdbc;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Date;
-
-import org.joda.time.DateTime;
-import org.springframework.jdbc.core.RowMapper;
-
-/**
- * {@link RowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties
- * of the {@link JdbcPet} class.
- */
-class JdbcPetRowMapper implements RowMapper {
-
- @Override
- public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException {
- JdbcPet pet = new JdbcPet();
- pet.setId(rs.getInt("pets.id"));
- pet.setName(rs.getString("name"));
- Date birthDate = rs.getDate("birth_date");
- pet.setBirthDate(new DateTime(birthDate));
- pet.setTypeId(rs.getInt("type_id"));
- pet.setOwnerId(rs.getInt("owner_id"));
- return pet;
- }
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java
deleted file mode 100644
index 6a4ba62c3..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2002-2015 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository.jdbc;
-
-import org.springframework.data.jdbc.core.OneToManyResultSetExtractor;
-import org.springframework.jdbc.core.ResultSetExtractor;
-import org.springframework.samples.petclinic.model.Visit;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-/**
- * {@link ResultSetExtractor} implementation by using the
- * {@link OneToManyResultSetExtractor} of Spring Data Core JDBC Extensions.
- */
-public class JdbcPetVisitExtractor extends
- OneToManyResultSetExtractor {
-
- public JdbcPetVisitExtractor() {
- super(new JdbcPetRowMapper(), new JdbcVisitRowMapper());
- }
-
- @Override
- protected Integer mapPrimaryKey(ResultSet rs) throws SQLException {
- return rs.getInt("pets.id");
- }
-
- @Override
- protected Integer mapForeignKey(ResultSet rs) throws SQLException {
- if (rs.getObject("visits.pet_id") == null) {
- return null;
- } else {
- return rs.getInt("visits.pet_id");
- }
- }
-
- @Override
- protected void addChild(JdbcPet root, Visit child) {
- root.addVisit(child);
- }
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java
deleted file mode 100644
index 0231275c1..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-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 org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.dao.DataAccessException;
-import org.springframework.jdbc.core.BeanPropertyRowMapper;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.samples.petclinic.model.Specialty;
-import org.springframework.samples.petclinic.model.Vet;
-import org.springframework.samples.petclinic.repository.VetRepository;
-import org.springframework.samples.petclinic.util.EntityUtils;
-import org.springframework.stereotype.Repository;
-
-/**
- * A simple JDBC-based implementation of the {@link VetRepository} interface.
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Rob Harrop
- * @author Sam Brannen
- * @author Thomas Risberg
- * @author Mark Fisher
- * @author Michael Isvy
- */
-@Repository
-public class JdbcVetRepositoryImpl implements VetRepository {
-
- private JdbcTemplate jdbcTemplate;
-
- @Autowired
- public JdbcVetRepositoryImpl(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
-
- /**
- * Refresh the cache of Vets that the ClinicService is holding.
- */
- @Override
- public Collection findAll() throws DataAccessException {
- List vets = new ArrayList<>();
- // Retrieve the list of all vets.
- vets.addAll(this.jdbcTemplate.query(
- "SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
- BeanPropertyRowMapper.newInstance(Vet.class)));
-
- // Retrieve the list of all possible specialties.
- final List specialties = this.jdbcTemplate.query(
- "SELECT id, name FROM specialties",
- BeanPropertyRowMapper.newInstance(Specialty.class));
-
- // Build each vet's list of specialties.
- for (Vet vet : vets) {
- final List vetSpecialtiesIds = this.jdbcTemplate.query(
- "SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
- new BeanPropertyRowMapper() {
- @Override
- public Integer mapRow(ResultSet rs, int row) throws SQLException {
- return rs.getInt(1);
- }
- },
- vet.getId());
- for (int specialtyId : vetSpecialtiesIds) {
- Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
- vet.addSpecialty(specialty);
- }
- }
- return vets;
- }
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java
deleted file mode 100644
index 330ca1a4c..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository.jdbc;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.dao.DataAccessException;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
-import org.springframework.samples.petclinic.model.Visit;
-import org.springframework.samples.petclinic.repository.VisitRepository;
-import org.springframework.stereotype.Repository;
-
-import javax.sql.DataSource;
-import java.util.List;
-
-/**
- * A simple JDBC-based implementation of the {@link VisitRepository} interface.
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Rob Harrop
- * @author Sam Brannen
- * @author Thomas Risberg
- * @author Mark Fisher
- * @author Michael Isvy
- */
-@Repository
-public class JdbcVisitRepositoryImpl implements VisitRepository {
-
- private JdbcTemplate jdbcTemplate;
-
- private SimpleJdbcInsert insertVisit;
-
- @Autowired
- public JdbcVisitRepositoryImpl(DataSource dataSource) {
- this.jdbcTemplate = new JdbcTemplate(dataSource);
-
- this.insertVisit = new SimpleJdbcInsert(dataSource)
- .withTableName("visits")
- .usingGeneratedKeyColumns("id");
- }
-
-
- @Override
- public void save(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");
- }
- }
-
-
- /**
- * 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().toDate())
- .addValue("description", visit.getDescription())
- .addValue("pet_id", visit.getPet().getId());
- }
-
- @Override
- public List findByPetId(Integer petId) {
- return this.jdbcTemplate.query(
- "SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=?",
- new JdbcVisitRowMapper(), petId);
- }
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java
deleted file mode 100644
index 94069042b..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2002-2015 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository.jdbc;
-
-
-import org.joda.time.DateTime;
-import org.springframework.jdbc.core.RowMapper;
-import org.springframework.samples.petclinic.model.Visit;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Date;
-
-/**
- * {@link RowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties
- * of the {@link Visit} class.
- */
-class JdbcVisitRowMapper implements RowMapper {
-
- @Override
- public Visit mapRow(ResultSet rs, int row) throws SQLException {
- Visit visit = new Visit();
- visit.setId(rs.getInt("visit_id"));
- Date visitDate = rs.getDate("visit_date");
- visit.setDate(new DateTime(visitDate));
- visit.setDescription(rs.getString("description"));
- return visit;
- }
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/package-info.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/package-info.java
deleted file mode 100644
index 376da279f..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/package-info.java
+++ /dev/null
@@ -1,6 +0,0 @@
-/**
- * The classes in this package represent the JDBC implementation
- * of PetClinic's persistence layer.
- */
-package org.springframework.samples.petclinic.repository.jdbc;
-
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java
deleted file mode 100644
index 3972dd349..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-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.orm.hibernate3.support.OpenSessionInViewFilter;
-import org.springframework.samples.petclinic.model.Owner;
-import org.springframework.samples.petclinic.repository.OwnerRepository;
-import org.springframework.stereotype.Repository;
-
-/**
- * JPA implementation of the {@link OwnerRepository} interface.
- *
- * @author Mike Keith
- * @author Rod Johnson
- * @author Sam Brannen
- * @author Michael Isvy
- * @since 22.4.2006
- */
-@Repository
-public class JpaOwnerRepositoryImpl implements OwnerRepository {
-
- @PersistenceContext
- private EntityManager em;
-
-
- /**
- * Important: in the current version of this method, we load Owners with all their Pets and Visits while
- * we do not need Visits at all and we only need one property from the Pet objects (the 'name' property).
- * There are some ways to improve it such as:
- * - creating a Ligtweight class (example here: https://community.jboss.org/wiki/LightweightClass)
- * - Turning on lazy-loading and using {@link OpenSessionInViewFilter}
- */
- @SuppressWarnings("unchecked")
- public Collection findByLastName(String lastName) {
- // using 'join fetch' because a single query should load both owners and pets
- // using 'left join fetch' because it might happen that an owner does not have pets yet
- Query query = this.em.createQuery("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName");
- query.setParameter("lastName", lastName + "%");
- return query.getResultList();
- }
-
- @Override
- public Owner findById(int id) {
- // using 'join fetch' because a single query should load both owners and pets
- // using 'left join fetch' because it might happen that an owner does not have pets yet
- Query query = this.em.createQuery("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id");
- query.setParameter("id", id);
- return (Owner) query.getSingleResult();
- }
-
-
- @Override
- public void save(Owner owner) {
- if (owner.getId() == null) {
- this.em.persist(owner);
- } else {
- this.em.merge(owner);
- }
-
- }
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java
deleted file mode 100644
index 227140d96..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository.jpa;
-
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-import org.springframework.samples.petclinic.model.Pet;
-import org.springframework.samples.petclinic.model.PetType;
-import org.springframework.samples.petclinic.repository.PetRepository;
-import org.springframework.stereotype.Repository;
-
-/**
- * JPA implementation of the {@link PetRepository} interface.
- *
- * @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;
-
- @Override
- @SuppressWarnings("unchecked")
- public List findPetTypes() {
- return this.em.createQuery("SELECT ptype FROM PetType ptype ORDER BY ptype.name").getResultList();
- }
-
- @Override
- public Pet findById(int id) {
- return this.em.find(Pet.class, id);
- }
-
- @Override
- public void save(Pet pet) {
- if (pet.getId() == null) {
- this.em.persist(pet);
- } else {
- this.em.merge(pet);
- }
- }
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVetRepositoryImpl.java
deleted file mode 100644
index e4c222b65..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVetRepositoryImpl.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository.jpa;
-
-import java.util.Collection;
-
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.samples.petclinic.model.Vet;
-import org.springframework.samples.petclinic.repository.VetRepository;
-import org.springframework.stereotype.Repository;
-
-/**
- * JPA implementation of the {@link VetRepository} interface.
- *
- * @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;
-
-
- @Override
- @Cacheable(value = "vets")
- @SuppressWarnings("unchecked")
- public Collection findAll() {
- return this.em.createQuery("SELECT distinct vet FROM Vet vet left join fetch vet.specialties ORDER BY vet.lastName, vet.firstName").getResultList();
- }
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java
deleted file mode 100644
index 5d1d42a07..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-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.model.Visit;
-import org.springframework.samples.petclinic.repository.VisitRepository;
-import org.springframework.stereotype.Repository;
-
-/**
- * JPA implementation of the ClinicService 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
- * @author Michael Isvy
- * @since 22.4.2006
- */
-@Repository
-public class JpaVisitRepositoryImpl implements VisitRepository {
-
- @PersistenceContext
- private EntityManager em;
-
-
- @Override
- public void save(Visit visit) {
- if (visit.getId() == null) {
- this.em.persist(visit);
- } else {
- this.em.merge(visit);
- }
- }
-
-
- @Override
- @SuppressWarnings("unchecked")
- public List 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();
- }
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/package-info.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/package-info.java
deleted file mode 100644
index 087dc15b6..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/package-info.java
+++ /dev/null
@@ -1,6 +0,0 @@
-/**
- * The classes in this package represent the JPA implementation
- * of PetClinic's persistence layer.
- */
-package org.springframework.samples.petclinic.repository.jpa;
-
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java
deleted file mode 100644
index 24c573eb7..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository.springdatajpa;
-
-import java.util.Collection;
-
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.Repository;
-import org.springframework.data.repository.query.Param;
-import org.springframework.samples.petclinic.model.Owner;
-import org.springframework.samples.petclinic.repository.OwnerRepository;
-
-/**
- * Spring Data JPA specialization of the {@link OwnerRepository} interface
- *
- * @author Michael Isvy
- * @since 15.1.2013
- */
-public interface SpringDataOwnerRepository extends OwnerRepository, Repository {
-
- @Override
- @Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%")
- public Collection findByLastName(@Param("lastName") String lastName);
-
- @Override
- @Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
- public Owner findById(@Param("id") int id);
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataPetRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataPetRepository.java
deleted file mode 100644
index 56a413147..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataPetRepository.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-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.model.Pet;
-import org.springframework.samples.petclinic.model.PetType;
-import org.springframework.samples.petclinic.repository.PetRepository;
-
-/**
- * Spring Data JPA specialization of the {@link PetRepository} interface
- *
- * @author Michael Isvy
- * @since 15.1.2013
- */
-public interface SpringDataPetRepository extends PetRepository, Repository {
-
- @Override
- @Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
- List findPetTypes() throws DataAccessException;
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVetRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVetRepository.java
deleted file mode 100644
index b8211b707..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVetRepository.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository.springdatajpa;
-
-import org.springframework.data.repository.Repository;
-import org.springframework.samples.petclinic.model.Vet;
-import org.springframework.samples.petclinic.repository.VetRepository;
-
-/**
- * Spring Data JPA specialization of the {@link VetRepository} interface
- *
- * @author Michael Isvy
- * @since 15.1.2013
- */
-public interface SpringDataVetRepository extends VetRepository, Repository {
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVisitRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVisitRepository.java
deleted file mode 100644
index 84740224b..000000000
--- a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataVisitRepository.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.repository.springdatajpa;
-
-import org.springframework.data.repository.Repository;
-import org.springframework.samples.petclinic.model.Visit;
-import org.springframework.samples.petclinic.repository.VisitRepository;
-
-/**
- * Spring Data JPA specialization of the {@link VisitRepository} interface
- *
- * @author Michael Isvy
- * @since 15.1.2013
- */
-public interface SpringDataVisitRepository extends VisitRepository, Repository {
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/service/ClinicService.java b/src/main/java/org/springframework/samples/petclinic/service/ClinicService.java
deleted file mode 100644
index 936582129..000000000
--- a/src/main/java/org/springframework/samples/petclinic/service/ClinicService.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.service;
-
-import java.util.Collection;
-
-import org.springframework.dao.DataAccessException;
-import org.springframework.samples.petclinic.model.Owner;
-import org.springframework.samples.petclinic.model.Pet;
-import org.springframework.samples.petclinic.model.PetType;
-import org.springframework.samples.petclinic.model.Vet;
-import org.springframework.samples.petclinic.model.Visit;
-
-
-/**
- * Mostly used as a facade so all controllers have a single point of entry
- *
- * @author Michael Isvy
- */
-public interface ClinicService {
-
- Collection findPetTypes() throws DataAccessException;
-
- Owner findOwnerById(int id) throws DataAccessException;
-
- Pet findPetById(int id) throws DataAccessException;
-
- void savePet(Pet pet) throws DataAccessException;
-
- void saveVisit(Visit visit) throws DataAccessException;
-
- Collection findVets() throws DataAccessException;
-
- void saveOwner(Owner owner) throws DataAccessException;
-
- Collection findOwnerByLastName(String lastName) throws DataAccessException;
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java b/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java
deleted file mode 100644
index 0d7ff4d0c..000000000
--- a/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.service;
-
-import java.util.Collection;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.dao.DataAccessException;
-import org.springframework.samples.petclinic.model.Owner;
-import org.springframework.samples.petclinic.model.Pet;
-import org.springframework.samples.petclinic.model.PetType;
-import org.springframework.samples.petclinic.model.Vet;
-import org.springframework.samples.petclinic.model.Visit;
-import org.springframework.samples.petclinic.repository.OwnerRepository;
-import org.springframework.samples.petclinic.repository.PetRepository;
-import org.springframework.samples.petclinic.repository.VetRepository;
-import org.springframework.samples.petclinic.repository.VisitRepository;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-/**
- * Mostly used as a facade for all Petclinic controllers
- * Also a placeholder for @Transactional and @Cacheable annotations
- *
- * @author Michael Isvy
- */
-@Service
-public class ClinicServiceImpl implements ClinicService {
-
- private PetRepository petRepository;
- private VetRepository vetRepository;
- private OwnerRepository ownerRepository;
- private VisitRepository visitRepository;
-
- @Autowired
- public ClinicServiceImpl(PetRepository petRepository, VetRepository vetRepository, OwnerRepository ownerRepository, VisitRepository visitRepository) {
- this.petRepository = petRepository;
- this.vetRepository = vetRepository;
- this.ownerRepository = ownerRepository;
- this.visitRepository = visitRepository;
- }
-
- @Override
- @Transactional(readOnly = true)
- public Collection findPetTypes() throws DataAccessException {
- return petRepository.findPetTypes();
- }
-
- @Override
- @Transactional(readOnly = true)
- public Owner findOwnerById(int id) throws DataAccessException {
- return ownerRepository.findById(id);
- }
-
- @Override
- @Transactional(readOnly = true)
- public Collection findOwnerByLastName(String lastName) throws DataAccessException {
- return ownerRepository.findByLastName(lastName);
- }
-
- @Override
- @Transactional
- public void saveOwner(Owner owner) throws DataAccessException {
- ownerRepository.save(owner);
- }
-
-
- @Override
- @Transactional
- public void saveVisit(Visit visit) throws DataAccessException {
- visitRepository.save(visit);
- }
-
-
- @Override
- @Transactional(readOnly = true)
- public Pet findPetById(int id) throws DataAccessException {
- return petRepository.findById(id);
- }
-
- @Override
- @Transactional
- public void savePet(Pet pet) throws DataAccessException {
- petRepository.save(pet);
- }
-
- @Override
- @Transactional(readOnly = true)
- @Cacheable(value = "vets")
- public Collection findVets() throws DataAccessException {
- return vetRepository.findAll();
- }
-
-
-}
diff --git a/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java b/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java
new file mode 100755
index 000000000..f90679094
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.samples.petclinic.system;
+
+import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.cache.configuration.MutableConfiguration;
+
+/**
+ * Cache configuration intended for caches providing the JCache API. This configuration
+ * creates the used cache for the application and enables statistics that become
+ * accessible via JMX.
+ */
+@Configuration(proxyBeanMethods = false)
+@EnableCaching
+class CacheConfiguration {
+
+ @Bean
+ public JCacheManagerCustomizer petclinicCacheConfigurationCustomizer() {
+ return cm -> cm.createCache("vets", cacheConfiguration());
+ }
+
+ /**
+ * Create a simple configuration that enable statistics via the JCache programmatic
+ * configuration API.
+ *
+ * Within the configuration object that is provided by the JCache API standard, there
+ * is only a very limited set of configuration options. The really relevant
+ * configuration options (like the size limit) must be set via a configuration
+ * mechanism that is provided by the selected JCache implementation.
+ */
+ private javax.cache.configuration.Configuration