From 9617efef3225b818b96cfb1d1d63ae2f69f9df4a Mon Sep 17 00:00:00 2001 From: Costin Leau <cleau@vmware.com> Date: Thu, 26 Nov 2009 18:30:49 +0000 Subject: [PATCH] SPR-6447 + improve DataSource setup --- db/build.xml | 85 ------------------- db/dropTables.txt | 7 -- db/emptyDB.txt | 7 -- db/mysql/createDB.txt | 3 - db/mysql/dropDB.txt | 1 - db/mysql/initDB.txt | 58 ------------- db/mysql/petclinic_db_setup_mysql.txt | 22 ----- db/mysql/petclinic_tomcat_mysql.xml | 64 --------------- db/petclinic_tomcat_all.xml | 112 -------------------------- db/populateDB.txt | 53 ------------ pom.xml | 20 +++-- src/main/resources/db/db_readme.txt | 15 ++++ 12 files changed, 30 insertions(+), 417 deletions(-) delete mode 100644 db/build.xml delete mode 100644 db/dropTables.txt delete mode 100644 db/emptyDB.txt delete mode 100644 db/mysql/createDB.txt delete mode 100644 db/mysql/dropDB.txt delete mode 100644 db/mysql/initDB.txt delete mode 100644 db/mysql/petclinic_db_setup_mysql.txt delete mode 100644 db/mysql/petclinic_tomcat_mysql.xml delete mode 100644 db/petclinic_tomcat_all.xml delete mode 100644 db/populateDB.txt create mode 100644 src/main/resources/db/db_readme.txt diff --git a/db/build.xml b/db/build.xml deleted file mode 100644 index b6d0993..0000000 --- a/db/build.xml +++ /dev/null @@ -1,85 +0,0 @@ -<?xml version="1.0"?> - -<project name="setupDB" basedir="." default="all"> - - <target name="dropHSQLTables" if="useHSQL"> - <echo message="Drop tables using: ${db.driver} ${db.url}" /> - <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}" onerror="continue"> - <classpath> - <fileset dir="${spring.root}/lib"> - <include name="hsqldb/hsqldb.jar" /> - </fileset> - </classpath> - <transaction src="${db.dir}/dropTables.txt" /> - </sql> - </target> - - <target name="createHSQLTables" if="useHSQL"> - <echo message="Create tables using: ${db.driver} ${db.url}" /> - <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}" onerror="continue"> - <classpath> - <fileset dir="${spring.root}/lib"> - <include name="hsqldb/hsqldb.jar" /> - </fileset> - </classpath> - <transaction src="${db.dir}/hsqldb/initDB.txt" /> - </sql> - </target> - - <target name="dropMYSQLTables" if="useMYSQL"> - <echo message="Dropping tables using: ${db.driver} ${db.url}" /> - <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}" onerror="continue"> - <classpath> - <fileset dir="${db.dir}/mysql"> - <include name="mysql*.jar" /> - </fileset> - </classpath> - <transaction src="${db.dir}/dropTables.txt" /> - </sql> - </target> - - <target name="createMYSQLTables" if="useMYSQL"> - <echo message="Creating tables using: ${db.driver} ${db.url}" /> - <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}" onerror="continue"> - <classpath> - <fileset dir="${db.dir}/mysql"> - <include name="mysql*.jar" /> - </fileset> - </classpath> - <transaction src="${db.dir}/mysql/initDB.txt" /> - </sql> - </target> - - <target name="emptyTables"> - <echo message="Emptying tables using: ${db.driver} ${db.url}" /> - <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}"> - <classpath> - <fileset dir="${spring.root}/lib"> - <include name="hsqldb/hsqldb.jar" /> - </fileset> - <fileset dir="${db.dir}/mysql"> - <include name="mysql*.jar" /> - </fileset> - </classpath> - <transaction src="${db.dir}/emptyDB.txt" /> - </sql> - </target> - - <target name="populateTables"> - <echo message="Populating tables using: ${db.driver} ${db.url}" /> - <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}"> - <classpath> - <fileset dir="${spring.root}/lib"> - <include name="hsqldb/hsqldb.jar" /> - </fileset> - <fileset dir="${db.dir}/mysql"> - <include name="mysql*.jar" /> - </fileset> - </classpath> - <transaction src="${db.dir}/populateDB.txt" /> - </sql> - </target> - - <target name="all" depends="dropHSQLTables,createHSQLTables,dropMYSQLTables,createMYSQLTables,emptyTables,populateTables" /> - -</project> \ No newline at end of file diff --git a/db/dropTables.txt b/db/dropTables.txt deleted file mode 100644 index 90ae632..0000000 --- a/db/dropTables.txt +++ /dev/null @@ -1,7 +0,0 @@ -DROP TABLE visits; -DROP TABLE pets; -DROP TABLE owners; -DROP TABLE types; -DROP TABLE vet_specialties; -DROP TABLE specialties; -DROP TABLE vets; diff --git a/db/emptyDB.txt b/db/emptyDB.txt deleted file mode 100644 index d5dd872..0000000 --- a/db/emptyDB.txt +++ /dev/null @@ -1,7 +0,0 @@ -DELETE FROM vets; -DELETE FROM specialties; -DELETE FROM vet_specialties; -DELETE FROM types; -DELETE FROM owners; -DELETE FROM pets; -DELETE FROM visits; diff --git a/db/mysql/createDB.txt b/db/mysql/createDB.txt deleted file mode 100644 index 5b4b385..0000000 --- a/db/mysql/createDB.txt +++ /dev/null @@ -1,3 +0,0 @@ -CREATE DATABASE petclinic; - -GRANT ALL PRIVILEGES ON petclinic.* TO pc@localhost IDENTIFIED BY 'pc'; \ No newline at end of file diff --git a/db/mysql/dropDB.txt b/db/mysql/dropDB.txt deleted file mode 100644 index e1209da..0000000 --- a/db/mysql/dropDB.txt +++ /dev/null @@ -1 +0,0 @@ -DROP DATABASE petclinic; diff --git a/db/mysql/initDB.txt b/db/mysql/initDB.txt deleted file mode 100644 index 0007ee3..0000000 --- a/db/mysql/initDB.txt +++ /dev/null @@ -1,58 +0,0 @@ -USE petclinic; - -CREATE TABLE vets ( - id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - first_name VARCHAR(30), - last_name VARCHAR(30), - INDEX(last_name) -) engine=InnoDB; - -CREATE TABLE specialties ( - id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(80), - INDEX(name) -) engine=InnoDB; - -CREATE TABLE vet_specialties ( - vet_id INT(4) UNSIGNED NOT NULL, - specialty_id INT(4) UNSIGNED NOT NULL -) engine=InnoDB; -ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_vets FOREIGN KEY (vet_id) REFERENCES vets(id); -ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_specialties FOREIGN KEY (specialty_id) REFERENCES specialties(id); - -CREATE TABLE types ( - id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(80), - INDEX(name) -) engine=InnoDB; - -CREATE TABLE owners ( - id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - first_name VARCHAR(30), - last_name VARCHAR(30), - address VARCHAR(255), - city VARCHAR(80), - telephone VARCHAR(20), - INDEX(last_name) -) engine=InnoDB; - -CREATE TABLE pets ( - id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(30), - birth_date DATE, - type_id INT(4) UNSIGNED NOT NULL, - owner_id INT(4) UNSIGNED NOT NULL, - INDEX(name) -) engine=InnoDB; -ALTER TABLE pets ADD CONSTRAINT fk_pets_owners FOREIGN KEY (owner_id) REFERENCES owners(id); -ALTER TABLE pets ADD CONSTRAINT fk_pets_types FOREIGN KEY (type_id) REFERENCES types(id); -CREATE INDEX pets_name ON pets(name); - -CREATE TABLE visits ( - id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - pet_id INT(4) UNSIGNED NOT NULL, - visit_date DATE, - description VARCHAR(255), - INDEX(pet_id) -) engine=InnoDB; -ALTER TABLE visits ADD CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets(id); diff --git a/db/mysql/petclinic_db_setup_mysql.txt b/db/mysql/petclinic_db_setup_mysql.txt deleted file mode 100644 index 66727e1..0000000 --- a/db/mysql/petclinic_db_setup_mysql.txt +++ /dev/null @@ -1,22 +0,0 @@ -================================================================================ -=== Spring PetClinic sample application - MySQL Configuration === -================================================================================ - -@author Sam Brannen - --------------------------------------------------------------------------------- - -1) Download and install the MySQL database (e.g., MySQL Community Server 5.1.x), - which can be found here: http://dev.mysql.com/downloads/ - -2) Download Connector/J, the MySQL JDBC driver (e.g., Connector/J 5.1.x), which - can be found here: http://dev.mysql.com/downloads/connector/j/ - Copy the Connector/J JAR file (e.g., mysql-connector-java-5.1.5-bin.jar) into - the db/mysql directory. - -3) Create the PetClinic database and user by executing the "db/mysql/createDB.txt" - script. - -4) Open "src/main/resources/jdbc.properties"; comment out all properties in the - "HSQL Settings" section; uncomment all properties in the "MySQL Settings" - section. \ No newline at end of file diff --git a/db/mysql/petclinic_tomcat_mysql.xml b/db/mysql/petclinic_tomcat_mysql.xml deleted file mode 100644 index d1c5a3b..0000000 --- a/db/mysql/petclinic_tomcat_mysql.xml +++ /dev/null @@ -1,64 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> - -<Context path="/petclinic" docBase="petclinic" debug="4" reloadable="true"> - <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_petclinic_log." suffix=".txt" timestamp="true"/> - - <!-- Define a database connection pool for MYSQL --> - <Resource name="jdbc/petclinicMYSQL" auth="Container" type="javax.sql.DataSource"/> - <ResourceParams name="jdbc/petclinicMYSQL"> - <parameter> - <name>factory</name> - <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> - </parameter> - - <parameter> - <name>driverClassName</name> - <value>org.gjt.mm.mysql.Driver</value> - </parameter> - <!-- - The JDBC connection url for connecting to your MySQL dB. - The autoReconnect=true argument to the url makes sure that the - mm.mysql JDBC Driver will automatically reconnect if mysqld closed the - connection. mysqld by default closes idle connections after 8 hours. - --> - <parameter> - <name>url</name> - <value>jdbc:mysql://localhost:3306/petclinic?autoReconnect=true</value> - </parameter> - <parameter> - <name>username</name> - <value>pc</value> - </parameter> - <parameter> - <name>password</name> - <value>pc</value> - </parameter> - - <parameter> - <name>maxActive</name> - <value>50</value> - </parameter> - <parameter> - <name>maxIdle</name> - <value>10</value> - </parameter> - <parameter> - <name>maxWait</name> - <value>10000</value> - </parameter> - <parameter> - <name>removeAbandoned</name> - <value>true</value> - </parameter> - <parameter> - <name>removeAbandonedTimeout</name> - <value>60</value> - </parameter> - <parameter> - <name>logAbandoned</name> - <value>true</value> - </parameter> - </ResourceParams> - - -</Context> diff --git a/db/petclinic_tomcat_all.xml b/db/petclinic_tomcat_all.xml deleted file mode 100644 index ed45c5c..0000000 --- a/db/petclinic_tomcat_all.xml +++ /dev/null @@ -1,112 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> - -<Context path="/petclinic" docBase="petclinic" debug="4" reloadable="true"> - <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_petclinic_log." suffix=".txt" timestamp="true"/> - - <!-- Define a database connection pool for HSQL --> - <!-- NOTE: make sure that a copy of hsqldb.jar is in the TOMCAT common/lib directory --> - <Resource name="jdbc/petclinicHSQL" auth="Container" type="javax.sql.DataSource"/> - <ResourceParams name="jdbc/petclinicHSQL"> - <parameter> - <name>factory</name> - <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> - </parameter> - - <parameter> - <name>driverClassName</name> - <value>org.hsqldb.jdbcDriver</value> - </parameter> - <parameter> - <name>url</name> - <value>jdbc:hsqldb:hsql://localhost:9001</value> - </parameter> - <parameter> - <name>username</name> - <value>sa</value> - </parameter> - - <parameter> - <name>maxActive</name> - <value>50</value> - </parameter> - <parameter> - <name>maxIdle</name> - <value>10</value> - </parameter> - <parameter> - <name>maxWait</name> - <value>10000</value> - </parameter> - <parameter> - <name>removeAbandoned</name> - <value>true</value> - </parameter> - <parameter> - <name>removeAbandonedTimeout</name> - <value>60</value> - </parameter> - <parameter> - <name>logAbandoned</name> - <value>true</value> - </parameter> - </ResourceParams> - - <!-- Define a database connection pool for MYSQL --> - <Resource name="jdbc/petclinicMYSQL" auth="Container" type="javax.sql.DataSource"/> - <ResourceParams name="jdbc/petclinicMYSQL"> - <parameter> - <name>factory</name> - <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> - </parameter> - - <parameter> - <name>driverClassName</name> - <value>org.gjt.mm.mysql.Driver</value> - </parameter> - <!-- - The JDBC connection url for connecting to your MySQL dB. - The autoReconnect=true argument to the url makes sure that the - mm.mysql JDBC Driver will automatically reconnect if mysqld closed the - connection. mysqld by default closes idle connections after 8 hours. - --> - <parameter> - <name>url</name> - <value>jdbc:mysql://localhost:3306/petclinic?autoReconnect=true</value> - </parameter> - <parameter> - <name>username</name> - <value>pc</value> - </parameter> - <parameter> - <name>password</name> - <value>pc</value> - </parameter> - - <parameter> - <name>maxActive</name> - <value>50</value> - </parameter> - <parameter> - <name>maxIdle</name> - <value>10</value> - </parameter> - <parameter> - <name>maxWait</name> - <value>10000</value> - </parameter> - <parameter> - <name>removeAbandoned</name> - <value>true</value> - </parameter> - <parameter> - <name>removeAbandonedTimeout</name> - <value>60</value> - </parameter> - <parameter> - <name>logAbandoned</name> - <value>true</value> - </parameter> - </ResourceParams> - - -</Context> diff --git a/db/populateDB.txt b/db/populateDB.txt deleted file mode 100644 index 1bf0c4a..0000000 --- a/db/populateDB.txt +++ /dev/null @@ -1,53 +0,0 @@ -INSERT INTO vets VALUES (1, 'James', 'Carter'); -INSERT INTO vets VALUES (2, 'Helen', 'Leary'); -INSERT INTO vets VALUES (3, 'Linda', 'Douglas'); -INSERT INTO vets VALUES (4, 'Rafael', 'Ortega'); -INSERT INTO vets VALUES (5, 'Henry', 'Stevens'); -INSERT INTO vets VALUES (6, 'Sharon', 'Jenkins'); - -INSERT INTO specialties VALUES (1, 'radiology'); -INSERT INTO specialties VALUES (2, 'surgery'); -INSERT INTO specialties VALUES (3, 'dentistry'); - -INSERT INTO vet_specialties VALUES (2, 1); -INSERT INTO vet_specialties VALUES (3, 2); -INSERT INTO vet_specialties VALUES (3, 3); -INSERT INTO vet_specialties VALUES (4, 2); -INSERT INTO vet_specialties VALUES (5, 1); - -INSERT INTO types VALUES (1, 'cat'); -INSERT INTO types VALUES (2, 'dog'); -INSERT INTO types VALUES (3, 'lizard'); -INSERT INTO types VALUES (4, 'snake'); -INSERT INTO types VALUES (5, 'bird'); -INSERT INTO types VALUES (6, 'hamster'); - -INSERT INTO owners VALUES (1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023'); -INSERT INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749'); -INSERT INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763'); -INSERT INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198'); -INSERT INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765'); -INSERT INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654'); -INSERT INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387'); -INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683'); -INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435'); -INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487'); - -INSERT INTO pets VALUES (1, 'Leo', '2000-09-07', 1, 1); -INSERT INTO pets VALUES (2, 'Basil', '2002-08-06', 6, 2); -INSERT INTO pets VALUES (3, 'Rosy', '2001-04-17', 2, 3); -INSERT INTO pets VALUES (4, 'Jewel', '2000-03-07', 2, 3); -INSERT INTO pets VALUES (5, 'Iggy', '2000-11-30', 3, 4); -INSERT INTO pets VALUES (6, 'George', '2000-01-20', 4, 5); -INSERT INTO pets VALUES (7, 'Samantha', '1995-09-04', 1, 6); -INSERT INTO pets VALUES (8, 'Max', '1995-09-04', 1, 6); -INSERT INTO pets VALUES (9, 'Lucky', '1999-08-06', 5, 7); -INSERT INTO pets VALUES (10, 'Mulligan', '1997-02-24', 2, 8); -INSERT INTO pets VALUES (11, 'Freddy', '2000-03-09', 5, 9); -INSERT INTO pets VALUES (12, 'Lucky', '2000-06-24', 2, 10); -INSERT INTO pets VALUES (13, 'Sly', '2002-06-08', 1, 10); - -INSERT INTO visits VALUES (1, 7, '1996-03-04', 'rabies shot'); -INSERT INTO visits VALUES (2, 8, '1996-03-04', 'rabies shot'); -INSERT INTO visits VALUES (3, 8, '1996-06-04', 'neutered'); -INSERT INTO visits VALUES (4, 7, '1996-09-04', 'spayed'); diff --git a/pom.xml b/pom.xml index 10e9ca9..6174812 100644 --- a/pom.xml +++ b/pom.xml @@ -3,8 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.springframework.samples</groupId> - <artifactId>petclinic-classic</artifactId> - <name>petclinic-classic</name> + <artifactId>petclinic</artifactId> + <name>petclinic</name> <packaging>war</packaging> <version>1.0.0-SNAPSHOT</version> <properties> @@ -102,6 +102,14 @@ <artifactId>com.springsource.org.hsqldb</artifactId> <version>1.8.0.9</version> </dependency> + <!-- MySQL JDBC Connector --> + <!-- + <dependency> + <groupId>com.mysql.jdbc</groupId> + <artifactId>com.springsource.com.mysql.jdbc</artifactId> + <version>5.1.6</version> + </dependency> + --> <dependency> <groupId>org.jdom</groupId> <artifactId>com.springsource.org.jdom</artifactId> @@ -112,6 +120,11 @@ <artifactId>org.springframework.asm</artifactId> <version>${spring.version}</version> </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>org.springframework.aspects</artifactId> + <version>${spring.version}</version> + </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>org.springframework.orm</artifactId> @@ -156,19 +169,16 @@ <groupId>org.slf4j</groupId> <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId> <version>${slf4j.version}</version> - <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>com.springsource.slf4j.api</artifactId> <version>${slf4j.version}</version> - <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>com.springsource.slf4j.log4j</artifactId> <version>${slf4j.version}</version> - <scope>provided</scope> <exclusions> <exclusion> <groupId>log4j</groupId> diff --git a/src/main/resources/db/db_readme.txt b/src/main/resources/db/db_readme.txt new file mode 100644 index 0000000..80deff0 --- /dev/null +++ b/src/main/resources/db/db_readme.txt @@ -0,0 +1,15 @@ +================================================================================ +=== Spring PetClinic sample application - Database Configuration === +================================================================================ + +@author Costin Leau + +-------------------------------------------------------------------------------- + +In its default configuration, Petclinic uses an in-memory database (HSQLDB) which +gets populated at startup with data. Since there is no persistent support, once +the application is destroyed, so is the database. +If a persistent database configuration is chosen, make sure to change the datasource +inside the relevant application-*.xml so that the schema and the data do not get +inserted each time the application is started. Additionally, update the jdbc.properties +file to reflect your change. \ No newline at end of file -- GitLab