petclinic-aplcache

Details

pom.xml 9(+9 -0)

diff --git a/pom.xml b/pom.xml
index 8530395..874af64 100644
--- a/pom.xml
+++ b/pom.xml
@@ -118,6 +118,15 @@
 			<version>${hibernate.version}</version>
 		</dependency>
 		
+		<!-- ********************************************************************** 
+			 ** 				SPRING DATA			 							 ** 
+			 ********************************************************************** -->
+		
+		<dependency>
+ 			<groupId>org.springframework.data</groupId>
+ 			<artifactId>spring-data-jpa</artifactId>
+ 			<version>1.1.0.RELEASE</version>
+		</dependency> 
 
 		<!-- Servlet -->
 		<dependency>
diff --git a/src/main/java/org/springframework/samples/petclinic/jdbc/JdbcPet.java b/src/main/java/org/springframework/samples/petclinic/jdbc/JdbcPet.java
index b2d2530..aa0bf18 100644
--- a/src/main/java/org/springframework/samples/petclinic/jdbc/JdbcPet.java
+++ b/src/main/java/org/springframework/samples/petclinic/jdbc/JdbcPet.java
@@ -7,7 +7,7 @@ import org.springframework.samples.petclinic.Pet;
  * are only relevant for a JDBC implmentation of the Clinic.
  *
  * @author Juergen Hoeller
- * @see JdbcClinic
+ * @see JdbcClinicImpl
  */
 class JdbcPet extends Pet {
 
diff --git a/src/main/java/org/springframework/samples/petclinic/jpa/SpringDataClinic.java b/src/main/java/org/springframework/samples/petclinic/jpa/SpringDataClinic.java
new file mode 100644
index 0000000..f21a576
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/jpa/SpringDataClinic.java
@@ -0,0 +1,45 @@
+package org.springframework.samples.petclinic.jpa;
+
+import java.util.Collection;
+
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.Repository;
+import org.springframework.samples.petclinic.Clinic;
+import org.springframework.samples.petclinic.Owner;
+import org.springframework.samples.petclinic.Pet;
+import org.springframework.samples.petclinic.PetType;
+import org.springframework.samples.petclinic.Vet;
+import org.springframework.samples.petclinic.Visit;
+
+/**
+ *
+ * @author Michael Isvy
+ * @since 15.1.2013
+ */
+public interface SpringDataClinic extends Clinic, Repository {
+
+
+
+	@Query("SELECT vet FROM Vet vet ORDER BY vet.lastName, vet.firstName")
+	public Collection<Vet> getVets();
+
+	@Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
+	public Collection<PetType> getPetTypes();
+
+	@Query("SELECT owner FROM Owner owner WHERE owner.lastName LIKE :lastName")
+	public Collection<Owner> findOwners(String lastName);
+	
+
+	public Owner findOwner(int id);
+
+	public Pet findPet(int id);
+
+	public void storeOwner(Owner owner);
+
+	public void storePet(Pet pet);
+
+	public void storeVisit(Visit visit);
+
+	public void deletePet(int id);
+
+}
diff --git a/src/main/resources/spring/applicationContext-dao.xml b/src/main/resources/spring/applicationContext-dao.xml
index f3316a9..9cd0805 100644
--- a/src/main/resources/spring/applicationContext-dao.xml
+++ b/src/main/resources/spring/applicationContext-dao.xml
@@ -3,13 +3,14 @@
 	Application context definition for PetClinic on JPA.
 -->
 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-		xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
-		xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
-		xsi:schemaLocation="
-			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
-			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-			http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
-			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
+	xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
+	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
+	xmlns:jpa="http://www.springframework.org/schema/data/jpa"
+	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
+		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+		http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd
+		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
+		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
 
 	<!-- ========================= RESOURCE DEFINITIONS ========================= -->
 
@@ -88,12 +89,6 @@
 		-->
 		<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
 	
-		<!--
-			Will automatically be transactional due to @Transactional.
-			EntityManager will be auto-injected due to @PersistenceContext.
-			PersistenceExceptions will be auto-translated due to @Repository.
-		-->
-		<bean id="clinic" class="org.springframework.samples.petclinic.jpa.JpaClinic"/>
 	</beans>
 	
 	<beans profile="jdbc">
@@ -103,7 +98,22 @@
 		
 	
 		<!-- PetClinic's central data access object using Spring's SimpleJdbcTemplate -->
-		<bean id="clinic" class="org.springframework.samples.petclinic.jdbc.JdbcClinic"/>
+		<bean id="clinic" class="org.springframework.samples.petclinic.jdbc.JdbcClinicImpl"/>
+	
+	</beans>
+	
+	<beans profile="plain-jpa">
+		<!--
+			Will automatically be transactional due to @Transactional.
+			EntityManager will be auto-injected due to @PersistenceContext.
+			PersistenceExceptions will be auto-translated due to @Repository.
+		-->
+		<bean id="clinic" class="org.springframework.samples.petclinic.jpa.JpaClinicImpl"/>
+	
+	</beans>
+	
+	<beans profile="spring-data-jpa">
+		<jpa:repositories base-package="org.springframework.samples.petclinic.jpa"/>
 	
 	</beans>
 </beans>
\ No newline at end of file
diff --git a/src/main/webapp/resources/html/tutorial.html b/src/main/webapp/resources/html/tutorial.html
index f5c7534..f053269 100644
--- a/src/main/webapp/resources/html/tutorial.html
+++ b/src/main/webapp/resources/html/tutorial.html
@@ -480,7 +480,7 @@
 
 	<p>
 		The JDBC implementation of the Clinic interface is
-		<span style="font-weight: bold; font-style: italic;">org.springframework.samples.petclinic.jdbc.JdbcClinic</span>,
+		<span style="font-weight: bold; font-style: italic;">org.springframework.samples.petclinic.jdbc.JdbcClinicImpl</span>,
 		which uses Java 5 language features,
 		<strong>org.springframework.jdbc.core.simple.SimpleJdbcTemplate</strong>, and
 		<strong>org.springframework.jdbc.core.simple.SimpleJdbcInsert</strong>.
@@ -513,7 +513,7 @@
 	<p>
 		The JPA implementation of the <span style="font-weight: bold;">Clinic</span>
 		interface is
-		<span style="font-weight: bold; font-style: italic;">org.springframework.samples.petclinic.jpa.JpaClinic</span>,
+		<span style="font-weight: bold; font-style: italic;">org.springframework.samples.petclinic.jpa.JpaClinicImpl</span>,
 		which is based on native JPA usage combined with Spring's
 		<span style="font-weight: bold;">@Repository</span> and
 		<span style="font-weight: bold;">@Transactional</span> annotations but
diff --git a/src/test/java/org/springframework/samples/petclinic/aspects/UsageLogAspectTests.java b/src/test/java/org/springframework/samples/petclinic/aspects/UsageLogAspectTests.java
index 901e766..2768909 100644
--- a/src/test/java/org/springframework/samples/petclinic/aspects/UsageLogAspectTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/aspects/UsageLogAspectTests.java
@@ -7,7 +7,7 @@ import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.samples.petclinic.Clinic;
 import org.springframework.samples.petclinic.aspects.UsageLogAspect;
-import org.springframework.samples.petclinic.jpa.JpaClinicTests;
+import org.springframework.samples.petclinic.jpa.JpaClinicImplTests;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -29,7 +29,7 @@ import static junit.framework.Assert.assertFalse;
  */
 @ContextConfiguration(locations={"classpath:spring/applicationContext-dao.xml"})
 @RunWith(SpringJUnit4ClassRunner.class)
-@ActiveProfiles("jpa")
+@ActiveProfiles({"jpa","plain-jpa"})
 public class UsageLogAspectTests {
 
 	@Autowired