KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > vm > VMTransaction


1 /*
2  * $Id: VMTransaction.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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.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 /**
24  * @author <a HREF="mailto:gnt@codehaus.org">Guillaume Nodet</a>
25  * @version $Revision: 3798 $
26  */

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     /*
38      * (non-Javadoc)
39      *
40      * @see org.mule.umo.UMOTransaction#bindResource(java.lang.Object,
41      * java.lang.Object)
42      */

43     public void bindResource(Object JavaDoc key, Object JavaDoc 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