Commit c9e8d3b7 authored by miferreiro's avatar miferreiro

Fixed entity

Changed the attribute breed by specie.
In addition, there are changes in the script that has the lines to build the DB.
parent 0ae8f660
...@@ -15,14 +15,13 @@ CREATE TABLE `daaexample`.`users` ( ...@@ -15,14 +15,13 @@ CREATE TABLE `daaexample`.`users` (
PRIMARY KEY (`login`) PRIMARY KEY (`login`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `daaexample`.`pet` ( CREATE TABLE `daaexample`.`pets` (
`id` int NOT NULL AUTO_INCREMENT, `id` int NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL, `name` varchar(50) NOT NULL,
`breed` varchar(50) NOT NULL, `specie` varchar(50) NOT NULL,
`idOwner` int NOT NULL, `idOwner` int NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
FOREIGN KEY (`idOwner`) REFERENCES `people`(`id`) FOREIGN KEY (`idOwner`) REFERENCES `people`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
GRANT ALL ON `daaexample`.* TO 'daa'@'localhost' IDENTIFIED BY 'daa'; GRANT ALL ON `daaexample`.* TO 'daa'@'localhost' IDENTIFIED BY 'daa';
...@@ -42,6 +41,8 @@ VALUES ('admin', '713bfda78870bf9d1b261f565286f85e97ee614efe5f0faf7c34e7ca4f65ba ...@@ -42,6 +41,8 @@ VALUES ('admin', '713bfda78870bf9d1b261f565286f85e97ee614efe5f0faf7c34e7ca4f65ba
INSERT INTO `daaexample`.`users` (`login`,`password`,`role`) INSERT INTO `daaexample`.`users` (`login`,`password`,`role`)
VALUES ('normal', '7bf24d6ca2242430343ab7e3efb89559a47784eea1123be989c1b2fb2ef66e83','USER'); VALUES ('normal', '7bf24d6ca2242430343ab7e3efb89559a47784eea1123be989c1b2fb2ef66e83','USER');
INSERT INTO `daaexample`.`pet` (`id`,`name`,`breed`,`idOwner`) VALUES (0,'Rex','Pastor Aleman',1); INSERT INTO `daaexample`.`pets` (`id`,`name`,`specie`,`idOwner`) VALUES (0,'Rex','Dog',1);
INSERT INTO `daaexample`.`pet` (`id`,`name`,`breed`,`idOwner`) VALUES (0,'Idefix','Terrier',2); INSERT INTO `daaexample`.`pets` (`id`,`name`,`specie`,`idOwner`) VALUES (0,'Doraemon','Cat',2);
INSERT INTO `daaexample`.`pet` (`id`,`name`,`breed`,`idOwner`) VALUES (0,'Snoopy','Beagle',3); INSERT INTO `daaexample`.`pets` (`id`,`name`,`specie`,`idOwner`) VALUES (0,'Yogui','Bear',3);
\ No newline at end of file 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
...@@ -15,10 +15,10 @@ CREATE TABLE `daaexample`.`users` ( ...@@ -15,10 +15,10 @@ CREATE TABLE `daaexample`.`users` (
PRIMARY KEY (`login`) PRIMARY KEY (`login`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `daaexample`.`pet` ( CREATE TABLE `daaexample`.`pets` (
`id` int NOT NULL AUTO_INCREMENT, `id` int NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL, `name` varchar(50) NOT NULL,
`breed` varchar(50) NOT NULL, `specie` varchar(50) NOT NULL,
`idOwner` int NOT NULL, `idOwner` int NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
FOREIGN KEY (`idOwner`) REFERENCES `people`(`id`) FOREIGN KEY (`idOwner`) REFERENCES `people`(`id`)
......
...@@ -10,7 +10,7 @@ import static java.util.Objects.requireNonNull; ...@@ -10,7 +10,7 @@ import static java.util.Objects.requireNonNull;
public class Pet { public class Pet {
private int id; private int id;
private String name; private String name;
private String breed; private String specie;
private int idOwner; private int idOwner;
// Constructor needed for the JSON conversion // Constructor needed for the JSON conversion
...@@ -21,13 +21,13 @@ public class Pet { ...@@ -21,13 +21,13 @@ public class Pet {
* *
* @param id identifier of the pet. * @param id identifier of the pet.
* @param name name 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 * @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.id = id;
this.setName(name); this.setName(name);
this.setBreed(breed); this.setSpecie(specie);
this.setIdOwner(idOwner); this.setIdOwner(idOwner);
} }
...@@ -57,21 +57,21 @@ public class Pet { ...@@ -57,21 +57,21 @@ public class Pet {
this.name = requireNonNull(name, "Name can't be null"); 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() { public String getSpecie() {
return breed; return specie;
} }
/** /**
* Set the breed of this pet. * Set the specie of this pet.
* *
* @param breed the new breed of the person. * @param specie the new specie of the pet.
* @throws NullPointerException if the {@code breed} is {@code null}. * @throws NullPointerException if the {@code specie} is {@code null}.
*/ */
public void setBreed(String breed) { public void setSpecie(String specie) {
this.breed = requireNonNull(breed, "Name can't be null"); this.specie = requireNonNull(specie, "specie can't be null");
} }
/** /**
...@@ -89,14 +89,14 @@ public class Pet { ...@@ -89,14 +89,14 @@ public class Pet {
* @throws NullPointerException if the {@code idOwner} is {@code null}. * @throws NullPointerException if the {@code idOwner} is {@code null}.
*/ */
public void setIdOwner(int idOwner) { public void setIdOwner(int idOwner) {
this.idOwner = requireNonNull(idOwner, "Name can't be null"); this.idOwner = requireNonNull(idOwner, "idOwner can't be null");
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; 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 + id;
result = prime * result + idOwner; result = prime * result + idOwner;
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
...@@ -112,10 +112,10 @@ public class Pet { ...@@ -112,10 +112,10 @@ public class Pet {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
Pet other = (Pet) obj; Pet other = (Pet) obj;
if (breed == null) { if (specie == null) {
if (other.breed != null) if (other.specie != null)
return false; return false;
} else if (!breed.equals(other.breed)) } else if (!specie.equals(other.specie))
return false; return false;
if (id != other.id) if (id != other.id)
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment