Coverage Report - org.kuali.rice.test.TransactionalLifecycle
 
Classes in this File Line Coverage Branch Coverage Complexity
TransactionalLifecycle
0%
0/22
0%
0/2
1.143
 
 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.test;
 17  
 
 18  
 import org.kuali.rice.core.api.lifecycle.Lifecycle;
 19  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 20  
 import org.springframework.transaction.PlatformTransactionManager;
 21  
 import org.springframework.transaction.TransactionStatus;
 22  
 import org.springframework.transaction.support.DefaultTransactionDefinition;
 23  
 
 24  
 /**
 25  
  * A lifecycle for testing with database transactional rollback.
 26  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 27  
  */
 28  
 public class TransactionalLifecycle implements Lifecycle {
 29  
         
 30  0
         private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
 31  
                         .getLogger(TransactionalLifecycle.class);
 32  
         
 33  
     /**
 34  
      * Name of the transaction manager to pull from the GlobalResourceLoader.
 35  
      * This will most likely be a Spring bean name.
 36  
      */
 37  
     public static final String DEFAULT_TRANSACTION_MANAGER_NAME = "transactionManager";
 38  
 
 39  
     private String transactionManagerName;
 40  
     private PlatformTransactionManager transactionManager;
 41  
 
 42  0
     public TransactionalLifecycle(String transactionManagerName) {
 43  0
             this.transactionManagerName = transactionManagerName;
 44  0
     }
 45  
     
 46  
     public TransactionalLifecycle() {
 47  0
             this(DEFAULT_TRANSACTION_MANAGER_NAME);
 48  0
     }
 49  
     
 50  
     public void setTransactionManager(PlatformTransactionManager transactionManager) {
 51  0
             this.transactionManager = transactionManager;
 52  0
     }
 53  
     
 54  
     /**
 55  
      * Returns the PlatformTransactionManager configured on this lifecycle.
 56  
      * If none defined, pulls the transaction manager out of the GlobalResourceLoader
 57  
      * @return the transaction manager in the GlobalResourceLoader
 58  
      */
 59  
     private PlatformTransactionManager getTransactionManager() {
 60  0
             if (transactionManager == null) {
 61  0
                     transactionManager = (PlatformTransactionManager) GlobalResourceLoader.getService(transactionManagerName);
 62  
             }
 63  0
             return transactionManager;
 64  
     }
 65  
 
 66  
     private boolean started;
 67  
     private TransactionStatus TRANSACTION_STATUS;
 68  
 
 69  
     public boolean isStarted() {
 70  0
         return started;
 71  
     }
 72  
 
 73  
     public void start() throws Exception {
 74  0
             LOG.info("Starting a transaction from TransactionalLifecycle...");
 75  0
         DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
 76  0
         defaultTransactionDefinition.setTimeout(3600);
 77  0
         TRANSACTION_STATUS = getTransactionManager().getTransaction(defaultTransactionDefinition);
 78  0
         started = true;
 79  0
     }
 80  
 
 81  
     public void stop() throws Exception {
 82  0
             LOG.info("...rolling back transaction from TransactionalLifecycle.");
 83  0
         getTransactionManager().rollback(TRANSACTION_STATUS);
 84  0
         started = false;
 85  0
     }
 86  
 
 87  
 }