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