1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.notes.dao.impl;
17
18 import java.util.List;
19
20 import javax.persistence.EntityManager;
21 import javax.persistence.PersistenceContext;
22 import javax.persistence.Query;
23
24 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
25 import org.kuali.rice.kew.notes.Attachment;
26 import org.kuali.rice.kew.notes.Note;
27 import org.kuali.rice.kew.notes.dao.NoteDAO;
28
29
30 public class NoteDAOJpaImpl implements NoteDAO {
31
32 @PersistenceContext(unitName="kew-unit")
33 EntityManager entityManager;
34
35 public Note getNoteByNoteId(String noteId) {
36 Query query = entityManager.createNamedQuery("KewNote.FindNoteByNoteId");
37 query.setParameter("noteId", noteId);
38 return (Note) query.getSingleResult();
39 }
40
41 public List getNotesByDocumentId(String documentId) {
42 Query query = entityManager.createNamedQuery("KewNote.FindNoteByDocumentId");
43 query.setParameter("documentId", documentId);
44 return (List) query.getResultList();
45 }
46
47 public void saveNote(Note note) {
48 if (note.getNoteId() == null){
49 entityManager.persist(note);
50 } else {
51 entityManager.merge(note);
52 }
53 }
54
55 public void deleteNote(Note note) {
56 Note n = getNoteByNoteId(note.getNoteId());
57 OrmUtils.merge(entityManager, n);
58 entityManager.remove(n);
59 }
60
61 public void deleteAttachment(Attachment attachment) {
62 Attachment a = findAttachment(attachment.getAttachmentId());
63 entityManager.remove(a);
64 }
65
66
67 public Attachment findAttachment(String attachmentId) {
68 Query query = entityManager.createNamedQuery("Attachment.FindAttachmentById");
69 query.setParameter("attachmentId", attachmentId);
70 return (Attachment)query.getSingleResult();
71 }
72
73 public EntityManager getEntityManager() {
74 return this.entityManager;
75 }
76
77 public void setEntityManager(EntityManager entityManager) {
78 this.entityManager = entityManager;
79 }
80
81 }