Coverage Report - org.mule.transaction.ExternalXaTransaction
 
Classes in this File Line Coverage Branch Coverage Complexity
ExternalXaTransaction
0%
0/12
0%
0/2
0
ExternalXaTransaction$ExternalTransaction
0%
0/27
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: ExternalXaTransaction.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transaction;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.api.transaction.TransactionException;
 15  
 import org.mule.config.i18n.CoreMessages;
 16  
 
 17  
 import java.text.MessageFormat;
 18  
 
 19  
 import javax.transaction.Status;
 20  
 import javax.transaction.Synchronization;
 21  
 
 22  
 /**
 23  
  * <code>ExternalXaTransaction</code> represents an external XA transaction in Mule.
 24  
  */
 25  
 public class ExternalXaTransaction extends XaTransaction
 26  
 {
 27  
     public ExternalXaTransaction(MuleContext muleContext)
 28  
     {
 29  0
         super(muleContext);
 30  0
     }
 31  
 
 32  
     protected void doBegin() throws TransactionException
 33  
     {
 34  0
         if (txManager == null)
 35  
         {
 36  0
             throw new IllegalStateException(
 37  
                     CoreMessages.objectNotRegistered("javax.transaction.TransactionManager", "Transaction Manager").getMessage());
 38  
         }
 39  
 
 40  
         try
 41  
         {
 42  0
             synchronized (this)
 43  
             {
 44  0
                 transaction = txManager.getTransaction();
 45  0
                 transaction.registerSynchronization(new ExternalTransaction(muleContext));
 46  0
             }
 47  
         }
 48  0
         catch (Exception e)
 49  
         {
 50  0
             throw new TransactionException(CoreMessages.cannotStartTransaction("XA"), e);
 51  0
         }
 52  0
     }
 53  
 
 54  
     /**
 55  
      * This class is notified when an external transaction is complete and cleans up
 56  
      * Mule-specific resources
 57  
      */
 58  
     class ExternalTransaction extends AbstractTransaction implements Synchronization
 59  
     {
 60  
         ExternalTransaction(MuleContext muleContext)
 61  0
         {
 62  0
             super(muleContext);
 63  0
         }
 64  
         
 65  
         /** Nothing to do */
 66  
         public void beforeCompletion()
 67  
         {
 68  0
         }
 69  
 
 70  
         /** Clean up mule resources */
 71  
         public void afterCompletion(int status)
 72  
         {
 73  0
             boolean commit = status == Status.STATUS_COMMITTED;
 74  
 
 75  
             try
 76  
             {
 77  0
                 if (commit)
 78  
                 {
 79  0
                     commit();
 80  
                 }
 81  
                 else
 82  
                 {
 83  0
                     rollback();
 84  
                 }
 85  
             }
 86  0
             catch (TransactionException ex)
 87  
             {
 88  0
                 logger.warn(MessageFormat.format(
 89  
                     "Exception while {0} an external transaction {1}", commit ? "committing" : "rolling back", this), ex);
 90  0
             }
 91  0
         }
 92  
 
 93  
         @Override
 94  
         protected void unbindTransaction()
 95  
         {
 96  
             // no-op -- already unbound in TransactionTemplate
 97  0
         }
 98  
 
 99  
         @Override
 100  
         protected void doCommit()
 101  
         {
 102  0
             delistResources();
 103  0
             closeResources();
 104  0
             transaction = null;
 105  0
         }
 106  
 
 107  
         @Override
 108  
         protected void doRollback()
 109  
         {
 110  0
             closeResources();
 111  0
             transaction = null;
 112  0
         }
 113  
 
 114  
         @Override
 115  
         protected void doBegin()
 116  
         {
 117  0
         }
 118  
 
 119  
         @Override
 120  
         public boolean isRollbackOnly() throws TransactionException
 121  
         {
 122  0
             return ExternalXaTransaction.this.isRollbackOnly();
 123  
         }
 124  
 
 125  
         public int getStatus() throws TransactionException
 126  
         {
 127  0
             return ExternalXaTransaction.this.getStatus();
 128  
         }
 129  
 
 130  
         public Object getResource(Object key)
 131  
         {
 132  0
             return ExternalXaTransaction.this.getResource(key);
 133  
         }
 134  
 
 135  
         public boolean hasResource(Object key)
 136  
         {
 137  0
             return ExternalXaTransaction.this.hasResource(key);
 138  
         }
 139  
 
 140  
         public void bindResource(Object key, Object resource) throws TransactionException
 141  
         {
 142  0
         }
 143  
 
 144  
         public void setRollbackOnly() throws TransactionException
 145  
         {
 146  0
         }
 147  
     }
 148  
 }