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