Coverage Report - org.kuali.rice.ksb.messaging.quartz.KSBSchedulerFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
KSBSchedulerFactoryBean
0%
0/41
0%
0/22
4
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in
 5  
  * compliance with the License. You may obtain a copy of the License at
 6  
  *
 7  
  * http://www.opensource.org/licenses/ecl2.php
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS
 10  
  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
 11  
  * language governing permissions and limitations under the License.
 12  
  */
 13  
 package org.kuali.rice.ksb.messaging.quartz;
 14  
 
 15  
 import javax.sql.DataSource;
 16  
 import javax.transaction.TransactionManager;
 17  
 
 18  
 import org.kuali.rice.core.config.ConfigContext;
 19  
 import org.kuali.rice.core.config.ConfigurationException;
 20  
 import org.kuali.rice.ksb.service.KSBServiceLocator;
 21  
 import org.kuali.rice.ksb.util.KSBConstants;
 22  
 import org.quartz.Scheduler;
 23  
 import org.quartz.SchedulerException;
 24  
 import org.quartz.SchedulerFactory;
 25  
 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
 26  
 import org.springframework.transaction.PlatformTransactionManager;
 27  
 
 28  
 /**
 29  
  * An implementation of the Quartz SchedulerFactoryBean which uses a database-backed quartz if the useQuartzDatabase property
 30  
  * is set.
 31  
  * 
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  */
 34  0
 public class KSBSchedulerFactoryBean extends SchedulerFactoryBean {
 35  
 
 36  
     private PlatformTransactionManager jtaTransactionManager;
 37  
     private TransactionManager transactionManager;
 38  
     private DataSource dataSource;
 39  
     private DataSource nonTransactionalDataSource;
 40  0
     private boolean transactionManagerSet = false;
 41  0
     private boolean nonTransactionalDataSourceSet = false;
 42  0
     private boolean nonTransactionalDataSourceNull = true;
 43  0
     private boolean dataSourceSet = false;
 44  0
     private boolean schedulerInjected = false;
 45  
     
 46  
     @Override
 47  
     protected Scheduler createScheduler(SchedulerFactory schedulerFactory, String schedulerName) throws SchedulerException {
 48  0
         if (ConfigContext.getCurrentContextConfig().getObject(KSBConstants.INJECTED_EXCEPTION_MESSAGE_SCHEDULER_KEY) != null) {
 49  
             try {
 50  0
                     schedulerInjected = true;
 51  0
                 Scheduler scheduler = (Scheduler) ConfigContext.getCurrentContextConfig().getObject(KSBConstants.INJECTED_EXCEPTION_MESSAGE_SCHEDULER_KEY);
 52  0
                 scheduler.addJobListener(new MessageServiceExecutorJobListener());
 53  0
                 return scheduler;
 54  0
             } catch (Exception e) {
 55  0
                 throw new ConfigurationException(e);
 56  
             }
 57  
         }
 58  0
         return super.createScheduler(schedulerFactory, schedulerName);
 59  
     }
 60  
 
 61  
     @Override
 62  
     public void afterPropertiesSet() throws Exception {
 63  
 
 64  0
         boolean useQuartzDatabase = new Boolean(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.USE_QUARTZ_DATABASE));
 65  0
         if (useQuartzDatabase && !schedulerInjected) {
 66  
             // require a transaction manager
 67  0
             if (jtaTransactionManager == null) {
 68  0
                 throw new ConfigurationException("No jta transaction manager was configured for the KSB Quartz Scheduler");
 69  
             }
 70  0
             setTransactionManager(jtaTransactionManager);
 71  0
             if (!nonTransactionalDataSourceSet) {
 72  
                     // since transaction manager is required... require a non transactional datasource
 73  0
                     nonTransactionalDataSource = KSBServiceLocator.getMessageNonTransactionalDataSource();
 74  0
                     if (nonTransactionalDataSource == null) {
 75  0
                             throw new ConfigurationException("No non-transactional data source was found but is required for the KSB Quartz Scheduler");
 76  
                     }
 77  0
                     super.setNonTransactionalDataSource(nonTransactionalDataSource);
 78  
             }
 79  0
             if (!dataSourceSet) {
 80  0
                     dataSource = KSBServiceLocator.getMessageDataSource();
 81  
             }
 82  0
             super.setDataSource(dataSource);
 83  0
             if (transactionManagerSet && nonTransactionalDataSourceNull) {
 84  0
                 throw new ConfigurationException("A valid transaction manager was set but no non-transactional data source was found");
 85  
             }
 86  
         }
 87  0
         super.afterPropertiesSet();
 88  0
     }
 89  
     
 90  
     /**
 91  
      * This overridden method is used simply to keep track of whether the transactionManager property has been set
 92  
      * 
 93  
      * @see org.springframework.scheduling.quartz.SchedulerFactoryBean#setTransactionManager(org.springframework.transaction.PlatformTransactionManager)
 94  
      */
 95  
     @Override
 96  
     public void setTransactionManager(PlatformTransactionManager jtaTransactionManager) {
 97  0
         transactionManagerSet = jtaTransactionManager != null;
 98  0
         this.jtaTransactionManager = jtaTransactionManager;
 99  0
     }
 100  
     
 101  
     /**
 102  
      * This overridden method is used to keep track of whether the non transactional data source is null
 103  
      * 
 104  
      * @see org.springframework.scheduling.quartz.SchedulerFactoryBean#setNonTransactionalDataSource(javax.sql.DataSource)
 105  
      */
 106  
     @Override
 107  
     public void setNonTransactionalDataSource(DataSource nonTransactionalDataSource) {
 108  0
         nonTransactionalDataSourceSet = true;
 109  0
         nonTransactionalDataSourceNull = (nonTransactionalDataSource == null);
 110  0
         this.nonTransactionalDataSource = nonTransactionalDataSource;
 111  0
     }
 112  
     
 113  
     @Override
 114  
     public void setDataSource(DataSource dataSource) {
 115  0
             dataSourceSet = true;
 116  0
             this.dataSource = dataSource;
 117  0
     }
 118  
 }