1 | package clarin.cmdi.componentregistry.persistence.jpa; |
---|
2 | |
---|
3 | import java.util.List; |
---|
4 | |
---|
5 | import org.springframework.dao.DataAccessException; |
---|
6 | import org.springframework.data.jpa.repository.JpaRepository; |
---|
7 | import org.springframework.data.jpa.repository.Query; |
---|
8 | |
---|
9 | import clarin.cmdi.componentregistry.model.Comment; |
---|
10 | import clarin.cmdi.componentregistry.model.RegistryUser; |
---|
11 | |
---|
12 | /** |
---|
13 | * Interface for DAOs that handle comments |
---|
14 | * @author george.georgovassilis@mpi.nl |
---|
15 | * |
---|
16 | */ |
---|
17 | public interface CommentsDao extends JpaRepository<Comment, Long>{ |
---|
18 | |
---|
19 | /** |
---|
20 | * Get the list of all the comments available in the database The |
---|
21 | * distinction between profile or component is not treated in this method |
---|
22 | * |
---|
23 | * @return list of Comments |
---|
24 | */ |
---|
25 | @Query("select c from Comment c order by c.id") |
---|
26 | List<Comment> getAllComments(); |
---|
27 | |
---|
28 | /** |
---|
29 | * Retrieve the comments related to a certain component |
---|
30 | * |
---|
31 | * @param id |
---|
32 | * Database record id (fkey) |
---|
33 | * @return list of Comments |
---|
34 | * @throws DataAccessException |
---|
35 | */ |
---|
36 | @Query("select c from Comment c where c.componentId = ?1 order by c.commentDate, c.id") |
---|
37 | List<Comment> getCommentsFromComponent(String componentId) |
---|
38 | throws DataAccessException; |
---|
39 | |
---|
40 | /** |
---|
41 | * |
---|
42 | * @param id |
---|
43 | * Id of description record |
---|
44 | * @return Principal name of description's owner, if any. Otherwise, null. |
---|
45 | */ |
---|
46 | @Query("select user from RegistryUser user, Comment comment, BaseDescription component where comment.id = ?1 and comment.componentId = component.componentId and component.dbUserId = user.id") |
---|
47 | RegistryUser getOwnerOfComment(long id); |
---|
48 | |
---|
49 | /** |
---|
50 | * Method use for tests that will select comments based on the content |
---|
51 | * |
---|
52 | * @param aComment |
---|
53 | * @return list of Comments |
---|
54 | * @throws DataAccessException |
---|
55 | */ |
---|
56 | @Query("select c from Comment c where c.comments = ?1") |
---|
57 | Comment getByComment(String aComment) throws DataAccessException; |
---|
58 | |
---|
59 | /** |
---|
60 | * Get number of comments for component |
---|
61 | * |
---|
62 | * @param componentId |
---|
63 | * @return comment count |
---|
64 | */ |
---|
65 | @Query("select count(c) from Comment c where c.componentId = ?1") |
---|
66 | long findCommentCountForComponent(String componentId); |
---|
67 | |
---|
68 | /** |
---|
69 | * Get number of comments for components |
---|
70 | * |
---|
71 | * @param componentIds |
---|
72 | * @return list of (componentId,count) tuples |
---|
73 | */ |
---|
74 | @Query(nativeQuery=true, value = "select component_id, count(*) from comments where component_id in (?1) group by component_id") |
---|
75 | List<Object[]> findCommentCountForComponents(List<String> ids); |
---|
76 | } |
---|