Coverage Report - org.mule.module.spring.transaction.SpringTransactionFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
SpringTransactionFactory
0%
0/10
N/A
1.462
SpringTransactionFactory$SpringTransaction
0%
0/21
0%
0/8
1.462
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.spring.transaction;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.transaction.Transaction;
 11  
 import org.mule.api.transaction.TransactionException;
 12  
 import org.mule.api.transaction.TransactionFactory;
 13  
 import org.mule.transaction.AbstractSingleResourceTransaction;
 14  
 
 15  
 import org.springframework.jdbc.datasource.ConnectionHolder;
 16  
 import org.springframework.jms.connection.JmsResourceHolder;
 17  
 import org.springframework.transaction.PlatformTransactionManager;
 18  
 import org.springframework.transaction.TransactionStatus;
 19  
 import org.springframework.transaction.support.TransactionSynchronizationManager;
 20  
 
 21  
 /**
 22  
  * TODO: document this class
 23  
  */
 24  0
 public class SpringTransactionFactory implements TransactionFactory
 25  
 {
 26  
 
 27  
     private PlatformTransactionManager manager;
 28  
 
 29  
     public SpringTransactionFactory()
 30  
     {
 31  0
         super();
 32  0
     }
 33  
 
 34  
     public Transaction beginTransaction(MuleContext muleContext) throws TransactionException
 35  
     {
 36  0
         Transaction tx = new SpringTransaction(muleContext);
 37  0
         tx.begin();
 38  0
         return tx;
 39  
     }
 40  
 
 41  
     public boolean isTransacted()
 42  
     {
 43  0
         return true;
 44  
     }
 45  
 
 46  
     /**
 47  
      * @return Returns the manager.
 48  
      */
 49  
     synchronized public PlatformTransactionManager getManager()
 50  
     {
 51  0
         return manager;
 52  
     }
 53  
 
 54  
     /**
 55  
      * @param manager The manager to set.
 56  
      */
 57  
     synchronized public void setManager(PlatformTransactionManager manager)
 58  
     {
 59  0
         this.manager = manager;
 60  0
     }
 61  
 
 62  
     /**
 63  
      * TODO: document this class
 64  
      */
 65  
     public class SpringTransaction extends AbstractSingleResourceTransaction
 66  
     {
 67  
         protected final TransactionStatus status;
 68  
 
 69  
         public SpringTransaction(MuleContext muleContext)
 70  0
         {
 71  0
             super(muleContext);
 72  0
             status = manager.getTransaction(null);
 73  0
         }
 74  
 
 75  
         protected void doBegin() throws TransactionException
 76  
         {
 77  
             // nothing to do
 78  0
         }
 79  
 
 80  
         protected void doCommit() throws TransactionException
 81  
         {
 82  0
            manager.commit(status);
 83  0
         }
 84  
 
 85  
         protected void doRollback() throws TransactionException
 86  
         {
 87  0
            manager.rollback(status);
 88  0
         }
 89  
 
 90  
         public Object getResource(Object key)
 91  
         {
 92  0
             Object res = TransactionSynchronizationManager.getResource(key);
 93  0
             if (res != null)
 94  
             {
 95  0
                 if (!(res instanceof ConnectionHolder))
 96  
                 {
 97  0
                     if (res instanceof JmsResourceHolder)
 98  
                     {
 99  0
                         return ((JmsResourceHolder)res).getConnection();
 100  
                     }
 101  
                 }
 102  
                 else
 103  
                 {
 104  0
                     return ((ConnectionHolder)res).getConnection();
 105  
                 }
 106  
             }
 107  0
             return res;
 108  
         }
 109  
 
 110  
         public boolean hasResource(Object key)
 111  
         {
 112  0
             return getResource(key) != null;
 113  
         }
 114  
 
 115  
         public void bindResource(Object key, Object resource) throws TransactionException
 116  
         {
 117  0
             throw new UnsupportedOperationException();
 118  
         }
 119  
 
 120  
         public void setRollbackOnly()
 121  
         {
 122  0
             super.setRollbackOnly();
 123  0
             status.setRollbackOnly();
 124  0
         }
 125  
 
 126  
     }
 127  
 
 128  
 }