diff --git a/src/main/resources/hsqldb/dropTables.txt b/src/main/resources/db/hsqldb/dropTables.txt similarity index 100% rename from src/main/resources/hsqldb/dropTables.txt rename to src/main/resources/db/hsqldb/dropTables.txt diff --git a/src/main/resources/hsqldb/initDB.txt b/src/main/resources/db/hsqldb/initDB.txt similarity index 100% rename from src/main/resources/hsqldb/initDB.txt rename to src/main/resources/db/hsqldb/initDB.txt diff --git a/src/main/resources/hsqldb/populateDB.txt b/src/main/resources/db/hsqldb/populateDB.txt similarity index 100% rename from src/main/resources/hsqldb/populateDB.txt rename to src/main/resources/db/hsqldb/populateDB.txt diff --git a/src/main/resources/db/mysql/createDB.txt b/src/main/resources/db/mysql/createDB.txt new file mode 100644 index 000000000..5b4b3859e --- /dev/null +++ b/src/main/resources/db/mysql/createDB.txt @@ -0,0 +1,3 @@ +CREATE DATABASE petclinic; + +GRANT ALL PRIVILEGES ON petclinic.* TO pc@localhost IDENTIFIED BY 'pc'; \ No newline at end of file diff --git a/src/main/resources/db/mysql/dropDB.txt b/src/main/resources/db/mysql/dropDB.txt new file mode 100644 index 000000000..e1209da0e --- /dev/null +++ b/src/main/resources/db/mysql/dropDB.txt @@ -0,0 +1 @@ +DROP DATABASE petclinic; diff --git a/src/main/resources/db/mysql/initDB.txt b/src/main/resources/db/mysql/initDB.txt new file mode 100644 index 000000000..0007ee3a3 --- /dev/null +++ b/src/main/resources/db/mysql/initDB.txt @@ -0,0 +1,58 @@ +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/src/main/resources/db/mysql/petclinic_tomcat_mysql.xml b/src/main/resources/db/mysql/petclinic_tomcat_mysql.xml new file mode 100644 index 000000000..d1c5a3b04 --- /dev/null +++ b/src/main/resources/db/mysql/petclinic_tomcat_mysql.xml @@ -0,0 +1,64 @@ + + + + + + + + + + factory + org.apache.commons.dbcp.BasicDataSourceFactory + + + + driverClassName + org.gjt.mm.mysql.Driver + + + + url + jdbc:mysql://localhost:3306/petclinic?autoReconnect=true + + + username + pc + + + password + pc + + + + maxActive + 50 + + + maxIdle + 10 + + + maxWait + 10000 + + + removeAbandoned + true + + + removeAbandonedTimeout + 60 + + + logAbandoned + true + + + + + diff --git a/src/main/resources/jdbc.properties b/src/main/resources/jdbc.properties index 47537f9cd..02bda078b 100644 --- a/src/main/resources/jdbc.properties +++ b/src/main/resources/jdbc.properties @@ -23,9 +23,9 @@ jdbc.password= # Properties that control the population of schema and data for a new data source jdbc.populate=true -jdbc.schemaLocation=classpath:hsqldb/initDB.txt -jdbc.dataLocation=classpath:hsqldb/populateDB.txt -jdbc.dropLocation=classpath:hsqldb/dropTables.txt +jdbc.schemaLocation=classpath:db/hsqldb/initDB.txt +jdbc.dataLocation=classpath:db/hsqldb/populateDB.txt +jdbc.dropLocation=classpath:db/hsqldb/dropTables.txt # Property that determines which Hibernate dialect to use # (only applied with "applicationContext-hibernate.xml") @@ -48,9 +48,9 @@ jpa.database=HSQL # Properties that control the population of schema and data for a new data source #jdbc.populate=false -#jdbc.schemaLocation= -#jdbc.dataLocation= -#jdbc.dropLocation= +#jdbc.schemaLocation=classpath:db/mysql/initDB.txt +#jdbc.dataLocation=classpath:db/mysql/populateDB.txt +#jdbc.dropLocation=classpath:db/mysql/dropTables.txt # Property that determines which Hibernate dialect to use # (only applied with "applicationContext-hibernate.xml")