From c9e8d3b7fffc451ef86d8eb8b2737eb9bf0293e8 Mon Sep 17 00:00:00 2001 From: miferreiro Date: Mon, 18 Feb 2019 18:07:23 +0100 Subject: [PATCH] Fixed entity Changed the attribute breed by specie. In addition, there are changes in the script that has the lines to build the DB. --- db/mysql-with-inserts.sql | 13 +++---- db/mysql.sql | 4 +-- .../java/es/uvigo/esei/daa/entities/Pet.java | 36 +++++++++---------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/db/mysql-with-inserts.sql b/db/mysql-with-inserts.sql index 9444668..f488a88 100644 --- a/db/mysql-with-inserts.sql +++ b/db/mysql-with-inserts.sql @@ -15,14 +15,13 @@ CREATE TABLE `daaexample`.`users` ( PRIMARY KEY (`login`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `daaexample`.`pet` ( +CREATE TABLE `daaexample`.`pets` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, - `breed` varchar(50) NOT NULL, + `specie` varchar(50) NOT NULL, `idOwner` int NOT NULL, PRIMARY KEY (`id`), FOREIGN KEY (`idOwner`) REFERENCES `people`(`id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8; GRANT ALL ON `daaexample`.* TO 'daa'@'localhost' IDENTIFIED BY 'daa'; @@ -42,6 +41,8 @@ VALUES ('admin', '713bfda78870bf9d1b261f565286f85e97ee614efe5f0faf7c34e7ca4f65ba INSERT INTO `daaexample`.`users` (`login`,`password`,`role`) VALUES ('normal', '7bf24d6ca2242430343ab7e3efb89559a47784eea1123be989c1b2fb2ef66e83','USER'); -INSERT INTO `daaexample`.`pet` (`id`,`name`,`breed`,`idOwner`) VALUES (0,'Rex','Pastor Aleman',1); -INSERT INTO `daaexample`.`pet` (`id`,`name`,`breed`,`idOwner`) VALUES (0,'Idefix','Terrier',2); -INSERT INTO `daaexample`.`pet` (`id`,`name`,`breed`,`idOwner`) VALUES (0,'Snoopy','Beagle',3); \ No newline at end of file +INSERT INTO `daaexample`.`pets` (`id`,`name`,`specie`,`idOwner`) VALUES (0,'Rex','Dog',1); +INSERT INTO `daaexample`.`pets` (`id`,`name`,`specie`,`idOwner`) VALUES (0,'Doraemon','Cat',2); +INSERT INTO `daaexample`.`pets` (`id`,`name`,`specie`,`idOwner`) VALUES (0,'Yogui','Bear',3); +INSERT INTO `daaexample`.`pets` (`id`,`name`,`specie`,`idOwner`) VALUES (0,'Prueba1','pet',4); +INSERT INTO `daaexample`.`pets` (`id`,`name`,`specie`,`idOwner`) VALUES (0,'Prueba2','pet',5); \ No newline at end of file diff --git a/db/mysql.sql b/db/mysql.sql index c102607..4ef9671 100644 --- a/db/mysql.sql +++ b/db/mysql.sql @@ -15,10 +15,10 @@ CREATE TABLE `daaexample`.`users` ( PRIMARY KEY (`login`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `daaexample`.`pet` ( +CREATE TABLE `daaexample`.`pets` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, - `breed` varchar(50) NOT NULL, + `specie` varchar(50) NOT NULL, `idOwner` int NOT NULL, PRIMARY KEY (`id`), FOREIGN KEY (`idOwner`) REFERENCES `people`(`id`) diff --git a/src/main/java/es/uvigo/esei/daa/entities/Pet.java b/src/main/java/es/uvigo/esei/daa/entities/Pet.java index f806a68..7d27902 100644 --- a/src/main/java/es/uvigo/esei/daa/entities/Pet.java +++ b/src/main/java/es/uvigo/esei/daa/entities/Pet.java @@ -10,7 +10,7 @@ import static java.util.Objects.requireNonNull; public class Pet { private int id; private String name; - private String breed; + private String specie; private int idOwner; // Constructor needed for the JSON conversion @@ -21,13 +21,13 @@ public class Pet { * * @param id identifier of the pet. * @param name name of the pet. - * @param breed breed of the pet. + * @param specie specie of the pet. * @param idOwner owner of the pet */ - public Pet(int id, String name, String breed, int idOwner) { + public Pet(int id, String name, String specie, int idOwner) { this.id = id; this.setName(name); - this.setBreed(breed); + this.setSpecie(specie); this.setIdOwner(idOwner); } @@ -57,21 +57,21 @@ public class Pet { this.name = requireNonNull(name, "Name can't be null"); } /** - * Returns the breed of the pet. + * Returns the specie of the pet. * - * @return the breed of the pet. + * @return the specie of the pet. */ - public String getBreed() { - return breed; + public String getSpecie() { + return specie; } /** - * Set the breed of this pet. + * Set the specie of this pet. * - * @param breed the new breed of the person. - * @throws NullPointerException if the {@code breed} is {@code null}. + * @param specie the new specie of the pet. + * @throws NullPointerException if the {@code specie} is {@code null}. */ - public void setBreed(String breed) { - this.breed = requireNonNull(breed, "Name can't be null"); + public void setSpecie(String specie) { + this.specie = requireNonNull(specie, "specie can't be null"); } /** @@ -89,14 +89,14 @@ public class Pet { * @throws NullPointerException if the {@code idOwner} is {@code null}. */ public void setIdOwner(int idOwner) { - this.idOwner = requireNonNull(idOwner, "Name can't be null"); + this.idOwner = requireNonNull(idOwner, "idOwner can't be null"); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((breed == null) ? 0 : breed.hashCode()); + result = prime * result + ((specie == null) ? 0 : specie.hashCode()); result = prime * result + id; result = prime * result + idOwner; result = prime * result + ((name == null) ? 0 : name.hashCode()); @@ -112,10 +112,10 @@ public class Pet { if (getClass() != obj.getClass()) return false; Pet other = (Pet) obj; - if (breed == null) { - if (other.breed != null) + if (specie == null) { + if (other.specie != null) return false; - } else if (!breed.equals(other.breed)) + } else if (!specie.equals(other.specie)) return false; if (id != other.id) return false; -- 2.18.1