Coverage Report - org.kuali.rice.krad.dao.impl.DocumentDaoOjb
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentDaoOjb
0%
0/31
0%
0/8
1.5
 
 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.krad.dao.impl;
 17  
 
 18  
 import org.apache.log4j.Logger;
 19  
 import org.apache.ojb.broker.query.Criteria;
 20  
 import org.apache.ojb.broker.query.QueryByCriteria;
 21  
 import org.apache.ojb.broker.query.QueryFactory;
 22  
 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
 23  
 import org.kuali.rice.krad.dao.BusinessObjectDao;
 24  
 import org.kuali.rice.krad.dao.DocumentDao;
 25  
 import org.kuali.rice.krad.document.Document;
 26  
 import org.kuali.rice.krad.service.DocumentAdHocService;
 27  
 import org.kuali.rice.krad.service.KRADServiceLocatorInternal;
 28  
 import org.kuali.rice.krad.util.KRADPropertyConstants;
 29  
 import org.kuali.rice.krad.util.OjbCollectionAware;
 30  
 import org.springframework.dao.DataAccessException;
 31  
 
 32  
 import java.util.ArrayList;
 33  
 import java.util.List;
 34  
 
 35  
 /**
 36  
  * This class is the OJB implementation of the DocumentDao interface.
 37  
  */
 38  
 public class DocumentDaoOjb extends PlatformAwareDaoBaseOjb implements DocumentDao, OjbCollectionAware{
 39  0
     private static final Logger LOG = Logger.getLogger(DocumentDaoOjb.class);
 40  
     protected BusinessObjectDao businessObjectDao;
 41  
     protected DocumentAdHocService documentAdHocService;
 42  
 
 43  
 
 44  
     public DocumentDaoOjb(BusinessObjectDao businessObjectDao, DocumentAdHocService documentAdHocService) {
 45  0
         super();
 46  0
         this.businessObjectDao = businessObjectDao;
 47  0
         this.documentAdHocService = documentAdHocService;
 48  0
     }
 49  
 
 50  
     /**
 51  
      * @see org.kuali.dao.DocumentDao#save(null)
 52  
      */
 53  
     @Override
 54  
     public <T extends Document> T save(T document) throws DataAccessException {
 55  0
             if ( LOG.isDebugEnabled() ) {
 56  0
                     LOG.debug( "About to store document: " + document, new Throwable() );
 57  
             }
 58  0
         Document retrievedDocument = findByDocumentHeaderId(document.getClass(),document.getDocumentNumber());
 59  0
         KRADServiceLocatorInternal.getOjbCollectionHelper().processCollections(this, document, retrievedDocument);
 60  0
         this.getPersistenceBrokerTemplate().store(document);
 61  0
         return document;
 62  
     }
 63  
 
 64  
     /**
 65  
      * Retrieve a Document of a specific type with a given document header ID.
 66  
      *
 67  
      * @param clazz
 68  
      * @param id
 69  
      * @return Document with given id
 70  
      */
 71  
     @Override
 72  
     public <T extends Document> T findByDocumentHeaderId(Class<T> clazz, String id) {
 73  0
         List<String> idList = new ArrayList<String>();
 74  0
         idList.add(id);
 75  
 
 76  0
         List<T> documentList = findByDocumentHeaderIds(clazz, idList);
 77  
 
 78  0
         T document = null;
 79  0
         if ((null != documentList) && (documentList.size() > 0)) {
 80  0
             document = documentList.get(0);
 81  
         }
 82  
 
 83  0
         return document;
 84  
     }
 85  
 
 86  
     /**
 87  
      * Retrieve a List of Document instances with the given ids
 88  
      *
 89  
      * @param clazz
 90  
      * @param idList
 91  
      * @return List
 92  
      */
 93  
     @Override
 94  
     public <T extends Document> List<T> findByDocumentHeaderIds(Class<T> clazz, List<String> idList) {
 95  0
         Criteria criteria = new Criteria();
 96  0
         criteria.addIn(KRADPropertyConstants.DOCUMENT_NUMBER, idList);
 97  
 
 98  0
         QueryByCriteria query = QueryFactory.newQuery(clazz, criteria);
 99  
         
 100  
         // this cast is correct because OJB produces a collection which contains elements of the class defined on the query
 101  
         @SuppressWarnings("unchecked")
 102  0
         List<T> tempList = new ArrayList<T>(this.getPersistenceBrokerTemplate().getCollectionByQuery(query));
 103  
         
 104  0
         for (T doc : tempList) {
 105  0
                 documentAdHocService.addAdHocs(doc);
 106  
         }
 107  0
         return tempList;
 108  
     }
 109  
 
 110  
     /**
 111  
      * Returns the {@link BusinessObjectDao}
 112  
      * @see org.kuali.rice.krad.dao.DocumentDao#getBusinessObjectDao()
 113  
      * @return the {@link BusinessObjectDao}
 114  
      */
 115  
     @Override
 116  
     public BusinessObjectDao getBusinessObjectDao() {
 117  0
         return businessObjectDao;
 118  
     }
 119  
 
 120  
     /**
 121  
      * Sets the {@link BusinessObjectDao}
 122  
      * @param businessObjectDao ths {@link BusinessObjectDao}
 123  
      */
 124  
     public void setBusinessObjectDao(BusinessObjectDao businessObjectDao) {
 125  0
         this.businessObjectDao = businessObjectDao;
 126  0
     }
 127  
 
 128  
     /**
 129  
          * @return the documentAdHocService
 130  
          */
 131  
     @Override
 132  
         public DocumentAdHocService getDocumentAdHocService() {
 133  0
                 return this.documentAdHocService;
 134  
         }
 135  
 
 136  
     /**
 137  
      * Setter for injecting the DocumentAdHocService
 138  
      * @param dahs
 139  
      */
 140  
     public void setDocumentAdHocService(DocumentAdHocService dahs) {
 141  0
             this.documentAdHocService = dahs;
 142  0
     }
 143  
 }