diff --git a/pom.xml b/pom.xml
index d9e1dc7ff..a0cb554ea 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,17 +29,10 @@
5.1.36
-
+
9.4.1211.jre7
2.7
-
- HSQL
- org.hsqldb.jdbcDriver
- jdbc:hsqldb:mem:petclinic
- sa
-
-
@@ -164,13 +157,6 @@
runtime
-
-
- org.hsqldb
- hsqldb
- runtime
-
-
org.hibernate
@@ -429,8 +415,30 @@
- MYSQL
+ HSQLDB
+
+ true
+
+ hsqldb
+ HSQL
+ org.hsqldb.jdbcDriver
+ jdbc:hsqldb:mem:petclinic
+ sa
+
+
+
+
+ org.hsqldb
+ hsqldb
+ runtime
+
+
+
+
+ MySQL
+
+ mysql
MYSQL
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/petclinic?useUnicode=true
@@ -442,14 +450,15 @@
mysql
mysql-connector-java
${mysql-driver.version}
+ runtime
- POSTGRESQL
+ PostgreSQL
+ postgresql
POSTGRESQL
- org.hibernate.dialect.PostgreSQLDialect
org.postgresql.Driver
jdbc:postgresql://localhost:5432/petclinic
postgres
@@ -460,6 +469,7 @@
org.postgresql
postgresql
${postgresql-driver.version}
+ runtime
diff --git a/readme.md b/readme.md
index 738057be9..bcb3c0916 100644
--- a/readme.md
+++ b/readme.md
@@ -23,13 +23,13 @@ gets populated at startup with data.
A similar setups is provided for MySql and PostgreSQL in case a persistent database configuration is needed.
To run petclinic locally using persistent database, it is needed to run with profile defined in main pom.xml file.
-For MySQL database, it is needed to run with 'MYSQL' profile defined in main pom.xml file.
+For MySQL database, it is needed to run with 'MySQL' profile defined in main pom.xml file.
```
- ./mvnw tomcat7:run -P MYSQL
+ ./mvnw tomcat7:run -P MySQL
```
-Before do this, would be good to check properties defined in MYSQL profile inside pom.xml file.
+Before do this, would be good to check properties defined in MySQL profile inside pom.xml file.
```
@@ -47,13 +47,13 @@ You may start a MySql database with docker:
docker run -e MYSQL_ROOT_PASSWORD=petclinic -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8
```
-For PostgreSQL database, it is needed to run with 'POSTGRESQL' profile defined in main pom.xml file.
+For PostgreSQL database, it is needed to run with 'PostgreSQL' profile defined in main pom.xml file.
```
- ./mvnw tomcat7:run -P POSTGRESQL
+ ./mvnw tomcat7:run -P PostgreSQL
```
-Before do this, would be good to check properties defined in POSTGRESQL profile inside pom.xml file.
+Before do this, would be good to check properties defined in PostgreSQL profile inside pom.xml file.
```
diff --git a/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt b/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt
index 251562ebc..21f616109 100644
--- a/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt
+++ b/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt
@@ -7,18 +7,17 @@
--------------------------------------------------------------------------------
-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/
+1) Download and install the MySQL database (e.g., MySQL Community Server 5.7.x),
+ which can be found here: http://dev.mysql.com/downloads/mysql/
+ Alternatively, you may use the official MySQL docker image. Refer to the
+ README.md for the Docker command line.
-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. Alternatively, uncomment the mysql-connector from the
- Petclinic pom.
+2) Dependency for Connector/J, the MySQL JDBC driver (e.g., Connector/J 5.1.x) is
+ included in Petclinic pom.xml file. See the MySQL maven profile.
+ Alternatively, download Connector/J JDBC driver from here:
+ http://dev.mysql.com/downloads/connector/j/
+ and copy the PostgreSQL JDBC driver JAR file (e.g., postgresql-9.4.1211.jre7.jar).
-3) Create the PetClinic database and user by executing the "db/mysql/initDB.sql"
- script.
-
-4) Open "src/main/resources/spring/data-access.properties"; comment out all properties in the
- "HSQL Settings" section; uncomment all properties in the "MySQL Settings"
- section.
+3) Change connection parameters into the MySQL profile of the pom.xml.
+ Build and starth the web app with the MySQL profile:
+ ./mvnw tomcat7:run -P MySQL
diff --git a/src/main/resources/db/postgresql/initDB.sql b/src/main/resources/db/postgresql/initDB.sql
index 546f18bc9..8fa482a36 100644
--- a/src/main/resources/db/postgresql/initDB.sql
+++ b/src/main/resources/db/postgresql/initDB.sql
@@ -1,9 +1,3 @@
-CREATE DATABASE petclinic
- WITH OWNER = postgres
- ENCODING = 'UTF8'
- TABLESPACE = pg_default
- CONNECTION LIMIT = -1;
-
CREATE TABLE IF NOT EXISTS vets (
id SERIAL,
first_name VARCHAR(30),
@@ -11,7 +5,7 @@ CREATE TABLE IF NOT EXISTS vets (
CONSTRAINT pk_vets PRIMARY KEY (id)
);
-CREATE INDEX idx_vets_last_name ON vets (last_name);
+CREATE INDEX IF NOT EXISTS idx_vets_last_name ON vets (last_name);
ALTER SEQUENCE vets_id_seq RESTART WITH 100;
@@ -22,7 +16,7 @@ CREATE TABLE IF NOT EXISTS specialties (
CONSTRAINT pk_specialties PRIMARY KEY (id)
);
-CREATE INDEX idx_specialties_name ON specialties (name);
+CREATE INDEX IF NOT EXISTS idx_specialties_name ON specialties (name);
ALTER SEQUENCE specialties_id_seq RESTART WITH 100;
@@ -43,7 +37,7 @@ CREATE TABLE IF NOT EXISTS types (
CONSTRAINT pk_types PRIMARY KEY (id)
);
-CREATE INDEX idx_types_name ON types (name);
+CREATE INDEX IF NOT EXISTS idx_types_name ON types (name);
ALTER SEQUENCE types_id_seq RESTART WITH 100;
@@ -57,7 +51,7 @@ CREATE TABLE IF NOT EXISTS owners (
CONSTRAINT pk_owners PRIMARY KEY (id)
);
-CREATE INDEX idx_owners_last_name ON owners (last_name);
+CREATE INDEX IF NOT EXISTS idx_owners_last_name ON owners (last_name);
ALTER SEQUENCE owners_id_seq RESTART WITH 100;
@@ -73,7 +67,7 @@ CREATE TABLE IF NOT EXISTS pets (
CONSTRAINT pk_pets PRIMARY KEY (id)
);
-CREATE INDEX idx_pets_name ON pets (name);
+CREATE INDEX IF NOT EXISTS idx_pets_name ON pets (name);
ALTER SEQUENCE pets_id_seq RESTART WITH 100;
diff --git a/src/main/resources/db/postgresql/petclinic_db_setup_postgresql.txt b/src/main/resources/db/postgresql/petclinic_db_setup_postgresql.txt
index c76ff3135..6d450b7ad 100644
--- a/src/main/resources/db/postgresql/petclinic_db_setup_postgresql.txt
+++ b/src/main/resources/db/postgresql/petclinic_db_setup_postgresql.txt
@@ -1,5 +1,5 @@
================================================================================
-=== Spring PetClinic sample application - PostgreSQL Configuration ===
+=== Spring PetClinic sample application - PostgreSQL Configuration ===
================================================================================
@author Sam Brannen
@@ -11,22 +11,19 @@
which can be found here: https://www.postgresql.org/download/
2) Dependency for postgresql-driver included in Petclinic pom.xml file.
- Alternatively, download PostgreSQL JDBC driver from here: https://jdbc.postgresql.org/download.html
+ See the PostgreSQL maven profile.
+ Alternatively, download PostgreSQL JDBC driver from here: https://jdbc.postgresql.org/download.html
and copy the PostgreSQL JDBC driver JAR file (e.g., postgresql-9.4.1211.jre7.jar) into
- the db/postgesql directory.
+ the db/postgesql directory.
-3) Create the PetClinic database
+3) Open psql and create the PetClinic database:
CREATE DATABASE petclinic
WITH OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
CONNECTION LIMIT = -1;
-
- and execute the "db/postgresql/initDB.sql" script, then execute "db/postgresql/populateDB.sql"
-4) Open "src/main/resources/spring/datasource-config.xml"; comment block
-
-
-
-
+4) If required, change connection parameters into the PostgreSQL profile of the pom.xml.
+ Build and starth the web app with the PostgreSQL profile:
+ ./mvnw tomcat7:run -P PostgreSQL
diff --git a/src/main/resources/db/postgresql/populateDB.sql b/src/main/resources/db/postgresql/populateDB.sql
index 11368403f..0f7a94dc7 100644
--- a/src/main/resources/db/postgresql/populateDB.sql
+++ b/src/main/resources/db/postgresql/populateDB.sql
@@ -1,53 +1,53 @@
-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 vets VALUES (1, 'James', 'Carter') ON CONFLICT DO NOTHING;
+INSERT INTO vets VALUES (2, 'Helen', 'Leary') ON CONFLICT DO NOTHING;
+INSERT INTO vets VALUES (3, 'Linda', 'Douglas') ON CONFLICT DO NOTHING;
+INSERT INTO vets VALUES (4, 'Rafael', 'Ortega') ON CONFLICT DO NOTHING;
+INSERT INTO vets VALUES (5, 'Henry', 'Stevens') ON CONFLICT DO NOTHING;
+INSERT INTO vets VALUES (6, 'Sharon', 'Jenkins') ON CONFLICT DO NOTHING;
-INSERT INTO specialties VALUES (1, 'radiology');
-INSERT INTO specialties VALUES (2, 'surgery');
-INSERT INTO specialties VALUES (3, 'dentistry');
+INSERT INTO specialties VALUES (1, 'radiology') ON CONFLICT DO NOTHING;
+INSERT INTO specialties VALUES (2, 'surgery') ON CONFLICT DO NOTHING;
+INSERT INTO specialties VALUES (3, 'dentistry') ON CONFLICT DO NOTHING;
-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 vet_specialties VALUES (2, 1) ON CONFLICT DO NOTHING;
+INSERT INTO vet_specialties VALUES (3, 2) ON CONFLICT DO NOTHING;
+INSERT INTO vet_specialties VALUES (3, 3) ON CONFLICT DO NOTHING;
+INSERT INTO vet_specialties VALUES (4, 2) ON CONFLICT DO NOTHING;
+INSERT INTO vet_specialties VALUES (5, 1) ON CONFLICT DO NOTHING;
-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 types VALUES (1, 'cat') ON CONFLICT DO NOTHING;
+INSERT INTO types VALUES (2, 'dog') ON CONFLICT DO NOTHING;
+INSERT INTO types VALUES (3, 'lizard') ON CONFLICT DO NOTHING;
+INSERT INTO types VALUES (4, 'snake') ON CONFLICT DO NOTHING;
+INSERT INTO types VALUES (5, 'bird') ON CONFLICT DO NOTHING;
+INSERT INTO types VALUES (6, 'hamster') ON CONFLICT DO NOTHING;
-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 owners VALUES (1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023') ON CONFLICT DO NOTHING;
+INSERT INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749') ON CONFLICT DO NOTHING;
+INSERT INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763') ON CONFLICT DO NOTHING;
+INSERT INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198') ON CONFLICT DO NOTHING;
+INSERT INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765') ON CONFLICT DO NOTHING;
+INSERT INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654') ON CONFLICT DO NOTHING;
+INSERT INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387') ON CONFLICT DO NOTHING;
+INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683') ON CONFLICT DO NOTHING;
+INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435') ON CONFLICT DO NOTHING;
+INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487') ON CONFLICT DO NOTHING;
-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 pets VALUES (1, 'Leo', '2000-09-07', 1, 1) ON CONFLICT DO NOTHING;
+INSERT INTO pets VALUES (2, 'Basil', '2002-08-06', 6, 2) ON CONFLICT DO NOTHING;
+INSERT INTO pets VALUES (3, 'Rosy', '2001-04-17', 2, 3) ON CONFLICT DO NOTHING;
+INSERT INTO pets VALUES (4, 'Jewel', '2000-03-07', 2, 3) ON CONFLICT DO NOTHING;
+INSERT INTO pets VALUES (5, 'Iggy', '2000-11-30', 3, 4) ON CONFLICT DO NOTHING;
+INSERT INTO pets VALUES (6, 'George', '2000-01-20', 4, 5) ON CONFLICT DO NOTHING;
+INSERT INTO pets VALUES (7, 'Samantha', '1995-09-04', 1, 6) ON CONFLICT DO NOTHING;
+INSERT INTO pets VALUES (8, 'Max', '1995-09-04', 1, 6) ON CONFLICT DO NOTHING;
+INSERT INTO pets VALUES (9, 'Lucky', '1999-08-06', 5, 7) ON CONFLICT DO NOTHING;
+INSERT INTO pets VALUES (10, 'Mulligan', '1997-02-24', 2, 8) ON CONFLICT DO NOTHING;
+INSERT INTO pets VALUES (11, 'Freddy', '2000-03-09', 5, 9) ON CONFLICT DO NOTHING;
+INSERT INTO pets VALUES (12, 'Lucky', '2000-06-24', 2, 10) ON CONFLICT DO NOTHING;
+INSERT INTO pets VALUES (13, 'Sly', '2002-06-08', 1, 10) ON CONFLICT DO NOTHING;
-INSERT INTO visits VALUES (1, 7, '2010-03-04', 'rabies shot');
-INSERT INTO visits VALUES (2, 8, '2011-03-04', 'rabies shot');
-INSERT INTO visits VALUES (3, 8, '2009-06-04', 'neutered');
-INSERT INTO visits VALUES (4, 7, '2008-09-04', 'spayed');
+INSERT INTO visits VALUES (1, 7, '2010-03-04', 'rabies shot') ON CONFLICT DO NOTHING;
+INSERT INTO visits VALUES (2, 8, '2011-03-04', 'rabies shot') ON CONFLICT DO NOTHING;
+INSERT INTO visits VALUES (3, 8, '2009-06-04', 'neutered') ON CONFLICT DO NOTHING;
+INSERT INTO visits VALUES (4, 7, '2008-09-04', 'spayed') ON CONFLICT DO NOTHING;
diff --git a/src/main/resources/spring/data-access.properties b/src/main/resources/spring/data-access.properties
index b6059028c..f039ea269 100644
--- a/src/main/resources/spring/data-access.properties
+++ b/src/main/resources/spring/data-access.properties
@@ -5,8 +5,8 @@
# Targeted at system administrators, to avoid touching the context XML files.
# Properties that control the population of schema and data for a new data source
-jdbc.initLocation=classpath:db/hsqldb/initDB.sql
-jdbc.dataLocation=classpath:db/hsqldb/populateDB.sql
+jdbc.initLocation=classpath:db/${db.script}/initDB.sql
+jdbc.dataLocation=classpath:db/${db.script}/populateDB.sql
jpa.showSql=true