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 | 0 | public class NoteDAOJpaImpl implements NoteDAO { |
31 | |
|
32 | |
@PersistenceContext(unitName="kew-unit") |
33 | |
EntityManager entityManager; |
34 | |
|
35 | |
public Note getNoteByNoteId(String noteId) { |
36 | 0 | Query query = entityManager.createNamedQuery("KewNote.FindNoteByNoteId"); |
37 | 0 | query.setParameter("noteId", noteId); |
38 | 0 | return (Note) query.getSingleResult(); |
39 | |
} |
40 | |
|
41 | |
public List getNotesByDocumentId(String documentId) { |
42 | 0 | Query query = entityManager.createNamedQuery("KewNote.FindNoteByDocumentId"); |
43 | 0 | query.setParameter("documentId", documentId); |
44 | 0 | return (List) query.getResultList(); |
45 | |
} |
46 | |
|
47 | |
public void saveNote(Note note) { |
48 | 0 | if (note.getNoteId() == null){ |
49 | 0 | entityManager.persist(note); |
50 | |
} else { |
51 | 0 | entityManager.merge(note); |
52 | |
} |
53 | 0 | } |
54 | |
|
55 | |
public void deleteNote(Note note) { |
56 | 0 | Note n = getNoteByNoteId(note.getNoteId()); |
57 | 0 | OrmUtils.merge(entityManager, n); |
58 | 0 | entityManager.remove(n); |
59 | 0 | } |
60 | |
|
61 | |
public void deleteAttachment(Attachment attachment) { |
62 | 0 | Attachment a = findAttachment(attachment.getAttachmentId()); |
63 | 0 | entityManager.remove(a); |
64 | 0 | } |
65 | |
|
66 | |
|
67 | |
public Attachment findAttachment(String attachmentId) { |
68 | 0 | Query query = entityManager.createNamedQuery("Attachment.FindAttachmentById"); |
69 | 0 | query.setParameter("attachmentId", attachmentId); |
70 | 0 | return (Attachment)query.getSingleResult(); |
71 | |
} |
72 | |
|
73 | |
public EntityManager getEntityManager() { |
74 | 0 | return this.entityManager; |
75 | |
} |
76 | |
|
77 | |
public void setEntityManager(EntityManager entityManager) { |
78 | 0 | this.entityManager = entityManager; |
79 | 0 | } |
80 | |
|
81 | |
} |