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