Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
DAAExample
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Miguel Ferreiro Díaz
DAAExample
Commits
e345b8eb
Commit
e345b8eb
authored
Feb 21, 2019
by
miferreiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renaming the class and adding exception in the getPets () function
parent
b851bc66
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
10 deletions
+11
-10
PetsDAO.java
src/main/java/es/uvigo/esei/daa/dao/PetsDAO.java
+11
-10
No files found.
src/main/java/es/uvigo/esei/daa/dao/PetDAO.java
→
src/main/java/es/uvigo/esei/daa/dao/Pet
s
DAO.java
View file @
e345b8eb
...
...
@@ -18,8 +18,8 @@ import es.uvigo.esei.daa.entities.Pet;
*
* @author Miguel Ferreiro Diaz
*/
public
class
PetDAO
extends
DAO
{
private
final
static
Logger
LOG
=
Logger
.
getLogger
(
PetDAO
.
class
.
getName
());
public
class
Pet
s
DAO
extends
DAO
{
private
final
static
Logger
LOG
=
Logger
.
getLogger
(
Pet
s
DAO
.
class
.
getName
());
/**
* Returns a person stored persisted in the system.
...
...
@@ -95,11 +95,7 @@ public class PetDAO extends DAO {
if
(
name
==
null
||
specie
==
null
)
{
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
())
{
final
String
query
=
"INSERT INTO pets VALUES(null, ?, ?,?)"
;
...
...
@@ -198,8 +194,13 @@ public class PetDAO extends DAO {
* @throws IllegalArgumentException if the provided id does not corresponds
* with any persisted person.
*/
public
List
<
Pet
>
getPets
(
int
id
)
public
List
<
Pet
>
getPets
(
int
id
Owner
)
throws
DAOException
,
IllegalArgumentException
{
if
(
idOwner
<=
0
)
{
throw
new
IllegalArgumentException
(
"idOwner can't be negative"
);
}
try
(
final
Connection
conn
=
this
.
getConnection
())
{
final
String
query
=
"SELECT T.id, T.name, T.specie, T.idOwner "
+
"FROM people P, pets T "
...
...
@@ -207,8 +208,8 @@ public class PetDAO extends DAO {
try
(
final
PreparedStatement
statement
=
conn
.
prepareStatement
(
query
))
{
statement
.
setInt
(
1
,
id
);
statement
.
setInt
(
1
,
id
Owner
);
try
(
final
ResultSet
result
=
statement
.
executeQuery
())
{
final
List
<
Pet
>
pets
=
new
LinkedList
<>();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment