Coverage Report - org.kuali.rice.kew.notes.dao.impl.NoteDAOJpaImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
NoteDAOJpaImpl
0%
0/24
0%
0/2
1.125
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.kew.notes.dao.impl;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import javax.persistence.EntityManager;
 21  
 import javax.persistence.PersistenceContext;
 22  
 import javax.persistence.Query;
 23  
 
 24  
 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
 25  
 import org.kuali.rice.kew.notes.Attachment;
 26  
 import org.kuali.rice.kew.notes.Note;
 27  
 import org.kuali.rice.kew.notes.dao.NoteDAO;
 28  
 
 29  
 
 30  0
 public class NoteDAOJpaImpl implements NoteDAO {
 31  
 
 32  
         @PersistenceContext(unitName="kew-unit")
 33  
         EntityManager entityManager;
 34  
         
 35  
     public Note getNoteByNoteId(String noteId) {
 36  0
             Query query = entityManager.createNamedQuery("KewNote.FindNoteByNoteId");
 37  0
             query.setParameter("noteId", noteId);
 38  0
         return (Note) query.getSingleResult();          
 39  
     }
 40  
 
 41  
     public List getNotesByDocumentId(String documentId) {
 42  0
             Query query = entityManager.createNamedQuery("KewNote.FindNoteByDocumentId");
 43  0
             query.setParameter("documentId", documentId);
 44  0
         return (List) query.getResultList();        
 45  
     }
 46  
     
 47  
     public void saveNote(Note note) {
 48  0
             if (note.getNoteId() == null){
 49  0
                     entityManager.persist(note);
 50  
             } else {
 51  0
                     entityManager.merge(note);
 52  
             }
 53  0
     }
 54  
 
 55  
     public void deleteNote(Note note) {
 56  0
             Note n = getNoteByNoteId(note.getNoteId());
 57  0
             OrmUtils.merge(entityManager, n);
 58  0
             entityManager.remove(n);
 59  0
     }
 60  
    
 61  
     public void deleteAttachment(Attachment attachment) {
 62  0
             Attachment a = findAttachment(attachment.getAttachmentId());
 63  0
             entityManager.remove(a);
 64  0
     }
 65  
 
 66  
         
 67  
     public Attachment findAttachment(String attachmentId) {
 68  0
             Query query = entityManager.createNamedQuery("Attachment.FindAttachmentById");
 69  0
             query.setParameter("attachmentId", attachmentId);
 70  0
             return (Attachment)query.getSingleResult();
 71  
     }
 72  
 
 73  
     public EntityManager getEntityManager() {
 74  0
         return this.entityManager;
 75  
     }
 76  
 
 77  
     public void setEntityManager(EntityManager entityManager) {
 78  0
         this.entityManager = entityManager;
 79  0
     }
 80  
 
 81  
 }