Clover Coverage Report - Implementation 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
22   122   10   3.14
2   54   0.45   7
7     1.43  
1    
 
  NoteDaoOjb       Line # 37 22 0% 10 31 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
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    * This class is the OJB implementation of the NoteDao interface.
34    *
35    * @author Kuali Rice Team (rice.collab@kuali.org)
36    */
 
37    public class NoteDaoOjb extends PlatformAwareDaoBaseOjb implements NoteDao {
38    private static Logger LOG = Logger.getLogger(NoteDaoOjb.class);
39   
40    /**
41    * Default constructor.
42    */
 
43  0 toggle public NoteDaoOjb() {
44  0 super();
45    }
46   
47    /**
48    * Saves a note to the DB using OJB.
49    *
50    * @param line
51    */
 
52  0 toggle public void save(Note note) throws DataAccessException {
53    //workaround in case sequence is empty I shouldn't need this but ojb seems to work weird with this case
54  0 if(note!=null&&note.getNoteIdentifier()==null&&note.getAttachment()!=null) {
55  0 Attachment attachment = note.getAttachment();
56  0 note.setAttachment(null);
57    //store without attachment
58  0 getPersistenceBrokerTemplate().store(note);
59  0 attachment.setNoteIdentifier(note.getNoteIdentifier());
60    //put attachment back
61  0 note.setAttachment(attachment);
62    }
63  0 getPersistenceBrokerTemplate().store(note);
64    }
65   
66    /**
67    * Deletes a note from the DB using OJB.
68    */
 
69  0 toggle 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    }
75   
76    /**
77    * Retrieves document associated with a given object using OJB.
78    *
79    * @param id
80    * @return
81    */
 
82  0 toggle public List<Note> findByremoteObjectId(String remoteObjectId) {
83  0 Criteria criteria = new Criteria();
84    //TODO: Notes - Chris move remoteObjectId string to constants
85  0 criteria.addEqualTo("RMT_OBJ_ID", remoteObjectId);
86   
87  0 QueryByCriteria query = QueryFactory.newQuery(Note.class, criteria);
88    //while this is currently called every time these methods could be changed to allow
89    //custom sorting by BO see discussion on Notes confluence page
90  0 defaultOrderBy(query);
91  0 Collection<Note> notes = findCollection(query);
92   
93  0 return new ArrayList<Note>(notes);
94    }
95   
 
96  0 toggle 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    * This method defines the default sort for notes
104    * @param query
105    */
 
106  0 toggle private void defaultOrderBy(QueryByCriteria query) {
107    //TODO: Notes - Chris move remoteObjectId string to constants
108  0 query.addOrderBy("notePostedTimestamp", true);
109    }
110   
111   
112    /**
113    * Retrieve a Collection of note instances found by a query.
114    *
115    * @param query
116    * @return
117    */
 
118  0 toggle @SuppressWarnings("unchecked")
119    private Collection<Note> findCollection(Query query) throws DataAccessException {
120  0 return getPersistenceBrokerTemplate().getCollectionByQuery(query);
121    }
122    }