Coverage Report - org.kuali.rice.kew.documentlink.dao.impl.DocumentLinkDAOJpaImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentLinkDAOJpaImpl
0%
0/27
0%
0/6
1.375
 
 1  
 /*
 2  
  * Copyright 2007-2010 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.documentlink.dao.impl;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import javax.persistence.EntityManager;
 21  
 import javax.persistence.PersistenceContext;
 22  
 
 23  
 import org.kuali.rice.core.jpa.criteria.Criteria;
 24  
 import org.kuali.rice.core.jpa.criteria.QueryByCriteria;
 25  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 26  
 import org.kuali.rice.kew.documentlink.DocumentLink;
 27  
 import org.kuali.rice.kew.documentlink.dao.DocumentLinkDAO;
 28  
 
 29  
 /**
 30  
  * This is a description of what this class does - g1zhang don't forget to fill this in. 
 31  
  * 
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  *
 34  
  */
 35  0
 public class DocumentLinkDAOJpaImpl implements DocumentLinkDAO {
 36  
 
 37  
         
 38  
     @PersistenceContext(unitName = "kew-unit")
 39  
     private EntityManager entityManager;
 40  
     
 41  
     public EntityManager getEntityManager() {
 42  0
         return this.entityManager;
 43  
     }
 44  
 
 45  
     public void setEntityManager(EntityManager entityManager) {
 46  0
         this.entityManager = entityManager;
 47  0
     }
 48  
     
 49  
         /**
 50  
          * double delete all links from orgn doc
 51  
          * 
 52  
          * @see org.kuali.rice.kew.documentlink.dao.DocumentLinkDAO#deleteDocmentLinksByDocId(java.lang.Long)
 53  
          */
 54  
         public void deleteDocmentLinksByDocId(Long docId) {
 55  0
                 List<DocumentLink> links = getLinkedDocumentsByDocId(docId);
 56  0
                 for(DocumentLink link: links){
 57  0
                         deleteDocumentLink(link);
 58  
                 }
 59  0
         }
 60  
 
 61  
         /**
 62  
          * double delete a link
 63  
          * 
 64  
          * @see org.kuali.rice.kew.documentlink.dao.DocumentLinkDAO#deleteDocumentLink(org.kuali.rice.kew.documentlink.DocumentLink)
 65  
          */
 66  
         public void deleteDocumentLink(DocumentLink link) {
 67  0
                 deleteSingleLinkFromOrgnDoc(link);
 68  0
                 deleteSingleLinkFromOrgnDoc(DocumentLinkDaoUtil.reverseLink(link));
 69  0
         }
 70  
 
 71  
         /**
 72  
          * get a link from orgn doc
 73  
          * 
 74  
          * @see org.kuali.rice.kew.documentlink.dao.DocumentLinkDAO#getLinkedDocument(org.kuali.rice.kew.documentlink.DocumentLink)
 75  
          */
 76  
         public DocumentLink getLinkedDocument(DocumentLink link) {
 77  0
                 Criteria crit = new Criteria(DocumentLink.class.getName());
 78  0
                 crit.eq("orgnDocId", link.getOrgnDocId());
 79  0
                 crit.eq("destDocId", link.getDestDocId());
 80  0
                 return (DocumentLink) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
 81  
         }
 82  
 
 83  
         /**
 84  
          * get all links from orgn doc
 85  
          * 
 86  
          * @see org.kuali.rice.kew.documentlink.dao.DocumentLinkDAO#getLinkedDocumentsByDocId(java.lang.Long)
 87  
          */
 88  
         public List<DocumentLink> getLinkedDocumentsByDocId(Long docId) {
 89  0
                 Criteria crit = new Criteria(DocumentLink.class.getName());
 90  0
                 crit.eq("orgnDocId", docId);
 91  0
                 return (List<DocumentLink>) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
 92  
         
 93  
         }
 94  
 
 95  
         /**
 96  
          * add double link
 97  
          * 
 98  
          * @see org.kuali.rice.kew.documentlink.dao.DocumentLinkDAO#saveDocumentLink(org.kuali.rice.kew.documentlink.DocumentLink)
 99  
          */
 100  
         public void saveDocumentLink(DocumentLink link) {
 101  0
                 if(getLinkedDocument(link) == null)
 102  0
                         entityManager.persist(link);
 103  
 //                //if we want a 2-way linked pair
 104  0
                 DocumentLink rLink = DocumentLinkDaoUtil.reverseLink(link);
 105  0
                 if(getLinkedDocument(rLink) == null)
 106  0
                         entityManager.persist(link);
 107  
 
 108  0
         }
 109  
         
 110  
         private void deleteSingleLinkFromOrgnDoc(DocumentLink link){
 111  0
                 DocumentLink cur = getLinkedDocument(link);
 112  0
                 entityManager.remove(cur) ;
 113  0
         }
 114  
 
 115  
 }