From 7cbfaf1726cd9d7e1620538d4bfbd005e3a2f20e Mon Sep 17 00:00:00 2001
From: Chris Beams <cbeams@vmware.com>
Date: Thu, 2 Sep 2010 07:51:24 +0000
Subject: [PATCH] Fix Petclinic case-sensitivity problems against MySQL
 (SPR-7512)

With thanks to Rob Winch for patch submission.
---
 src/main/resources/META-INF/orm.xml                | 14 +++++++-------
 .../samples/petclinic/AbstractClinicTests.java     |  4 ++--
 .../petclinic/jpa/AbstractJpaClinicTests.java      |  4 ++--
 .../petclinic/AbstractClinicTests-context.xml      |  9 ++++++---
 .../petclinic/jpa/applicationContext-jpaCommon.xml | 12 ++++++++----
 5 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/src/main/resources/META-INF/orm.xml b/src/main/resources/META-INF/orm.xml
index d7c8f704..7ea243ec 100644
--- a/src/main/resources/META-INF/orm.xml
+++ b/src/main/resources/META-INF/orm.xml
@@ -42,10 +42,10 @@
 	</mapped-superclass>
 
 	<entity class="Vet">
-		<table name="VETS"/>
+		<table name="vets"/>
 		<attributes>
 			<many-to-many name="specialtiesInternal" target-entity="Specialty" fetch="EAGER">
-				<join-table name="VET_SPECIALTIES">
+				<join-table name="vet_specialties">
 					<join-column name="VET_ID"/>
 					<inverse-join-column name="SPECIALTY_ID"/>
 				</join-table>
@@ -56,11 +56,11 @@
 	</entity>
 
 	<entity class="Specialty">
-		<table name="SPECIALTIES"/>
+		<table name="specialties"/>
 	</entity>
 
 	<entity class="Owner">
-		<table name="OWNERS"/>
+		<table name="owners"/>
 		<attributes>
 			<basic name="address"/>
 			<basic name="city"/>
@@ -75,7 +75,7 @@
 	</entity>
 
 	<entity class="Pet">
-		<table name="PETS"/>
+		<table name="pets"/>
 		<attributes>
 			<basic name="birthDate">
 				<column name="BIRTH_DATE"/>
@@ -101,11 +101,11 @@
 	</entity>
 
 	<entity class="PetType">
-		<table name="TYPES"/>
+		<table name="types"/>
 	</entity>
 
 	<entity class="Visit">
-		<table name="VISITS"/>
+		<table name="visits"/>
 		<attributes>
 			<basic name="date">
 				<column name="VISIT_DATE"/>
diff --git a/src/test/java/org/springframework/samples/petclinic/AbstractClinicTests.java b/src/test/java/org/springframework/samples/petclinic/AbstractClinicTests.java
index a6986918..63010dc3 100644
--- a/src/test/java/org/springframework/samples/petclinic/AbstractClinicTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/AbstractClinicTests.java
@@ -92,7 +92,7 @@ public abstract class AbstractClinicTests extends AbstractTransactionalJUnit4Spr
 		Collection<Vet> vets = this.clinic.getVets();
 		// Use the inherited countRowsInTable() convenience method (from
 		// AbstractTransactionalJUnit4SpringContextTests) to verify the results.
-		assertEquals("JDBC query must show the same number of vets", super.countRowsInTable("VETS"), vets.size());
+		assertEquals("JDBC query must show the same number of vets", super.countRowsInTable("vets"), vets.size());
 		Vet v1 = EntityUtils.getById(vets, Vet.class, 2);
 		assertEquals("Leary", v1.getLastName());
 		assertEquals(1, v1.getNrOfSpecialties());
@@ -107,7 +107,7 @@ public abstract class AbstractClinicTests extends AbstractTransactionalJUnit4Spr
 	@Test
 	public void getPetTypes() {
 		Collection<PetType> petTypes = this.clinic.getPetTypes();
-		assertEquals("JDBC query must show the same number of pet types", super.countRowsInTable("TYPES"),
+		assertEquals("JDBC query must show the same number of pet types", super.countRowsInTable("types"),
 				petTypes.size());
 		PetType t1 = EntityUtils.getById(petTypes, PetType.class, 1);
 		assertEquals("cat", t1.getName());
diff --git a/src/test/java/org/springframework/samples/petclinic/jpa/AbstractJpaClinicTests.java b/src/test/java/org/springframework/samples/petclinic/jpa/AbstractJpaClinicTests.java
index d8adc918..335297d9 100644
--- a/src/test/java/org/springframework/samples/petclinic/jpa/AbstractJpaClinicTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/jpa/AbstractJpaClinicTests.java
@@ -83,7 +83,7 @@ public abstract class AbstractJpaClinicTests extends AbstractJpaTests {
 		// Use the inherited countRowsInTable() convenience method (from
 		// AbstractTransactionalDataSourceSpringContextTests) to verify the
 		// results.
-		assertEquals("JDBC query must show the same number of vets", super.countRowsInTable("VETS"), vets.size());
+		assertEquals("JDBC query must show the same number of vets", super.countRowsInTable("vets"), vets.size());
 		Vet v1 = EntityUtils.getById(vets, Vet.class, 2);
 		assertEquals("Leary", v1.getLastName());
 		assertEquals(1, v1.getNrOfSpecialties());
@@ -97,7 +97,7 @@ public abstract class AbstractJpaClinicTests extends AbstractJpaTests {
 
 	public void testGetPetTypes() {
 		Collection<PetType> petTypes = this.clinic.getPetTypes();
-		assertEquals("JDBC query must show the same number of pet types", super.countRowsInTable("TYPES"),
+		assertEquals("JDBC query must show the same number of pet types", super.countRowsInTable("types"),
 				petTypes.size());
 		PetType t1 = EntityUtils.getById(petTypes, PetType.class, 1);
 		assertEquals("cat", t1.getName());
diff --git a/src/test/resources/org/springframework/samples/petclinic/AbstractClinicTests-context.xml b/src/test/resources/org/springframework/samples/petclinic/AbstractClinicTests-context.xml
index a0bc4bd0..d048d8ae 100644
--- a/src/test/resources/org/springframework/samples/petclinic/AbstractClinicTests-context.xml
+++ b/src/test/resources/org/springframework/samples/petclinic/AbstractClinicTests-context.xml
@@ -16,9 +16,12 @@
 
 	<tx:annotation-driven/>
 
-	<jdbc:embedded-database id="dataSource">
+	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
+			p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
+			p:username="${jdbc.username}" p:password="${jdbc.password}"/>
+
+	<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
 		<jdbc:script location="${jdbc.initLocation}"/>
 		<jdbc:script location="${jdbc.dataLocation}"/>
-	</jdbc:embedded-database>
-		
+	</jdbc:initialize-database>
 </beans>
diff --git a/src/test/resources/org/springframework/samples/petclinic/jpa/applicationContext-jpaCommon.xml b/src/test/resources/org/springframework/samples/petclinic/jpa/applicationContext-jpaCommon.xml
index f5fbe563..3202f94c 100644
--- a/src/test/resources/org/springframework/samples/petclinic/jpa/applicationContext-jpaCommon.xml
+++ b/src/test/resources/org/springframework/samples/petclinic/jpa/applicationContext-jpaCommon.xml
@@ -14,11 +14,16 @@
 
 	<tx:annotation-driven />
 
-	<jdbc:embedded-database id="dataSource">
+	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
+			p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
+			p:username="${jdbc.username}" p:password="${jdbc.password}"/>
+
+	<jdbc:initialize-database data-source="dataSource">
 		<jdbc:script location="${jdbc.initLocation}"/>
 		<jdbc:script location="${jdbc.dataLocation}"/>
-	</jdbc:embedded-database>
-	
+	</jdbc:initialize-database>
+
+
 	<!-- Note: the specific "jpaAdapter" bean sits in adapter context file -->
 	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
 		p:dataSource-ref="dataSource" p:jpaVendorAdapter-ref="jpaAdapter">
@@ -30,5 +35,4 @@
 
 	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
 		p:entityManagerFactory-ref="entityManagerFactory" />
-
 </beans>
-- 
GitLab