Coverage Report - org.kuali.rice.kns.org.kuali.rice.krad.app.persistence.jpa.RicePersistenceUnitPostProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
RicePersistenceUnitPostProcessor
0%
0/19
0%
0/8
1.667
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.kns.org.kuali.rice.krad.app.persistence.jpa;
 17  
 
 18  
 import javax.sql.DataSource;
 19  
 
 20  
 import org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo;
 21  
 import org.springframework.orm.jpa.persistenceunit.PersistenceUnitPostProcessor;
 22  
 
 23  0
 public class RicePersistenceUnitPostProcessor implements PersistenceUnitPostProcessor {
 24  0
         static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RicePersistenceUnitPostProcessor.class);
 25  
         
 26  
         public static final String KNS_APPLICATION_PERSISTENCE_UNIT_NAME = "kns-application-unit";
 27  
         public static final String KNS_SERVER_PERSISTENCE_UNIT_NAME = "kns-server-unit";
 28  
 
 29  
         private DataSource jtaDataSource;
 30  
     
 31  
     public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo mutablePersistenceUnitInfo) {
 32  0
         mutablePersistenceUnitInfo.setJtaDataSource(getJtaDataSource());
 33  0
         addKNSManagedClassNames(mutablePersistenceUnitInfo);
 34  0
         if (mutablePersistenceUnitInfo.getPersistenceUnitName().equals(KNS_APPLICATION_PERSISTENCE_UNIT_NAME) || mutablePersistenceUnitInfo.getPersistenceUnitName().equals(KNS_SERVER_PERSISTENCE_UNIT_NAME)) {
 35  0
                 addRiceManagedClassNamesToKNSPersistenceUnit(mutablePersistenceUnitInfo);
 36  
         }
 37  0
     }
 38  
     
 39  
     /**
 40  
      * 
 41  
      * Adds all the KNS Managed entities to the persistence unit - which is important, becuase all
 42  
      * persistence units get the KNS entities to manage
 43  
      * 
 44  
      * @param mutablePersistenceUnitInfo
 45  
      */
 46  
     public void addKNSManagedClassNames(MutablePersistenceUnitInfo mutablePersistenceUnitInfo) {
 47  0
             addManagedClassNames(mutablePersistenceUnitInfo, new KNSPersistableBusinessObjectClassExposer());
 48  0
     }
 49  
     
 50  
     /**
 51  
      * Adds the class names listed by exposed by the given exposer into the persistence unit
 52  
      * 
 53  
      * @param mutablePersistenceUnitInfo the persistence unit to add managed JPA entity class names to
 54  
      * @param exposer the exposer for class names to manage
 55  
      */
 56  
     public void addManagedClassNames(MutablePersistenceUnitInfo mutablePersistenceUnitInfo, PersistableBusinessObjectClassExposer exposer) {
 57  0
             for (String exposedClassName : exposer.exposePersistableBusinessObjectClassNames()) {
 58  0
                     if (LOG.isDebugEnabled()) {
 59  0
                             LOG.debug("JPA will now be managing class: "+exposedClassName);
 60  
                     }
 61  0
                     mutablePersistenceUnitInfo.addManagedClassName(exposedClassName);
 62  
             }
 63  0
     }
 64  
     
 65  
     public void addRiceManagedClassNamesToKNSPersistenceUnit(MutablePersistenceUnitInfo mutablePersistenceUnitInfo) {
 66  0
             addManagedClassNames(mutablePersistenceUnitInfo, new RiceToNervousSystemBusinessObjectClassExposer());
 67  0
     }
 68  
 
 69  
     public DataSource getJtaDataSource() {
 70  0
         return jtaDataSource;
 71  
     }
 72  
 
 73  
     public void setJtaDataSource(DataSource jtaDataSource) {
 74  0
         this.jtaDataSource = jtaDataSource;
 75  0
     }
 76  
         
 77  
 }