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
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Martín Vázquez Torres
daaexample
Commits
ba522393
Commit
ba522393
authored
Feb 20, 2017
by
cyanide4all
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working as intended, finally
parent
1a64cd50
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
30 deletions
+20
-30
PetDAO.java
src/main/java/es/uvigo/esei/daa/dao/PetDAO.java
+10
-18
PetResource.java
src/main/java/es/uvigo/esei/daa/rest/PetResource.java
+1
-1
pet.js
src/main/webapp/js/dao/pet.js
+5
-8
pet.js
src/main/webapp/js/view/pet.js
+3
-2
pet.html
src/main/webapp/pet.html
+1
-1
No files found.
src/main/java/es/uvigo/esei/daa/dao/PetDAO.java
View file @
ba522393
...
@@ -20,30 +20,21 @@ import es.uvigo.esei.daa.entities.Pet;
...
@@ -20,30 +20,21 @@ import es.uvigo.esei.daa.entities.Pet;
*/
*/
public
class
PetDAO
extends
DAO
{
public
class
PetDAO
extends
DAO
{
private
final
static
Logger
LOG
=
Logger
.
getLogger
(
PetDAO
.
class
.
getName
());
private
final
static
Logger
LOG
=
Logger
.
getLogger
(
PetDAO
.
class
.
getName
());
//TODO está puesto a 1 para testeos
private
int
ownerID
=
1
;
public
int
getOwnerID
(){
return
ownerID
;
}
public
void
setOwnerID
(
int
ownerID
)
{
this
.
ownerID
=
ownerID
;}
public
PetDAO
(
int
ownerID
)
{
this
.
ownerID
=
ownerID
;
}
public
PetDAO
(){}
public
PetDAO
(){}
/**
/**
* Returns a pet stored persisted in the system.
* Returns a pet stored persisted in the system.
*
*
*
* @param ownerID necessary for the rowToEntity method
* @param id identifier of the pet.
* @param id identifier of the pet.
* @return a pet with the provided identifier.
* @return a pet with the provided identifier.
* @throws DAOException if an error happens while retrieving the pet.
* @throws DAOException if an error happens while retrieving the pet.
* @throws IllegalArgumentException if the provided id does not corresponds
* @throws IllegalArgumentException if the provided id does not corresponds
* with any persisted pet.
* with any persisted pet.
*/
*/
public
Pet
get
(
int
id
)
public
Pet
get
(
int
ownerID
,
int
id
)
throws
DAOException
,
IllegalArgumentException
{
throws
DAOException
,
IllegalArgumentException
{
try
(
final
Connection
conn
=
this
.
getConnection
())
{
try
(
final
Connection
conn
=
this
.
getConnection
())
{
final
String
query
=
"SELECT * FROM pet WHERE id=?"
;
final
String
query
=
"SELECT * FROM pet WHERE id=?"
;
...
@@ -53,7 +44,7 @@ public class PetDAO extends DAO {
...
@@ -53,7 +44,7 @@ public class PetDAO extends DAO {
try
(
final
ResultSet
result
=
statement
.
executeQuery
())
{
try
(
final
ResultSet
result
=
statement
.
executeQuery
())
{
if
(
result
.
next
())
{
if
(
result
.
next
())
{
return
rowToEntity
(
result
);
return
rowToEntity
(
ownerID
,
result
);
}
else
{
}
else
{
throw
new
IllegalArgumentException
(
"Invalid id"
);
throw
new
IllegalArgumentException
(
"Invalid id"
);
}
}
...
@@ -67,11 +58,11 @@ public class PetDAO extends DAO {
...
@@ -67,11 +58,11 @@ public class PetDAO extends DAO {
/**
/**
* Returns a list with all the pets persisted in the system.
* Returns a list with all the pets persisted in the system.
*
*
@param ownerID id of the owner of the pets to list
* @return a list with all the pet persisted in the system.
* @return a list with all the pet persisted in the system.
* @throws DAOException if an error happens while retrieving the pets.
* @throws DAOException if an error happens while retrieving the pets.
*/
*/
public
List
<
Pet
>
list
()
throws
DAOException
{
public
List
<
Pet
>
list
(
int
ownerID
)
throws
DAOException
{
try
(
final
Connection
conn
=
this
.
getConnection
())
{
try
(
final
Connection
conn
=
this
.
getConnection
())
{
final
String
query
=
"SELECT * FROM pet WHERE ownerID=?"
;
final
String
query
=
"SELECT * FROM pet WHERE ownerID=?"
;
...
@@ -82,7 +73,7 @@ public class PetDAO extends DAO {
...
@@ -82,7 +73,7 @@ public class PetDAO extends DAO {
final
List
<
Pet
>
petList
=
new
LinkedList
<>();
final
List
<
Pet
>
petList
=
new
LinkedList
<>();
while
(
result
.
next
())
{
while
(
result
.
next
())
{
petList
.
add
(
rowToEntity
(
result
));
petList
.
add
(
rowToEntity
(
ownerID
,
result
));
}
}
return
petList
;
return
petList
;
...
@@ -98,12 +89,13 @@ public class PetDAO extends DAO {
...
@@ -98,12 +89,13 @@ public class PetDAO extends DAO {
* Persists a new pet in the system. An identifier will be assigned
* Persists a new pet in the system. An identifier will be assigned
* automatically to the new pet.
* automatically to the new pet.
*
*
* @param ownerID id of the owner of the pet.
* @param name name of the new pet. Can't be {@code null}.
* @param name name of the new pet. Can't be {@code null}.
* @return a {@link Pet} entity representing the persisted pet.
* @return a {@link Pet} entity representing the persisted pet.
* @throws DAOException if an error happens while persisting the new pet.
* @throws DAOException if an error happens while persisting the new pet.
* @throws IllegalArgumentException if the name is {@code null}.
* @throws IllegalArgumentException if the name is {@code null}.
*/
*/
public
Pet
add
(
String
name
)
public
Pet
add
(
int
ownerID
,
String
name
)
throws
DAOException
,
IllegalArgumentException
{
throws
DAOException
,
IllegalArgumentException
{
if
(
name
==
null
)
{
if
(
name
==
null
)
{
throw
new
IllegalArgumentException
(
"name can't be null"
);
throw
new
IllegalArgumentException
(
"name can't be null"
);
...
@@ -194,7 +186,7 @@ public class PetDAO extends DAO {
...
@@ -194,7 +186,7 @@ public class PetDAO extends DAO {
}
}
}
}
private
Pet
rowToEntity
(
ResultSet
row
)
throws
SQLException
{
private
Pet
rowToEntity
(
int
ownerID
,
ResultSet
row
)
throws
SQLException
{
return
new
Pet
(
return
new
Pet
(
row
.
getInt
(
"id"
),
row
.
getInt
(
"id"
),
row
.
getString
(
"name"
),
row
.
getString
(
"name"
),
...
...
src/main/java/es/uvigo/esei/daa/rest/PetResource.java
View file @
ba522393
This diff is collapsed.
Click to expand it.
src/main/webapp/js/dao/pet.js
View file @
ba522393
...
@@ -12,6 +12,11 @@ var PetDAO = (function() {
...
@@ -12,6 +12,11 @@ var PetDAO = (function() {
};
};
function
PetDAO
()
{
function
PetDAO
()
{
//This method serves as initialization for the resourcePath var fot the current webpage
this
.
addToResourcePath
=
function
(
ownerID
)
{
resourcePath
=
resourcePath
+
ownerID
+
"/"
;
}
this
.
listPets
=
function
(
done
,
fail
,
always
)
{
this
.
listPets
=
function
(
done
,
fail
,
always
)
{
requestByAjax
({
requestByAjax
({
url
:
resourcePath
,
url
:
resourcePath
,
...
@@ -19,14 +24,6 @@ var PetDAO = (function() {
...
@@ -19,14 +24,6 @@ var PetDAO = (function() {
},
done
,
fail
,
always
);
},
done
,
fail
,
always
);
};
};
this
.
setOwnerIDPetDAO
=
function
(
ownerID
,
done
,
fail
,
always
)
{
requestByAjax
({
url
:
resourcePath
+
ownerID
,
type
:
'POST'
,
data
:
ownerID
},
done
,
fail
,
always
);
};
this
.
addPet
=
function
(
pet
,
done
,
fail
,
always
)
{
this
.
addPet
=
function
(
pet
,
done
,
fail
,
always
)
{
requestByAjax
({
requestByAjax
({
url
:
resourcePath
,
url
:
resourcePath
,
...
...
src/main/webapp/js/view/pet.js
View file @
ba522393
...
@@ -21,8 +21,9 @@ var PetView = (function() {
...
@@ -21,8 +21,9 @@ var PetView = (function() {
dao
=
petDao
;
dao
=
petDao
;
self
=
this
;
self
=
this
;
dao
.
setOwnerIDPetDAO
(
getQueryParameter
(
'id'
));
//This has to be executed prior to everything for the correct execution of every other method in dao
dao
.
addToResourcePath
(
getQueryParameter
(
"id"
));
insertPetForm
(
$
(
'#'
+
formContainerId
));
insertPetForm
(
$
(
'#'
+
formContainerId
));
insertPetList
(
$
(
'#'
+
listContainerId
));
insertPetList
(
$
(
'#'
+
listContainerId
));
...
...
src/main/webapp/pet.html
View file @
ba522393
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
</head>
</head>
<body>
<body>
<div
id=
"pet-container"
>
<div
id=
"pet-container"
>
<h1>
Pe
ople
</h1>
<h1>
Pe
ts
</h1>
<a
id=
"#logout"
href=
"logout"
>
Logout
</a>
<a
id=
"#atras"
href=
"main.html"
>
Back
</a>
<a
id=
"#logout"
href=
"logout"
>
Logout
</a>
<a
id=
"#atras"
href=
"main.html"
>
Back
</a>
</div>
</div>
...
...
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