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.Collection; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import org.apache.log4j.Logger; |
23 | |
import org.apache.ojb.broker.query.Criteria; |
24 | |
import org.apache.ojb.broker.query.Query; |
25 | |
import org.apache.ojb.broker.query.QueryByCriteria; |
26 | |
import org.apache.ojb.broker.query.QueryFactory; |
27 | |
import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; |
28 | |
import org.kuali.rice.krad.bo.Attachment; |
29 | |
import org.kuali.rice.krad.bo.Note; |
30 | |
import org.kuali.rice.krad.dao.NoteDao; |
31 | |
import org.springframework.dao.DataAccessException; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class NoteDaoOjb extends PlatformAwareDaoBaseOjb implements NoteDao { |
39 | 0 | private static Logger LOG = Logger.getLogger(NoteDaoOjb.class); |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public NoteDaoOjb() { |
45 | 0 | super(); |
46 | 0 | } |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public void save(Note note) throws DataAccessException { |
54 | |
|
55 | |
|
56 | 0 | if (note.getAttachment() != null && note.getAttachment().getAttachmentFileName() == null) { |
57 | 0 | note.setAttachment(null); |
58 | |
} |
59 | |
|
60 | 0 | if (note != null && note.getNoteIdentifier() == null && note.getAttachment() != null) { |
61 | 0 | Attachment attachment = note.getAttachment(); |
62 | 0 | note.setAttachment(null); |
63 | |
|
64 | 0 | getPersistenceBrokerTemplate().store(note); |
65 | 0 | attachment.setNoteIdentifier(note.getNoteIdentifier()); |
66 | |
|
67 | 0 | note.setAttachment(attachment); |
68 | |
} |
69 | 0 | getPersistenceBrokerTemplate().store(note); |
70 | 0 | } |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public void deleteNote(Note note) throws DataAccessException { |
76 | 0 | getPersistenceBrokerTemplate().delete(note.getAttachment()); |
77 | 0 | note.setAttachment(null); |
78 | 0 | getPersistenceBrokerTemplate().delete(note); |
79 | |
|
80 | 0 | } |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public List<Note> findByremoteObjectId(String remoteObjectId) { |
89 | 0 | Criteria criteria = new Criteria(); |
90 | |
|
91 | 0 | criteria.addEqualTo("RMT_OBJ_ID", remoteObjectId); |
92 | |
|
93 | 0 | QueryByCriteria query = QueryFactory.newQuery(Note.class, criteria); |
94 | |
|
95 | |
|
96 | 0 | defaultOrderBy(query); |
97 | 0 | Collection<Note> notes = findCollection(query); |
98 | |
|
99 | 0 | return new ArrayList<Note>(notes); |
100 | |
} |
101 | |
|
102 | |
public Note getNoteByNoteId(Long noteId) { |
103 | 0 | Criteria crit = new Criteria(); |
104 | 0 | crit.addEqualTo("noteIdentifier", noteId); |
105 | 0 | return (Note) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(Note.class, crit)); |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
private void defaultOrderBy(QueryByCriteria query) { |
113 | |
|
114 | 0 | query.addOrderBy("notePostedTimestamp", true); |
115 | 0 | } |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
@SuppressWarnings("unchecked") |
125 | |
private Collection<Note> findCollection(Query query) throws DataAccessException { |
126 | 0 | return getPersistenceBrokerTemplate().getCollectionByQuery(query); |
127 | |
} |
128 | |
} |