From aa6172bfec1216623fa9e8d5634780631794ee27 Mon Sep 17 00:00:00 2001 From: anbu Date: Sun, 31 Jan 2021 04:16:39 +0000 Subject: [PATCH] Made the webapp launch, but some of the forms fail - need to investigate --- pom.xml | 4 + .../samples/petclinic/model/BaseEntity.java | 50 +------ .../samples/petclinic/model/NamedEntity.java | 23 +--- .../samples/petclinic/model/Person.java | 26 ++-- .../samples/petclinic/owner/Owner.java | 44 +++--- .../samples/petclinic/owner/Pet.java | 15 ++- .../samples/petclinic/owner/PetType.java | 16 ++- .../samples/petclinic/system/InitData.java | 96 +++++++++++++ .../samples/petclinic/vet/Specialty.java | 20 ++- .../samples/petclinic/vet/Vet.java | 7 + .../samples/petclinic/visit/Visit.java | 37 ++--- .../petclinic/visit/VisitRepository.java | 1 - src/main/resources/application.yml | 12 +- src/main/resources/db/h2/data.sql | 45 +++---- src/main/resources/db/h2/schema.sql | 127 +++++++++--------- .../petclinic/service/EntityUtils.java | 2 +- 16 files changed, 291 insertions(+), 234 deletions(-) create mode 100644 src/main/java/org/springframework/samples/petclinic/system/InitData.java diff --git a/pom.xml b/pom.xml index 733c136ec..cbe3d20f2 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,10 @@ org.springframework.boot spring-boot-starter-thymeleaf + + org.liquibase + liquibase-core + org.springframework.boot spring-boot-starter-test diff --git a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java index 37e14c589..5151a640c 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java +++ b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java @@ -1,51 +1,9 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package org.springframework.samples.petclinic.model; -import java.io.Serializable; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; +public interface BaseEntity { + Integer getId(); -/** - * Simple JavaBean domain object with an id property. Used as a base class for objects - * needing this property. - * - * @author Ken Krebs - * @author Juergen Hoeller - */ -@MappedSuperclass -public class BaseEntity implements Serializable { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - public Integer getId() { - return id; + default boolean isNew() { + return getId() == null; } - - public void setId(Integer id) { - this.id = id; - } - - public boolean isNew() { - return this.id == null; - } - } diff --git a/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java b/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java index 741c909d5..486c667e6 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java +++ b/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java @@ -16,9 +16,6 @@ package org.springframework.samples.petclinic.model; -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; - /** * Simple JavaBean domain object adds a name property to BaseEntity. Used as * a base class for objects needing these properties. @@ -26,23 +23,7 @@ import javax.persistence.MappedSuperclass; * @author Ken Krebs * @author Juergen Hoeller */ -@MappedSuperclass -public class NamedEntity extends BaseEntity { - - @Column(name = "name") - private String name; - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - @Override - public String toString() { - return this.getName(); - } +public interface NamedEntity extends BaseEntity { + String getName(); } diff --git a/src/main/java/org/springframework/samples/petclinic/model/Person.java b/src/main/java/org/springframework/samples/petclinic/model/Person.java index 0758254ef..da03f7ad4 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Person.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Person.java @@ -17,8 +17,12 @@ package org.springframework.samples.petclinic.model; import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; import javax.persistence.MappedSuperclass; import javax.validation.constraints.NotEmpty; +import lombok.Data; /** * Simple JavaBean domain object representing an person. @@ -26,7 +30,11 @@ import javax.validation.constraints.NotEmpty; * @author Ken Krebs */ @MappedSuperclass -public class Person extends BaseEntity { +@Data +public class Person implements BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Integer id; @Column(name = "first_name") @NotEmpty @@ -36,20 +44,4 @@ public class Person extends BaseEntity { @NotEmpty private String lastName; - public String getFirstName() { - return this.firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return this.lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - } diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java index b429ee869..ad74c69ab 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java @@ -24,13 +24,19 @@ import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.validation.constraints.Digits; import javax.validation.constraints.NotEmpty; +import lombok.Data; +import lombok.NoArgsConstructor; import org.springframework.beans.support.MutableSortDefinition; import org.springframework.beans.support.PropertyComparator; import org.springframework.core.style.ToStringCreator; +import org.springframework.samples.petclinic.model.BaseEntity; import org.springframework.samples.petclinic.model.Person; /** @@ -43,7 +49,12 @@ import org.springframework.samples.petclinic.model.Person; */ @Entity @Table(name = "owners") -public class Owner extends Person { +@Data +@NoArgsConstructor +public class Owner extends Person implements BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Integer id; @Column(name = "address") @NotEmpty @@ -61,28 +72,15 @@ public class Owner extends Person { @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") private Set pets; - public String getAddress() { - return this.address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getCity() { - return this.city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getTelephone() { - return this.telephone; - } - - public void setTelephone(String telephone) { - this.telephone = telephone; + /** + * all args constructor. + */ + public Owner(String firstName, String lastName, String address, String city, String telephone) { + this.setFirstName(firstName); + this.setLastName(lastName); + this.setAddress(address); + this.setCity(city); + this.setTelephone(telephone); } protected Set getPetsInternal() { diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java b/src/main/java/org/springframework/samples/petclinic/owner/Pet.java index 22e991acb..863e1c6ac 100755 --- a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Pet.java @@ -26,14 +26,18 @@ import java.util.List; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.Transient; +import lombok.Data; import org.springframework.beans.support.MutableSortDefinition; import org.springframework.beans.support.PropertyComparator; import org.springframework.format.annotation.DateTimeFormat; -import org.springframework.samples.petclinic.model.NamedEntity; +import org.springframework.samples.petclinic.model.BaseEntity; import org.springframework.samples.petclinic.visit.Visit; /** @@ -45,7 +49,14 @@ import org.springframework.samples.petclinic.visit.Visit; */ @Entity @Table(name = "pets") -public class Pet extends NamedEntity { +@Data +public class Pet implements BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Integer id; + + @Column(name = "name") + private String name; @Column(name = "birth_date") @DateTimeFormat(pattern = "yyyy-MM-dd") diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetType.java b/src/main/java/org/springframework/samples/petclinic/owner/PetType.java index 38dae555d..349159210 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/PetType.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/PetType.java @@ -16,8 +16,15 @@ package org.springframework.samples.petclinic.owner; +import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; import javax.persistence.Table; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; import org.springframework.samples.petclinic.model.NamedEntity; /** @@ -27,6 +34,13 @@ import org.springframework.samples.petclinic.model.NamedEntity; */ @Entity @Table(name = "types") -public class PetType extends NamedEntity { +@Data +public class PetType implements NamedEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Integer id; + + @Column(name = "name") + private String name; } diff --git a/src/main/java/org/springframework/samples/petclinic/system/InitData.java b/src/main/java/org/springframework/samples/petclinic/system/InitData.java new file mode 100644 index 000000000..c7a1a0ce9 --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/system/InitData.java @@ -0,0 +1,96 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.samples.petclinic.system; + +import java.util.stream.Stream; +import javax.annotation.PostConstruct; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import lombok.extern.slf4j.Slf4j; +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.samples.petclinic.owner.Owner; +import org.springframework.samples.petclinic.owner.PetType; +import org.springframework.samples.petclinic.vet.Specialty; +import org.springframework.samples.petclinic.vet.Vet; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +@Component +@Slf4j +@Transactional +class InitData { + private final EntityManagerFactory emf; + + @Autowired + public InitData(EntityManagerFactory emf) { + this.emf = emf; + } + + @PostConstruct + public void registerListeners() { + SessionFactory sessionFactory = emf.unwrap(SessionFactory.class); + EntityManager em = sessionFactory.createEntityManager(); + + createPetTypes(em); + createOwners(em); + createVets(em); + createSpecialities(em); + } + + private void createPetTypes(EntityManager em) { + em.getTransaction().begin(); + Stream.of("cat", "dog", "lizard", "snake", "bird", "hamster").forEach(v -> { + PetType petType = new PetType(); + em.persist(petType); + }); + em.getTransaction().commit(); + } + + private void createSpecialities(EntityManager em) { + em.getTransaction().begin(); + Stream.of("radiology", "surgery", "dentistry").forEach(name -> em.persist(new Specialty(name))); + em.getTransaction().commit(); + } + + private void createVets(EntityManager em) { + em.getTransaction().begin(); + em.persist(new Vet("James", "Carter")); + em.persist(new Vet("Helen", "Leary")); + em.persist(new Vet("Linda", "Douglas")); + em.persist(new Vet("Rafael", "Ortega")); + em.persist(new Vet("Henry", "Stevens")); + em.persist(new Vet("Sharon", "Jenkins")); + em.getTransaction().commit(); + } + + private void createOwners(EntityManager em) { + em.getTransaction().begin(); + em.persist(new Owner("George", "Franklin", "110 W. Liberty St.", "Madison", "6085551023")); + em.persist(new Owner("Betty", "Davis", "638 Cardinal Ave.", "Sun Prairie", "6085551749")); + em.persist(new Owner("Eduardo", "Rodriquez", "2693 Commerce St.", "McFarland", "6085558763")); + em.persist(new Owner("Harold", "Davis", "563 Friendly St.", "Windsor", "6085553198")); + em.persist(new Owner("Peter", "McTavish", "2387 S. Fair Way", "Madison", "6085552765")); + em.persist(new Owner("Jean", "Coleman", "105 N. Lake St.", "Monona", "6085552654")); + em.persist(new Owner("Jeff", "Black", "1450 Oak Blvd.", "Monona", "6085555387")); + em.persist(new Owner("Maria", "Escobito", "345 Maple St.", "Madison", "6085557683")); + em.persist(new Owner("David", "Schroeder", "2749 Blackhawk Trail", "Madison", "6085559435")); + em.persist(new Owner("Carlos", "Estaban", "2335 Independence La.", "Waunakee", "6085555487")); + em.getTransaction().commit(); + } + +} diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java b/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java index 7d1ac9b92..777d9bffe 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java @@ -17,8 +17,14 @@ package org.springframework.samples.petclinic.vet; import java.io.Serializable; +import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; import javax.persistence.Table; +import lombok.Data; +import lombok.NoArgsConstructor; import org.springframework.samples.petclinic.model.NamedEntity; /** @@ -28,6 +34,18 @@ import org.springframework.samples.petclinic.model.NamedEntity; */ @Entity @Table(name = "specialties") -public class Specialty extends NamedEntity implements Serializable { +@Data +@NoArgsConstructor +public class Specialty implements Serializable { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Integer id; + + @Column(name = "name") + private String name; + + public Specialty(String name) { + this.setName(name); + } } diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Vet.java b/src/main/java/org/springframework/samples/petclinic/vet/Vet.java index 543f19928..6bc53a4b9 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/Vet.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Vet.java @@ -28,6 +28,7 @@ import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.Table; import javax.xml.bind.annotation.XmlElement; +import lombok.NoArgsConstructor; import org.springframework.beans.support.MutableSortDefinition; import org.springframework.beans.support.PropertyComparator; import org.springframework.samples.petclinic.model.Person; @@ -42,8 +43,14 @@ import org.springframework.samples.petclinic.model.Person; */ @Entity @Table(name = "vets") +@NoArgsConstructor public class Vet extends Person { + public Vet(String firstName, String lastName) { + this.setFirstName(firstName); + this.setLastName(lastName); + } + @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), inverseJoinColumns = @JoinColumn(name = "specialty_id")) diff --git a/src/main/java/org/springframework/samples/petclinic/visit/Visit.java b/src/main/java/org/springframework/samples/petclinic/visit/Visit.java index 1d435307a..66ee798d3 100755 --- a/src/main/java/org/springframework/samples/petclinic/visit/Visit.java +++ b/src/main/java/org/springframework/samples/petclinic/visit/Visit.java @@ -16,13 +16,17 @@ package org.springframework.samples.petclinic.visit; +import java.io.Serializable; import java.time.LocalDate; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; import javax.persistence.Table; import javax.validation.constraints.NotEmpty; +import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; -import org.springframework.samples.petclinic.model.BaseEntity; /** * Simple JavaBean domain object representing a visit. @@ -32,7 +36,11 @@ import org.springframework.samples.petclinic.model.BaseEntity; */ @Entity @Table(name = "visits") -public class Visit extends BaseEntity { +@Data +public class Visit implements Serializable { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Integer id; @Column(name = "visit_date") @DateTimeFormat(pattern = "yyyy-MM-dd") @@ -51,29 +59,4 @@ public class Visit extends BaseEntity { public Visit() { this.date = LocalDate.now(); } - - public LocalDate getDate() { - return this.date; - } - - public void setDate(LocalDate date) { - this.date = date; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Integer getPetId() { - return this.petId; - } - - public void setPetId(Integer petId) { - this.petId = petId; - } - } diff --git a/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java b/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java index cddb3cb57..5c23561c0 100644 --- a/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java @@ -19,7 +19,6 @@ package org.springframework.samples.petclinic.visit; import java.util.List; import org.springframework.dao.DataAccessException; import org.springframework.data.repository.Repository; -import org.springframework.samples.petclinic.model.BaseEntity; /** * Repository class for Visit domain objects All method names are compliant diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index be804faed..3153cfced 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,15 +2,17 @@ database: h2 spring: datasource: - schema: classpath*:db/${database}/schema.sql +# schema: classpath*:db/${database}/schema.sql data: classpath*:db/${database}/data.sql jpa: hibernate.ddl-auto: none open-in-view: false -spring.thymeleaf.mode: HTML - -# Internationalization -spring.messages.basename: messages/messages + liquibase: + enabled: true + change-log: classpath*:db/db-changelog.yaml + thymeleaf.mode: HTML + # Internationalization + messages.basename: messages/messages # Actuator management.endpoints.web.exposure.include: '*' diff --git a/src/main/resources/db/h2/data.sql b/src/main/resources/db/h2/data.sql index 16dda3e84..f4f49d4a7 100644 --- a/src/main/resources/db/h2/data.sql +++ b/src/main/resources/db/h2/data.sql @@ -1,13 +1,13 @@ -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'); +-- 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 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); @@ -15,23 +15,16 @@ 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 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', '2010-09-07', 1, 1); INSERT INTO pets VALUES (2, 'Basil', '2012-08-06', 6, 2); diff --git a/src/main/resources/db/h2/schema.sql b/src/main/resources/db/h2/schema.sql index f3c6947b7..9b9ac68ed 100644 --- a/src/main/resources/db/h2/schema.sql +++ b/src/main/resources/db/h2/schema.sql @@ -1,64 +1,65 @@ -DROP TABLE vet_specialties IF EXISTS; -DROP TABLE vets IF EXISTS; -DROP TABLE specialties IF EXISTS; -DROP TABLE visits IF EXISTS; -DROP TABLE pets IF EXISTS; -DROP TABLE types IF EXISTS; -DROP TABLE owners IF EXISTS; +-- DROP TABLE vet_specialties IF EXISTS; +-- DROP TABLE vets IF EXISTS; +-- DROP TABLE specialties IF EXISTS; +-- DROP TABLE visits IF EXISTS; +-- DROP TABLE pets IF EXISTS; +-- DROP TABLE types IF EXISTS; +-- DROP TABLE owners IF EXISTS; +-- +-- +-- CREATE TABLE vets ( +-- id INTEGER IDENTITY PRIMARY KEY, +-- first_name VARCHAR(30), +-- last_name VARCHAR(30) +-- ); +-- CREATE INDEX vets_last_name ON vets (last_name); +-- +-- CREATE TABLE specialties ( +-- id INTEGER IDENTITY PRIMARY KEY, +-- name VARCHAR(80) +-- ); +-- CREATE INDEX specialties_name ON specialties (name); +-- +-- CREATE TABLE vet_specialties ( +-- vet_id INTEGER NOT NULL, +-- specialty_id INTEGER NOT NULL +-- ); +-- 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 INTEGER IDENTITY PRIMARY KEY, +-- name VARCHAR(80) +-- ); +-- CREATE INDEX types_name ON types (name); +-- +-- CREATE TABLE owners ( +-- id INTEGER IDENTITY PRIMARY KEY, +-- first_name VARCHAR(30), +-- last_name VARCHAR_IGNORECASE(30), +-- address VARCHAR(255), +-- city VARCHAR(80), +-- telephone VARCHAR(20) +-- ); +-- CREATE INDEX owners_last_name ON owners (last_name); +-- +-- CREATE TABLE pets ( +-- id INTEGER IDENTITY PRIMARY KEY, +-- name VARCHAR(30), +-- birth_date DATE, +-- type_id INTEGER NOT NULL, +-- owner_id INTEGER NOT NULL +-- ); +-- 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 INTEGER IDENTITY PRIMARY KEY, +-- pet_id INTEGER NOT NULL, +-- visit_date DATE, +-- description VARCHAR(255) +-- ); +-- ALTER TABLE visits ADD CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets (id); +-- CREATE INDEX visits_pet_id ON visits (pet_id); - -CREATE TABLE vets ( - id INTEGER IDENTITY PRIMARY KEY, - first_name VARCHAR(30), - last_name VARCHAR(30) -); -CREATE INDEX vets_last_name ON vets (last_name); - -CREATE TABLE specialties ( - id INTEGER IDENTITY PRIMARY KEY, - name VARCHAR(80) -); -CREATE INDEX specialties_name ON specialties (name); - -CREATE TABLE vet_specialties ( - vet_id INTEGER NOT NULL, - specialty_id INTEGER NOT NULL -); -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 INTEGER IDENTITY PRIMARY KEY, - name VARCHAR(80) -); -CREATE INDEX types_name ON types (name); - -CREATE TABLE owners ( - id INTEGER IDENTITY PRIMARY KEY, - first_name VARCHAR(30), - last_name VARCHAR_IGNORECASE(30), - address VARCHAR(255), - city VARCHAR(80), - telephone VARCHAR(20) -); -CREATE INDEX owners_last_name ON owners (last_name); - -CREATE TABLE pets ( - id INTEGER IDENTITY PRIMARY KEY, - name VARCHAR(30), - birth_date DATE, - type_id INTEGER NOT NULL, - owner_id INTEGER NOT NULL -); -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 INTEGER IDENTITY PRIMARY KEY, - pet_id INTEGER NOT NULL, - visit_date DATE, - description VARCHAR(255) -); -ALTER TABLE visits ADD CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets (id); -CREATE INDEX visits_pet_id ON visits (pet_id); diff --git a/src/test/java/org/springframework/samples/petclinic/service/EntityUtils.java b/src/test/java/org/springframework/samples/petclinic/service/EntityUtils.java index 792972535..c4887d9e1 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/EntityUtils.java +++ b/src/test/java/org/springframework/samples/petclinic/service/EntityUtils.java @@ -16,6 +16,7 @@ package org.springframework.samples.petclinic.service; +import java.io.Serializable; import java.util.Collection; import org.springframework.orm.ObjectRetrievalFailureException; @@ -27,7 +28,6 @@ import org.springframework.samples.petclinic.model.BaseEntity; * * @author Juergen Hoeller * @author Sam Brannen - * @see org.springframework.samples.petclinic.model.BaseEntity * @since 29.10.2003 */ public abstract class EntityUtils {