source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/persistence/jpa/CommentsDao.java @ 4098

Last change on this file since 4098 was 4098, checked in by George.Georgovassilis@mpi.nl, 10 years ago

#360, #431, #432: JPA and unified component entities

  • Property svn:mime-type set to text/plain
File size: 2.4 KB
Line 
1package clarin.cmdi.componentregistry.persistence.jpa;
2
3import java.util.List;
4
5import org.springframework.dao.DataAccessException;
6import org.springframework.data.jpa.repository.JpaRepository;
7import org.springframework.data.jpa.repository.Query;
8
9import clarin.cmdi.componentregistry.model.Comment;
10import clarin.cmdi.componentregistry.model.RegistryUser;
11
12/**
13 * Interface for DAOs that handle comments
14 * @author george.georgovassilis@mpi.nl
15 *
16 */
17public 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}
Note: See TracBrowser for help on using the repository browser.