Coverage Report - org.mule.transport.vm.VMTransaction
 
Classes in this File Line Coverage Branch Coverage Complexity
VMTransaction
0%
0/24
0%
0/4
2.6
 
 1  
 /*
 2  
  * $Id: VMTransaction.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.transport.vm;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.api.transaction.TransactionException;
 15  
 import org.mule.config.i18n.CoreMessages;
 16  
 import org.mule.transaction.AbstractSingleResourceTransaction;
 17  
 import org.mule.transaction.IllegalTransactionStateException;
 18  
 import org.mule.util.queue.QueueManager;
 19  
 import org.mule.util.queue.QueueSession;
 20  
 import org.mule.util.xa.ResourceManagerException;
 21  
 
 22  
 public class VMTransaction extends AbstractSingleResourceTransaction
 23  
 {
 24  
 
 25  
     public VMTransaction(MuleContext muleContext) throws TransactionException
 26  
     {
 27  0
         super(muleContext);
 28  0
         QueueManager qm = muleContext.getQueueManager();
 29  0
         QueueSession qs = qm.getQueueSession();
 30  0
         bindResource(qm, qs);
 31  0
     }
 32  
 
 33  
     public void bindResource(Object key, Object resource) throws TransactionException
 34  
     {
 35  0
         if (!(key instanceof QueueManager) || !(resource instanceof QueueSession))
 36  
         {
 37  0
             throw new IllegalTransactionStateException(
 38  
                 CoreMessages.transactionCanOnlyBindToResources("QueueManager/QueueSession"));
 39  
         }
 40  0
         super.bindResource(key, resource);
 41  0
     }
 42  
 
 43  
     protected void doBegin() throws TransactionException
 44  
     {
 45  
         try
 46  
         {
 47  0
             ((QueueSession)resource).begin();
 48  
         }
 49  0
         catch (ResourceManagerException e)
 50  
         {
 51  0
             throw new TransactionException(CoreMessages.cannotStartTransaction("VMTransaction"), e);
 52  0
         }
 53  0
     }
 54  
 
 55  
     protected void doCommit() throws TransactionException
 56  
     {
 57  
         try
 58  
         {
 59  0
             ((QueueSession)resource).commit();
 60  
         }
 61  0
         catch (ResourceManagerException e)
 62  
         {
 63  0
             throw new TransactionException(CoreMessages.transactionCommitFailed(), e);
 64  0
         }
 65  0
     }
 66  
 
 67  
     protected void doRollback() throws TransactionException
 68  
     {
 69  
         try
 70  
         {
 71  0
             ((QueueSession)resource).rollback();
 72  
         }
 73  0
         catch (ResourceManagerException e)
 74  
         {
 75  0
             throw new TransactionException(CoreMessages.transactionRollbackFailed(), e);
 76  0
         }
 77  0
     }
 78  
 
 79  
 }