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