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 | |
|
20 | |
import javax.persistence.EntityManager; |
21 | |
import javax.persistence.PersistenceContext; |
22 | |
|
23 | |
import org.apache.log4j.Logger; |
24 | |
import org.kuali.rice.core.jpa.criteria.Criteria; |
25 | |
import org.kuali.rice.core.jpa.criteria.QueryByCriteria; |
26 | |
import org.kuali.rice.kns.bo.Attachment; |
27 | |
import org.kuali.rice.kns.bo.DocumentHeader; |
28 | |
import org.kuali.rice.kns.bo.Note; |
29 | |
import org.kuali.rice.kns.dao.NoteDao; |
30 | |
import org.springframework.dao.DataAccessException; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class NoteDaoJpa implements NoteDao { |
38 | |
|
39 | 0 | private static Logger LOG = Logger.getLogger(NoteDaoJpa.class); |
40 | |
|
41 | |
@PersistenceContext |
42 | |
private EntityManager entityManager; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public void save(Note note) throws DataAccessException { |
48 | 0 | if (note != null && note.getNoteIdentifier() == null && note.getAttachment() != null) { |
49 | 0 | Attachment attachment = note.getAttachment(); |
50 | 0 | note.setAttachment(null); |
51 | |
|
52 | 0 | entityManager.merge(note); |
53 | 0 | attachment.setNoteIdentifier(note.getNoteIdentifier()); |
54 | |
|
55 | 0 | note.setAttachment(attachment); |
56 | |
} |
57 | 0 | entityManager.merge(note); |
58 | |
|
59 | 0 | } |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public void deleteNote(Note note) throws DataAccessException { |
65 | 0 | entityManager.remove(note.getAttachment()); |
66 | 0 | note.setAttachment(null); |
67 | 0 | entityManager.remove(note); |
68 | 0 | } |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public ArrayList findByremoteObjectId(String remoteObjectId) { |
74 | 0 | Criteria criteria = new Criteria(Note.class.getName()); |
75 | |
|
76 | 0 | criteria.eq("remoteObjectIdentifier", remoteObjectId); |
77 | 0 | criteria.orderBy("notePostedTimestamp", true); |
78 | 0 | return new ArrayList(new QueryByCriteria(entityManager, criteria).toQuery().getResultList()); |
79 | |
} |
80 | |
|
81 | |
public Note getNoteByNoteId(Long noteId) { |
82 | 0 | Criteria criteria = new Criteria(Note.class.getName()); |
83 | 0 | criteria.eq("noteIdentifier", noteId); |
84 | 0 | return (Note) new org.kuali.rice.core.jpa.criteria.QueryByCriteria(entityManager, criteria).toQuery().getSingleResult(); |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public EntityManager getEntityManager() { |
91 | 0 | return this.entityManager; |
92 | |
} |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
public void setEntityManager(EntityManager entityManager) { |
98 | 0 | this.entityManager = entityManager; |
99 | 0 | } |
100 | |
|
101 | |
} |