Commit e345b8eb authored by miferreiro's avatar miferreiro

Renaming the class and adding exception in the getPets () function

parent b851bc66
...@@ -18,8 +18,8 @@ import es.uvigo.esei.daa.entities.Pet; ...@@ -18,8 +18,8 @@ import es.uvigo.esei.daa.entities.Pet;
* *
* @author Miguel Ferreiro Diaz * @author Miguel Ferreiro Diaz
*/ */
public class PetDAO extends DAO { public class PetsDAO extends DAO {
private final static Logger LOG = Logger.getLogger(PetDAO.class.getName()); private final static Logger LOG = Logger.getLogger(PetsDAO.class.getName());
/** /**
* Returns a person stored persisted in the system. * Returns a person stored persisted in the system.
...@@ -96,10 +96,6 @@ public class PetDAO extends DAO { ...@@ -96,10 +96,6 @@ public class PetDAO extends DAO {
throw new IllegalArgumentException("name and specie can't be null " + specie); throw new IllegalArgumentException("name and specie can't be null " + specie);
} }
if ( idOwner <= 0) {
throw new IllegalArgumentException("idOwner can't be negative");
}
try (Connection conn = this.getConnection()) { try (Connection conn = this.getConnection()) {
final String query = "INSERT INTO pets VALUES(null, ?, ?,?)"; final String query = "INSERT INTO pets VALUES(null, ?, ?,?)";
...@@ -198,8 +194,13 @@ public class PetDAO extends DAO { ...@@ -198,8 +194,13 @@ public class PetDAO extends DAO {
* @throws IllegalArgumentException if the provided id does not corresponds * @throws IllegalArgumentException if the provided id does not corresponds
* with any persisted person. * with any persisted person.
*/ */
public List<Pet> getPets(int id) public List<Pet> getPets(int idOwner)
throws DAOException, IllegalArgumentException { throws DAOException, IllegalArgumentException {
if ( idOwner <= 0) {
throw new IllegalArgumentException("idOwner can't be negative");
}
try (final Connection conn = this.getConnection()) { try (final Connection conn = this.getConnection()) {
final String query = "SELECT T.id, T.name, T.specie, T.idOwner " final String query = "SELECT T.id, T.name, T.specie, T.idOwner "
+ "FROM people P, pets T " + "FROM people P, pets T "
...@@ -207,7 +208,7 @@ public class PetDAO extends DAO { ...@@ -207,7 +208,7 @@ public class PetDAO extends DAO {
try (final PreparedStatement statement = conn.prepareStatement(query)) { try (final PreparedStatement statement = conn.prepareStatement(query)) {
statement.setInt(1, id); statement.setInt(1, idOwner);
try (final ResultSet result = statement.executeQuery()) { try (final ResultSet result = statement.executeQuery()) {
......
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