Coverage Report - org.kuali.student.core.comment.dao.impl.CommentDaoImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CommentDaoImpl
79%
43/54
N/A
1.182
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.core.comment.dao.impl;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import javax.persistence.EntityManager;
 21  
 import javax.persistence.NoResultException;
 22  
 import javax.persistence.PersistenceContext;
 23  
 import javax.persistence.Query;
 24  
 
 25  
 import org.kuali.student.core.comment.dao.CommentDao;
 26  
 import org.kuali.student.core.comment.entity.Comment;
 27  
 import org.kuali.student.core.comment.entity.CommentType;
 28  
 import org.kuali.student.core.comment.entity.Reference;
 29  
 import org.kuali.student.core.comment.entity.Tag;
 30  
 import org.kuali.student.core.dao.impl.AbstractSearchableCrudDaoImpl;
 31  
 
 32  
 /**
 33  
  * This is a description of what this class does - lindholm don't forget to fill this in.
 34  
  *
 35  
  * @author Kuali Rice Team (kuali-rice@googlegroups.com)
 36  
  *
 37  
  */
 38  2
 public class CommentDaoImpl extends AbstractSearchableCrudDaoImpl implements CommentDao {
 39  
     @PersistenceContext(unitName = "Comment")
 40  
     @Override
 41  
     public void setEm(EntityManager em) {
 42  1
         super.setEm(em);
 43  1
     }
 44  
 
 45  
 
 46  
     public Comment getComment(String referenceId, String referenceTypeKey){
 47  0
         Query query = em.createNamedQuery("Comment.getComment");
 48  0
         query.setParameter("refId", referenceId);
 49  0
         query.setParameter("refTypeId", referenceTypeKey);
 50  0
         Comment comment = (Comment) query.getSingleResult();
 51  0
         return comment;
 52  
 
 53  
     }
 54  
 
 55  
     public List<Comment> getComments(String referenceId, String referenceTypeKey){
 56  2
         Query query = em.createNamedQuery("Comment.getComments");
 57  2
         query.setParameter("refId", referenceId);
 58  2
         query.setParameter("refTypeId", referenceTypeKey);
 59  
         @SuppressWarnings("unchecked")
 60  2
         List<Comment> comments = query.getResultList();
 61  2
         return comments;
 62  
     }
 63  
 
 64  
     public List<Comment> getCommentsByRefId(String referenceId){
 65  1
         Query query = em.createNamedQuery("Comment.getCommentsByRefId");
 66  1
         query.setParameter("refId", referenceId);
 67  
         @SuppressWarnings("unchecked")
 68  1
         List<Comment> comments = query.getResultList();
 69  1
         return comments;
 70  
     }
 71  
 
 72  
     public List<Comment> getCommentsByType(String referenceId, String referenceTypeKey, String commentTypeKey ){
 73  0
         Query query = em.createNamedQuery("Comment.getCommentsByType");
 74  0
         query.setParameter("refId", referenceId);
 75  0
         query.setParameter("refTypeId", referenceTypeKey);
 76  0
         query.setParameter("commentTypeId", commentTypeKey);
 77  
         @SuppressWarnings("unchecked")
 78  0
         List<Comment> comments = query.getResultList();
 79  0
         return comments;
 80  
     }
 81  
 
 82  
         public List<CommentType> getCommentTypesByReferenceTypeId(String referenceTypeId) {
 83  1
         Query query = em.createNamedQuery("CommentType.getCommentTypesByReferenceTypeId");
 84  1
         query.setParameter("referenceTypeId", referenceTypeId);
 85  
         @SuppressWarnings("unchecked")
 86  1
         List<CommentType> comments = query.getResultList();
 87  1
         return comments;
 88  
 
 89  
     }
 90  
 
 91  
     public Tag getTag(String referenceId, String referenceTypeKey){
 92  3
         Query query = em.createNamedQuery("Tag.getTag");
 93  3
         query.setParameter("refId", referenceId);
 94  3
         query.setParameter("refTypeId", referenceTypeKey);
 95  3
         Tag tag = (Tag)query.getSingleResult();
 96  1
         return tag;
 97  
     }
 98  
     public List<Tag> getTags(String referenceId, String referenceTypeKey){
 99  2
         Query query = em.createNamedQuery("Tag.getTags");
 100  2
         query.setParameter("refId", referenceId);
 101  2
         query.setParameter("refTypeId", referenceTypeKey);
 102  
         @SuppressWarnings("unchecked")
 103  2
         List<Tag> tags = query.getResultList();
 104  2
         return tags;
 105  
     }
 106  
 
 107  
     public List<Tag> getTagsByRefId(String referenceId){
 108  1
         Query query = em.createNamedQuery("Tag.getTagsByRefId");
 109  1
         query.setParameter("refId", referenceId);
 110  
         @SuppressWarnings("unchecked")
 111  1
         List<Tag> tags = query.getResultList();
 112  1
         return tags;
 113  
     }
 114  
 
 115  
     public List<Tag> getTagsByType(String referenceId, String referenceTypeKey, String tagTypeKey ){
 116  1
         Query query = em.createNamedQuery("Tag.getTagsByType");
 117  1
         query.setParameter("refId", referenceId);
 118  1
         query.setParameter("refTypeId", referenceTypeKey);
 119  1
         query.setParameter("tagTypeId", tagTypeKey);
 120  
         @SuppressWarnings("unchecked")
 121  1
         List<Tag> tags = query.getResultList();
 122  1
         return tags;
 123  
     }
 124  
 
 125  
     public Reference getReference(String referenceId, String referenceType){
 126  17
         Query query = em.createNamedQuery("Reference.getReference");
 127  17
         query.setParameter("refId", referenceId);
 128  17
         query.setParameter("refTypeId", referenceType);
 129  
         try{
 130  17
         Reference reference = (Reference)query.getSingleResult();
 131  12
         return reference;
 132  
         }
 133  5
         catch(NoResultException e){
 134  5
             return null;
 135  
         }
 136  
 
 137  
 
 138  
     }
 139  
 
 140  
 
 141  
 }