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