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