Coverage Report - org.mule.providers.jms.JmsTransaction
 
Classes in this File Line Coverage Branch Coverage Complexity
JmsTransaction
0%
0/22
0%
0/2
3.5
 
 1  
 /*
 2  
  * $Id: JmsTransaction.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 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.providers.jms;
 12  
 
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.providers.jms.i18n.JmsMessages;
 15  
 import org.mule.transaction.AbstractSingleResourceTransaction;
 16  
 import org.mule.transaction.IllegalTransactionStateException;
 17  
 import org.mule.umo.TransactionException;
 18  
 
 19  
 import javax.jms.Connection;
 20  
 import javax.jms.JMSException;
 21  
 import javax.jms.Session;
 22  
 
 23  
 /**
 24  
  * <code>JmsTransaction</code> is a wrapper for a JMS local transaction. This
 25  
  * object holds the JMS session and controls when the transaction is committed or
 26  
  * rolled back.
 27  
  */
 28  0
 public class JmsTransaction extends AbstractSingleResourceTransaction
 29  
 {
 30  
 
 31  
     public void bindResource(Object key, Object resource) throws TransactionException
 32  
     {
 33  0
         if (!(key instanceof Connection) || !(resource instanceof Session))
 34  
         {
 35  0
             throw new IllegalTransactionStateException(
 36  
                 CoreMessages.transactionCanOnlyBindToResources("javax.jms.Connection/javax.jms.Session"));
 37  
         }
 38  
 
 39  0
         Session session = (Session)resource;
 40  
         try
 41  
         {
 42  0
             if (!session.getTransacted())
 43  
             {
 44  0
                 throw new IllegalTransactionStateException(JmsMessages.sessionShouldBeTransacted());
 45  
             }
 46  
         }
 47  0
         catch (JMSException e)
 48  
         {
 49  0
             throw new IllegalTransactionStateException(CoreMessages.transactionCannotReadState(), e);
 50  0
         }
 51  
 
 52  0
         super.bindResource(key, resource);
 53  0
     }
 54  
 
 55  
     protected void doBegin() throws TransactionException
 56  
     {
 57  
         // do nothing
 58  0
     }
 59  
 
 60  
     protected void doCommit() throws TransactionException
 61  
     {
 62  
         try
 63  
         {
 64  0
             ((Session)resource).commit();
 65  
         }
 66  0
         catch (JMSException e)
 67  
         {
 68  0
             throw new TransactionException(CoreMessages.transactionCommitFailed(), e);
 69  0
         }
 70  0
     }
 71  
 
 72  
     protected void doRollback() throws TransactionException
 73  
     {
 74  
         try
 75  
         {
 76  0
             ((Session)resource).rollback();
 77  
         }
 78  0
         catch (JMSException e)
 79  
         {
 80  0
             throw new TransactionException(CoreMessages.transactionRollbackFailed(), e);
 81  0
         }
 82  0
     }
 83  
 }