-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathImageContributionEventDaoJpa.java
More file actions
52 lines (45 loc) · 1.84 KB
/
ImageContributionEventDaoJpa.java
File metadata and controls
52 lines (45 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package ai.elimu.dao.jpa;
import ai.elimu.model.contributor.ImageContributionEvent;
import ai.elimu.dao.ImageContributionEventDao;
import ai.elimu.model.content.multimedia.Image;
import ai.elimu.model.contributor.Contributor;
import java.util.List;
import org.springframework.dao.DataAccessException;
public class ImageContributionEventDaoJpa extends GenericDaoJpa<ImageContributionEvent> implements ImageContributionEventDao {
@Override
public List<ImageContributionEvent> readAll(Image image) throws DataAccessException {
return em.createQuery(
"SELECT ice " +
"FROM ImageContributionEvent ice " +
"WHERE ice.image = :image " +
"ORDER BY ice.time DESC")
.setParameter("image", image)
.getResultList();
}
@Override
public List<ImageContributionEvent> readAll(Contributor contributor) throws DataAccessException {
return em.createQuery(
"SELECT ice " +
"FROM ImageContributionEvent ice " +
"WHERE ice.contributor = :contributor " +
"ORDER BY ice.time DESC")
.setParameter("contributor", contributor)
.getResultList();
}
@Override
public Long readCount(Contributor contributor) throws DataAccessException {
return (Long) em.createQuery("SELECT COUNT(ice) " +
"FROM ImageContributionEvent ice " +
"WHERE ice.contributor = :contributor")
.setParameter("contributor", contributor)
.getSingleResult();
}
@Override
public void deleteAllEventsForImage(Image image) {
em.createQuery("DELETE " +
"FROM ImageContributionEvent ice " +
"WHERE ice.image = :image")
.setParameter("image", image)
.executeUpdate();
}
}