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 | |
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.kns.bo.Attachment; |
29 | |
import org.kuali.rice.kns.bo.Note; |
30 | |
import org.kuali.rice.kns.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 | 0 | if(note!=null&¬e.getNoteIdentifier()==null&¬e.getAttachment()!=null) { |
56 | 0 | Attachment attachment = note.getAttachment(); |
57 | 0 | note.setAttachment(null); |
58 | |
|
59 | 0 | getPersistenceBrokerTemplate().store(note); |
60 | 0 | attachment.setNoteIdentifier(note.getNoteIdentifier()); |
61 | |
|
62 | 0 | note.setAttachment(attachment); |
63 | |
} |
64 | 0 | getPersistenceBrokerTemplate().store(note); |
65 | 0 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public void deleteNote(Note note) throws DataAccessException { |
71 | 0 | getPersistenceBrokerTemplate().delete(note.getAttachment()); |
72 | 0 | note.setAttachment(null); |
73 | 0 | getPersistenceBrokerTemplate().delete(note); |
74 | |
|
75 | 0 | } |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
public List<Note> findByremoteObjectId(String remoteObjectId) { |
84 | 0 | Criteria criteria = new Criteria(); |
85 | |
|
86 | 0 | criteria.addEqualTo("RMT_OBJ_ID", remoteObjectId); |
87 | |
|
88 | 0 | QueryByCriteria query = QueryFactory.newQuery(Note.class, criteria); |
89 | |
|
90 | |
|
91 | 0 | defaultOrderBy(query); |
92 | 0 | Collection<Note> notes = findCollection(query); |
93 | |
|
94 | 0 | return new ArrayList<Note>(notes); |
95 | |
} |
96 | |
|
97 | |
public Note getNoteByNoteId(Long noteId) { |
98 | 0 | Criteria crit = new Criteria(); |
99 | 0 | crit.addEqualTo("noteIdentifier", noteId); |
100 | 0 | return (Note) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(Note.class, crit)); |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
private void defaultOrderBy(QueryByCriteria query) { |
108 | |
|
109 | 0 | query.addOrderBy("notePostedTimestamp", true); |
110 | 0 | } |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
@SuppressWarnings("unchecked") |
120 | |
private Collection<Note> findCollection(Query query) throws DataAccessException { |
121 | 0 | return getPersistenceBrokerTemplate().getCollectionByQuery(query); |
122 | |
} |
123 | |
} |