1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.dao.impl;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import javax.persistence.EntityManager;
22 import javax.persistence.PersistenceContext;
23
24 import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
25 import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria;
26 import org.kuali.rice.krad.bo.Attachment;
27 import org.kuali.rice.krad.bo.Note;
28 import org.kuali.rice.krad.dao.NoteDao;
29 import org.springframework.dao.DataAccessException;
30
31
32
33
34
35
36 public class NoteDaoJpa implements NoteDao {
37
38 @PersistenceContext
39 private EntityManager entityManager;
40
41
42
43
44 public void save(Note note) throws DataAccessException {
45 if (note != null && note.getNoteIdentifier() == null && note.getAttachment() != null) {
46 Attachment attachment = note.getAttachment();
47 note.setAttachment(null);
48
49 entityManager.merge(note);
50 attachment.setNoteIdentifier(note.getNoteIdentifier());
51
52 note.setAttachment(attachment);
53 }
54 entityManager.merge(note);
55
56 }
57
58
59
60
61 public void deleteNote(Note note) throws DataAccessException {
62 entityManager.remove(note.getAttachment());
63 note.setAttachment(null);
64 entityManager.remove(note);
65 }
66
67
68
69
70 public List<Note> findByremoteObjectId(String remoteObjectId) {
71 Criteria criteria = new Criteria(Note.class.getName());
72
73 criteria.eq("remoteObjectIdentifier", remoteObjectId);
74 criteria.orderBy("notePostedTimestamp", true);
75 return new ArrayList<Note>(new QueryByCriteria(entityManager, criteria).toQuery().getResultList());
76 }
77
78 public Note getNoteByNoteId(Long noteId) {
79 Criteria criteria = new Criteria(Note.class.getName());
80 criteria.eq("noteIdentifier", noteId);
81 return (Note) new QueryByCriteria(entityManager, criteria).toQuery().getSingleResult();
82 }
83
84
85
86
87 public EntityManager getEntityManager() {
88 return this.entityManager;
89 }
90
91
92
93
94 public void setEntityManager(EntityManager entityManager) {
95 this.entityManager = entityManager;
96 }
97
98 }