Coverage Report - org.kuali.rice.kns.dao.impl.NoteDaoOjb
 
Classes in this File Line Coverage Branch Coverage Complexity
NoteDaoOjb
0%
0/27
0%
0/6
1.429
 
 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.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  
  * This class is the OJB implementation of the NoteDao interface.
 35  
  *
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  */
 38  
 public class NoteDaoOjb extends PlatformAwareDaoBaseOjb implements NoteDao {
 39  0
     private static Logger LOG = Logger.getLogger(NoteDaoOjb.class);
 40  
 
 41  
     /**
 42  
      * Default constructor.
 43  
      */
 44  
     public NoteDaoOjb() {
 45  0
         super();
 46  0
     }
 47  
 
 48  
     /**
 49  
      * Saves a note to the DB using OJB.
 50  
      *
 51  
      * @param line
 52  
      */
 53  
     public void save(Note note) throws DataAccessException {
 54  
         //workaround in case sequence is empty  I shouldn't need this but ojb seems to work weird with this case
 55  0
         if(note!=null&&note.getNoteIdentifier()==null&&note.getAttachment()!=null) {
 56  0
             Attachment attachment = note.getAttachment();
 57  0
             note.setAttachment(null);
 58  
             //store without attachment
 59  0
             getPersistenceBrokerTemplate().store(note);
 60  0
             attachment.setNoteIdentifier(note.getNoteIdentifier());
 61  
             //put attachment back
 62  0
             note.setAttachment(attachment);
 63  
         }
 64  0
         getPersistenceBrokerTemplate().store(note);
 65  0
     }
 66  
 
 67  
     /**
 68  
      * Deletes a note from the DB using OJB.
 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  
      * Retrieves document associated with a given object using OJB.
 79  
      *
 80  
      * @param id
 81  
      * @return
 82  
      */
 83  
     public List<Note> findByremoteObjectId(String remoteObjectId) {
 84  0
         Criteria criteria = new Criteria();
 85  
         //TODO: Notes - Chris move remoteObjectId string to constants
 86  0
         criteria.addEqualTo("RMT_OBJ_ID", remoteObjectId);
 87  
 
 88  0
         QueryByCriteria query = QueryFactory.newQuery(Note.class, criteria);
 89  
         //while this is currently called every time these methods could be changed to allow
 90  
         //custom sorting by BO see discussion on Notes confluence page
 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  
      * This method defines the default sort for notes
 105  
      * @param query
 106  
      */
 107  
     private void defaultOrderBy(QueryByCriteria query) {
 108  
         //TODO: Notes - Chris move remoteObjectId string to constants
 109  0
         query.addOrderBy("notePostedTimestamp", true);
 110  0
     }
 111  
 
 112  
 
 113  
     /**
 114  
      * Retrieve a Collection of note instances found by a query.
 115  
      *
 116  
      * @param query
 117  
      * @return
 118  
      */
 119  
     @SuppressWarnings("unchecked")
 120  
     private Collection<Note> findCollection(Query query) throws DataAccessException {
 121  0
         return getPersistenceBrokerTemplate().getCollectionByQuery(query);
 122  
     }
 123  
 }