1 10 11 package org.mule.providers.jms; 12 13 import javax.jms.Connection ; 14 import javax.jms.JMSException ; 15 import javax.jms.Session ; 16 17 import org.mule.config.i18n.Message; 18 import org.mule.config.i18n.Messages; 19 import org.mule.transaction.AbstractSingleResourceTransaction; 20 import org.mule.transaction.IllegalTransactionStateException; 21 import org.mule.umo.TransactionException; 22 23 28 public class JmsTransaction extends AbstractSingleResourceTransaction 29 { 30 31 37 public void bindResource(Object key, Object resource) throws TransactionException 38 { 39 if (!(key instanceof Connection ) || !(resource instanceof Session )) 40 { 41 throw new IllegalTransactionStateException(new Message( 42 Messages.TX_CAN_ONLY_BIND_TO_X_TYPE_RESOURCES, "javax.jms.Connection/javax.jms.Session")); 43 } 44 45 Session session = (Session )resource; 46 try 47 { 48 if (!session.getTransacted()) 49 { 50 throw new IllegalTransactionStateException(new Message("jms", 4)); 51 } 52 } 53 catch (JMSException e) 54 { 55 throw new IllegalTransactionStateException(new Message(Messages.TX_CANT_READ_STATE), e); 56 } 57 58 super.bindResource(key, resource); 59 } 60 61 66 protected void doBegin() throws TransactionException 67 { 68 } 70 71 76 protected void doCommit() throws TransactionException 77 { 78 try 79 { 80 ((Session )resource).commit(); 81 } 82 catch (JMSException e) 83 { 84 throw new TransactionException(new Message(Messages.TX_COMMIT_FAILED), e); 85 } 86 } 87 88 93 protected void doRollback() throws TransactionException 94 { 95 try 96 { 97 ((Session )resource).rollback(); 98 } 99 catch (JMSException e) 100 { 101 throw new TransactionException(new Message(Messages.TX_ROLLBACK_FAILED), e); 102 } 103 } 104 105 } 106 | Popular Tags |