1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.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.kns.bo.Attachment; |
27 | |
import org.kuali.rice.kns.bo.Note; |
28 | |
import org.kuali.rice.kns.dao.NoteDao; |
29 | |
import org.springframework.dao.DataAccessException; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | 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 | 0 | if (note != null && note.getNoteIdentifier() == null && note.getAttachment() != null) { |
46 | 0 | Attachment attachment = note.getAttachment(); |
47 | 0 | note.setAttachment(null); |
48 | |
|
49 | 0 | entityManager.merge(note); |
50 | 0 | attachment.setNoteIdentifier(note.getNoteIdentifier()); |
51 | |
|
52 | 0 | note.setAttachment(attachment); |
53 | |
} |
54 | 0 | entityManager.merge(note); |
55 | |
|
56 | 0 | } |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public void deleteNote(Note note) throws DataAccessException { |
62 | 0 | entityManager.remove(note.getAttachment()); |
63 | 0 | note.setAttachment(null); |
64 | 0 | entityManager.remove(note); |
65 | 0 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public List<Note> findByremoteObjectId(String remoteObjectId) { |
71 | 0 | Criteria criteria = new Criteria(Note.class.getName()); |
72 | |
|
73 | 0 | criteria.eq("remoteObjectIdentifier", remoteObjectId); |
74 | 0 | criteria.orderBy("notePostedTimestamp", true); |
75 | 0 | return new ArrayList<Note>(new QueryByCriteria(entityManager, criteria).toQuery().getResultList()); |
76 | |
} |
77 | |
|
78 | |
public Note getNoteByNoteId(Long noteId) { |
79 | 0 | Criteria criteria = new Criteria(Note.class.getName()); |
80 | 0 | criteria.eq("noteIdentifier", noteId); |
81 | 0 | return (Note) new QueryByCriteria(entityManager, criteria).toQuery().getSingleResult(); |
82 | |
} |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public EntityManager getEntityManager() { |
88 | 0 | return this.entityManager; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public void setEntityManager(EntityManager entityManager) { |
95 | 0 | this.entityManager = entityManager; |
96 | 0 | } |
97 | |
|
98 | |
} |