Coverage Report - org.kuali.rice.kns.dao.impl.NoteDaoJpa
 
Classes in this File Line Coverage Branch Coverage Complexity
NoteDaoJpa
0%
0/24
0%
0/6
1.5
 
 1  
 /*
 2  
  * Copyright 2007-2008 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  
 
 20  
 import javax.persistence.EntityManager;
 21  
 import javax.persistence.PersistenceContext;
 22  
 
 23  
 import org.apache.log4j.Logger;
 24  
 import org.kuali.rice.core.jpa.criteria.Criteria;
 25  
 import org.kuali.rice.core.jpa.criteria.QueryByCriteria;
 26  
 import org.kuali.rice.kns.bo.Attachment;
 27  
 import org.kuali.rice.kns.bo.DocumentHeader;
 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 JPA implementation of the NoteDao interface.
 34  
  * 
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  */
 37  0
 public class NoteDaoJpa implements NoteDao {
 38  
 
 39  0
         private static Logger LOG = Logger.getLogger(NoteDaoJpa.class);
 40  
 
 41  
         @PersistenceContext
 42  
         private EntityManager entityManager;
 43  
 
 44  
         /**
 45  
          * Saves a note to the DB using JPA.
 46  
          */
 47  
         public void save(Note note) throws DataAccessException {
 48  0
                 if (note != null && note.getNoteIdentifier() == null && note.getAttachment() != null) {
 49  0
                         Attachment attachment = note.getAttachment();
 50  0
                         note.setAttachment(null);
 51  
                         // store without attachment
 52  0
                         entityManager.merge(note);
 53  0
                         attachment.setNoteIdentifier(note.getNoteIdentifier());
 54  
                         // put attachment back
 55  0
                         note.setAttachment(attachment);
 56  
                 }
 57  0
                 entityManager.merge(note);
 58  
                 
 59  0
         }
 60  
 
 61  
         /**
 62  
          * Deletes a note from the DB using JPA.
 63  
          */
 64  
         public void deleteNote(Note note) throws DataAccessException {
 65  0
                 entityManager.remove(note.getAttachment());
 66  0
                 note.setAttachment(null);
 67  0
                 entityManager.remove(note);
 68  0
         }
 69  
 
 70  
         /**
 71  
          * Retrieves document associated with a given object using JPA.
 72  
          */
 73  
         public ArrayList findByremoteObjectId(String remoteObjectId) {
 74  0
                 Criteria criteria = new Criteria(Note.class.getName());
 75  
                 // TODO: Notes - Chris move remoteObjectId string to constants
 76  0
                 criteria.eq("remoteObjectIdentifier", remoteObjectId);
 77  0
                 criteria.orderBy("notePostedTimestamp", true);
 78  0
                 return new ArrayList(new QueryByCriteria(entityManager, criteria).toQuery().getResultList());
 79  
         }
 80  
         
 81  
          public Note getNoteByNoteId(Long noteId) {
 82  0
                  Criteria criteria = new Criteria(Note.class.getName());
 83  0
                  criteria.eq("noteIdentifier", noteId);
 84  0
              return (Note) new org.kuali.rice.core.jpa.criteria.QueryByCriteria(entityManager, criteria).toQuery().getSingleResult();          
 85  
             }
 86  
 
 87  
     /**
 88  
      * @return the entityManager
 89  
      */
 90  
     public EntityManager getEntityManager() {
 91  0
         return this.entityManager;
 92  
     }
 93  
 
 94  
     /**
 95  
      * @param entityManager the entityManager to set
 96  
      */
 97  
     public void setEntityManager(EntityManager entityManager) {
 98  0
         this.entityManager = entityManager;
 99  0
     }
 100  
 
 101  
 }