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