Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Team 14 - IDATT1002
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eirik Steira
Team 14 - IDATT1002
Commits
65907ba6
Commit
65907ba6
authored
5 years ago
by
Lars Brodin Østby
Browse files
Options
Downloads
Patches
Plain Diff
Image repositroy abstract class update
parent
64406b3a
No related branches found
No related tags found
1 merge request
!30
Weekly merge to master
Pipeline
#76023
passed
5 years ago
Stage: build
Stage: test
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/NTNU/IDATT1002/repository/ImageRepository.java
+4
-94
4 additions, 94 deletions
src/main/java/NTNU/IDATT1002/repository/ImageRepository.java
with
4 additions
and
94 deletions
src/main/java/NTNU/IDATT1002/repository/ImageRepository.java
+
4
−
94
View file @
65907ba6
...
...
@@ -16,49 +16,19 @@ import java.util.List;
* @see NTNU.IDATT1002.repository.Repository
*/
public
class
ImageRepository
implem
en
t
s
Repository
<
Image
,
Long
>
{
public
class
ImageRepository
ext
en
d
s
Generic
Repository
<
Image
,
Long
>
{
private
EntityManager
entityManager
;
/**
* Constructor to inject {@link EntityManager} dependency.
*
* @param entityManager the entity manager to utilize
.
* @param entityManager the entity manager to utilize
*/
public
ImageRepository
(
EntityManager
entityManager
)
{
this
.
entityManager
=
entityManager
;
super
(
entityManager
)
;
}
/**
* Saves a given image and returns the saved instance.
*
* @param image the image album to save
* @return the saved image
*/
public
Optional
<
Image
>
save
(
Image
image
)
{
try
{
persist
(
image
);
return
Optional
.
of
(
image
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
Optional
.
empty
();
}
/**
* Persists the given image
*
* @param image the image to persist
*/
private
void
persist
(
Image
image
)
{
entityManager
.
getTransaction
().
begin
();
entityManager
.
persist
(
image
);
entityManager
.
getTransaction
().
commit
();
}
/**
* Retrieves all instances of the type image.
...
...
@@ -69,66 +39,6 @@ public class ImageRepository implements Repository<Image, Long> {
return
Optional
.
empty
();
}
/**
* Retrieves all instances of type image.
*
* @return all saved image
*/
public
List
<
Image
>
findAll
()
{
return
entityManager
.
createQuery
(
"from Image"
).
getResultList
();
}
/**
* Retrieves an image with the given id.
*
* @param id the if of the image to find
* @return the entity with the given id if found, else Optional.empty()
*/
public
Optional
<
Image
>
findById
(
Long
id
)
{
Image
image
=
entityManager
.
find
(
Image
.
class
,
id
);
return
image
!=
null
?
Optional
.
of
(
image
)
:
Optional
.
empty
();
}
/**
* Deletes the given image
*
* @param image the image to delete
*/
public
void
delete
(
Image
image
)
{
try
{
entityManager
.
getTransaction
().
begin
();
entityManager
.
remove
(
image
);
entityManager
.
getTransaction
().
commit
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/**
* Deletes an image with the given id.
*
* @param id the id of the image to delete
*/
public
void
deleteById
(
Long
id
)
{
Optional
<
Image
>
image
=
findById
(
id
);
image
.
ifPresent
(
this
::
delete
);
}
/**
* Return the number of images
*
* @return the number of images
*/
public
long
count
()
{
return
findAll
().
size
();
}
/**
* Return whether the given image exists.
...
...
@@ -137,7 +47,7 @@ public class ImageRepository implements Repository<Image, Long> {
* @return true if the image album exist, else false
*/
@Override
public
boolean
exists
(
Image
image
)
{
return
findById
(
image
.
getImageID
()).
isPresent
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment