KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > recover > bean > XAResourceEnlisterBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.recover.bean;
23
24 import javax.ejb.EJBException JavaDoc;
25 import javax.naming.Context JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28 import javax.transaction.RollbackException JavaDoc;
29 import javax.transaction.SystemException JavaDoc;
30 import javax.transaction.Transaction JavaDoc;
31 import javax.transaction.TransactionManager JavaDoc;
32 import javax.transaction.xa.XAResource JavaDoc;
33
34 import org.jboss.logging.Logger;
35 import org.jboss.test.util.ejb.SessionSupport;
36 import org.jboss.tm.recovery.Recoverable;
37
38 /**
39  * A XAResourceEnlisterBean.
40  *
41  * @author <a HREF="reverbel@ime.usp.br">Francisco Reverbel</a>
42  * @version $Revision: 37406 $
43  */

44 public class XAResourceEnlisterBean
45       extends SessionSupport
46 {
47    private static final Logger log =
48       Logger.getLogger(XAResourceEnlisterBean.class);
49
50    private TransactionManager JavaDoc tm;
51    private Recoverable recoverable1;
52    private Recoverable recoverable2;
53    private Recoverable recoverable3;
54
55    public void ejbCreate()
56    {
57       try
58       {
59          Context JavaDoc ctx = new InitialContext JavaDoc();
60          tm = (TransactionManager JavaDoc) ctx.lookup("java:/TransactionManager");
61          recoverable1 = (Recoverable) ctx.lookup("DummyRecoverableProxy1");
62          recoverable2 = (Recoverable) ctx.lookup("DummyRecoverableProxy2");
63          recoverable3 = (Recoverable) ctx.lookup("DummyRecoverableProxy3");
64       }
65       catch (NamingException JavaDoc e)
66       {
67          throw new EJBException JavaDoc(e);
68       }
69    }
70
71    public void method()
72    {
73       log.info("method called");
74       try
75       {
76          Transaction JavaDoc tx = tm.getTransaction();
77          log.info("tx=" + tx);
78
79          XAResource JavaDoc xaRes1 = recoverable1.getResource();
80          tx.enlistResource(xaRes1);
81          log.info("enlisted xaRes1=" + xaRes1);
82          XAResource JavaDoc xaRes2 = recoverable2.getResource();
83          tx.enlistResource(xaRes2);
84          log.info("enlisted xaRes2=" + xaRes2);
85          XAResource JavaDoc xaRes3 = recoverable3.getResource();
86          tx.enlistResource(xaRes3);
87          log.info("enlisted xaRes3=" + xaRes3);
88       }
89       catch (SystemException JavaDoc e)
90       {
91          log.info(e);
92          throw new EJBException JavaDoc(e);
93       }
94       catch (RollbackException JavaDoc e)
95       {
96          log.info(e);
97          throw new EJBException JavaDoc(e);
98       }
99    }
100
101    public void enlistXAResource(int i)
102    {
103       log.info("enlistXAResrouce(" + i + ") called");
104       try
105       {
106          XAResource JavaDoc xaRes;
107          Transaction JavaDoc tx = tm.getTransaction();
108          log.info("tx=" + tx);
109          
110          switch (i)
111          {
112             case 1:
113                xaRes = recoverable1.getResource();
114                tx.enlistResource(xaRes);
115                log.info("enlisted xaRes1=" + xaRes);
116                break;
117             case 2:
118                xaRes = recoverable2.getResource();
119                tx.enlistResource(xaRes);
120                log.info("enlisted xaRes2=" + xaRes);
121                break;
122             case 3:
123                xaRes = recoverable3.getResource();
124                tx.enlistResource(xaRes);
125                log.info("enlisted xaRes3=" + xaRes);
126                break;
127             default:
128                throw new EJBException JavaDoc("There is no XAResource " + i);
129          }
130       }
131       catch (SystemException JavaDoc e)
132       {
133          log.info(e);
134          throw new EJBException JavaDoc(e);
135       }
136       catch (RollbackException JavaDoc e)
137       {
138          log.info(e);
139          throw new EJBException JavaDoc(e);
140       }
141       
142    }
143 }
144
Popular Tags