1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.comment.dao.impl; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
import javax.persistence.EntityManager; |
21 | |
import javax.persistence.NoResultException; |
22 | |
import javax.persistence.PersistenceContext; |
23 | |
import javax.persistence.Query; |
24 | |
|
25 | |
import org.kuali.student.common.dao.impl.AbstractSearchableCrudDaoImpl; |
26 | |
import org.kuali.student.core.comment.dao.CommentDao; |
27 | |
import org.kuali.student.core.comment.entity.Comment; |
28 | |
import org.kuali.student.core.comment.entity.CommentType; |
29 | |
import org.kuali.student.core.comment.entity.Reference; |
30 | |
import org.kuali.student.core.comment.entity.Tag; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 1 | public class CommentDaoImpl extends AbstractSearchableCrudDaoImpl implements CommentDao { |
39 | |
@PersistenceContext(unitName = "Comment") |
40 | |
@Override |
41 | |
public void setEm(EntityManager em) { |
42 | 0 | super.setEm(em); |
43 | 0 | } |
44 | |
|
45 | |
|
46 | |
public Comment getComment(String referenceId, String referenceTypeKey){ |
47 | 0 | Query query = em.createNamedQuery("Comment.getComment"); |
48 | 0 | query.setParameter("refId", referenceId); |
49 | 0 | query.setParameter("refTypeId", referenceTypeKey); |
50 | 0 | Comment comment = (Comment) query.getSingleResult(); |
51 | 0 | return comment; |
52 | |
|
53 | |
} |
54 | |
|
55 | |
public List<Comment> getComments(String referenceId, String referenceTypeKey){ |
56 | 0 | Query query = em.createNamedQuery("Comment.getComments"); |
57 | 0 | query.setParameter("refId", referenceId); |
58 | 0 | query.setParameter("refTypeId", referenceTypeKey); |
59 | |
@SuppressWarnings("unchecked") |
60 | 0 | List<Comment> comments = query.getResultList(); |
61 | 0 | return comments; |
62 | |
} |
63 | |
|
64 | |
public List<Comment> getCommentsByRefId(String referenceId){ |
65 | 0 | Query query = em.createNamedQuery("Comment.getCommentsByRefId"); |
66 | 0 | query.setParameter("refId", referenceId); |
67 | |
@SuppressWarnings("unchecked") |
68 | 0 | List<Comment> comments = query.getResultList(); |
69 | 0 | return comments; |
70 | |
} |
71 | |
|
72 | |
public List<Comment> getCommentsByType(String referenceId, String referenceTypeKey, String commentTypeKey ){ |
73 | 0 | Query query = em.createNamedQuery("Comment.getCommentsByType"); |
74 | 0 | query.setParameter("refId", referenceId); |
75 | 0 | query.setParameter("refTypeId", referenceTypeKey); |
76 | 0 | query.setParameter("commentTypeId", commentTypeKey); |
77 | |
@SuppressWarnings("unchecked") |
78 | 0 | List<Comment> comments = query.getResultList(); |
79 | 0 | return comments; |
80 | |
} |
81 | |
|
82 | |
public List<CommentType> getCommentTypesByReferenceTypeId(String referenceTypeId) { |
83 | 0 | Query query = em.createNamedQuery("CommentType.getCommentTypesByReferenceTypeId"); |
84 | 0 | query.setParameter("referenceTypeId", referenceTypeId); |
85 | |
@SuppressWarnings("unchecked") |
86 | 0 | List<CommentType> comments = query.getResultList(); |
87 | 0 | return comments; |
88 | |
|
89 | |
} |
90 | |
|
91 | |
public Tag getTag(String referenceId, String referenceTypeKey){ |
92 | 0 | Query query = em.createNamedQuery("Tag.getTag"); |
93 | 0 | query.setParameter("refId", referenceId); |
94 | 0 | query.setParameter("refTypeId", referenceTypeKey); |
95 | 0 | Tag tag = (Tag)query.getSingleResult(); |
96 | 0 | return tag; |
97 | |
} |
98 | |
public List<Tag> getTags(String referenceId, String referenceTypeKey){ |
99 | 0 | Query query = em.createNamedQuery("Tag.getTags"); |
100 | 0 | query.setParameter("refId", referenceId); |
101 | 0 | query.setParameter("refTypeId", referenceTypeKey); |
102 | |
@SuppressWarnings("unchecked") |
103 | 0 | List<Tag> tags = query.getResultList(); |
104 | 0 | return tags; |
105 | |
} |
106 | |
|
107 | |
public List<Tag> getTagsByRefId(String referenceId){ |
108 | 0 | Query query = em.createNamedQuery("Tag.getTagsByRefId"); |
109 | 0 | query.setParameter("refId", referenceId); |
110 | |
@SuppressWarnings("unchecked") |
111 | 0 | List<Tag> tags = query.getResultList(); |
112 | 0 | return tags; |
113 | |
} |
114 | |
|
115 | |
public List<Tag> getTagsByType(String referenceId, String referenceTypeKey, String tagTypeKey ){ |
116 | 0 | Query query = em.createNamedQuery("Tag.getTagsByType"); |
117 | 0 | query.setParameter("refId", referenceId); |
118 | 0 | query.setParameter("refTypeId", referenceTypeKey); |
119 | 0 | query.setParameter("tagTypeId", tagTypeKey); |
120 | |
@SuppressWarnings("unchecked") |
121 | 0 | List<Tag> tags = query.getResultList(); |
122 | 0 | return tags; |
123 | |
} |
124 | |
|
125 | |
public Reference getReference(String referenceId, String referenceType){ |
126 | 0 | Query query = em.createNamedQuery("Reference.getReference"); |
127 | 0 | query.setParameter("refId", referenceId); |
128 | 0 | query.setParameter("refTypeId", referenceType); |
129 | |
try{ |
130 | 0 | Reference reference = (Reference)query.getSingleResult(); |
131 | 0 | return reference; |
132 | |
} |
133 | 0 | catch(NoResultException e){ |
134 | 0 | return null; |
135 | |
} |
136 | |
|
137 | |
|
138 | |
} |
139 | |
|
140 | |
|
141 | |
} |