Coverage Report - org.kuali.rice.kew.documentlink.dao.impl.DocumentLinkDAOOjbImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentLinkDAOOjbImpl
0%
0/34
0%
0/6
1.429
 
 1  
 /*
 2  
  * Copyright 2007-2009 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 org.kuali.rice.kew.documentlink.DocumentLink;
 21  
 import org.kuali.rice.kew.documentlink.dao.DocumentLinkDAO;
 22  
 import org.apache.ojb.broker.query.Criteria;
 23  
 import org.apache.ojb.broker.query.QueryByCriteria;
 24  
 import org.kuali.rice.kew.notes.Note;
 25  
 import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
 26  
 
 27  
 /**
 28  
  * This is a description of what this class does - g1zhang don't forget to fill this in. 
 29  
  * 
 30  
  * @author Kuali Rice Team (kuali-rice@googlegroups.com)
 31  
  *
 32  
  */
 33  0
 public class DocumentLinkDAOOjbImpl extends PersistenceBrokerDaoSupport implements DocumentLinkDAO{
 34  
 
 35  
         public void saveDocumentLink(DocumentLink link) {
 36  0
                 if(getLinkedDocument(link) == null)
 37  0
                         this.getPersistenceBrokerTemplate().store(link);          
 38  
                 //if we want a 2-way linked pair
 39  0
                 DocumentLink rLink = DocumentLinkDaoUtil.reverseLink(link);
 40  0
                 if(getLinkedDocument(rLink) == null)
 41  0
                         this.getPersistenceBrokerTemplate().store(rLink);
 42  0
         }
 43  
 
 44  
         public void deleteDocumentLink(DocumentLink link) {
 45  0
                 deleteSingleLinkFromOrgnDoc(link);
 46  0
                 deleteSingleLinkFromOrgnDoc(DocumentLinkDaoUtil.reverseLink(link));
 47  0
         }
 48  
 
 49  
         //double delete style
 50  
         public void deleteDocmentLinksByDocId(String docId){
 51  0
                 List<DocumentLink> links = getLinkedDocumentsByDocId(docId);
 52  0
                 for(DocumentLink link: links){
 53  0
                         deleteDocumentLink(link);
 54  
                 }
 55  
                 
 56  0
         }
 57  
 
 58  
         /**
 59  
          * This overridden method ...
 60  
          * 
 61  
          * @see org.kuali.rice.kew.documentlink.dao.DocumentLinkDAO#getLinkedDocumentByDocId(java.lang.Long)
 62  
          */
 63  
         public List<DocumentLink> getLinkedDocumentsByDocId(String docId) {
 64  0
                 Criteria crit = new Criteria();
 65  0
                 crit.addEqualTo("orgnDocId", docId);
 66  0
                 QueryByCriteria query = new QueryByCriteria(DocumentLink.class, crit);
 67  0
                 query.addOrderByAscending("orgnDocId");
 68  0
                 return (List<DocumentLink>) this.getPersistenceBrokerTemplate().getCollectionByQuery(query);  
 69  
         }
 70  
 
 71  
         /**
 72  
          * This overridden method ...
 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();
 78  0
                 crit.addEqualTo("orgnDocId", link.getOrgnDocId());
 79  0
                 crit.addEqualTo("destDocId", link.getDestDocId());
 80  0
                 QueryByCriteria query = new QueryByCriteria(DocumentLink.class, crit);
 81  0
                 query.addOrderByAscending("orgnDocId");
 82  0
                 return (DocumentLink) this.getPersistenceBrokerTemplate().getObjectByQuery(query);  
 83  
         }
 84  
 
 85  
         private void deleteSingleLinkFromOrgnDoc(DocumentLink link){
 86  0
                 Criteria crit = new Criteria();
 87  0
                 crit.addEqualTo("orgnDocId", link.getOrgnDocId());
 88  0
                 crit.addEqualTo("destDocId", link.getDestDocId());
 89  0
                 this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(DocumentLink.class, crit));
 90  0
         }
 91  
 
 92  
         public void deleteSingleLinksByOrgnDocId(String docId){
 93  0
                 Criteria crit = new Criteria();
 94  0
                 crit.addEqualTo("orgnDocId", docId);
 95  0
                 this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(DocumentLink.class, crit));
 96  0
         }
 97  
 }