1 10 11 package org.mule.providers.vm; 12 13 import org.mule.MuleManager; 14 import org.mule.config.i18n.Message; 15 import org.mule.config.i18n.Messages; 16 import org.mule.transaction.AbstractSingleResourceTransaction; 17 import org.mule.transaction.IllegalTransactionStateException; 18 import org.mule.umo.TransactionException; 19 import org.mule.util.queue.QueueManager; 20 import org.mule.util.queue.QueueSession; 21 import org.mule.util.xa.ResourceManagerException; 22 23 27 public class VMTransaction extends AbstractSingleResourceTransaction 28 { 29 30 public VMTransaction() throws TransactionException 31 { 32 QueueManager qm = MuleManager.getInstance().getQueueManager(); 33 QueueSession qs = qm.getQueueSession(); 34 bindResource(qm, qs); 35 } 36 37 43 public void bindResource(Object key, Object resource) throws TransactionException 44 { 45 if (!(key instanceof QueueManager) || !(resource instanceof QueueSession)) 46 { 47 throw new IllegalTransactionStateException(new Message( 48 Messages.TX_CAN_ONLY_BIND_TO_X_TYPE_RESOURCES, "QueueManager/QueueSession")); 49 } 50 super.bindResource(key, resource); 51 } 52 53 protected void doBegin() throws TransactionException 54 { 55 try 56 { 57 ((QueueSession)resource).begin(); 58 } 59 catch (ResourceManagerException e) 60 { 61 throw new TransactionException( 62 new Message(Messages.TX_CANT_START_X_TRANSACTION, "VMTransaction"), e); 63 } 64 } 65 66 protected void doCommit() throws TransactionException 67 { 68 try 69 { 70 ((QueueSession)resource).commit(); 71 } 72 catch (ResourceManagerException e) 73 { 74 throw new TransactionException(new Message(Messages.TX_COMMIT_FAILED), e); 75 } 76 } 77 78 protected void doRollback() throws TransactionException 79 { 80 try 81 { 82 ((QueueSession)resource).rollback(); 83 } 84 catch (ResourceManagerException e) 85 { 86 throw new TransactionException(new Message(Messages.TX_ROLLBACK_FAILED), e); 87 } 88 } 89 90 } 91 | Popular Tags |