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