KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jca > ejb > UserTxSessionBean


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.jca.ejb;
23
24 import javax.ejb.EJBException JavaDoc;
25 import javax.ejb.SessionBean JavaDoc;
26 import javax.ejb.SessionContext JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28 import javax.transaction.UserTransaction JavaDoc;
29
30 import org.jboss.logging.Logger;
31 import org.jboss.test.jca.adapter.TestConnection;
32 import org.jboss.test.jca.adapter.TestConnectionFactory;
33
34 /**
35  * UserTxSessionBean.java
36  *
37  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
38  * @version <tt>$Revision: 37406 $</tt>
39  *
40  * @ejb.bean name="UserTxSession"
41  * jndi-name="UserTxSession"
42  * local-jndi-name="LocalUserTxSession"
43  * view-type="both"
44  * type="Stateless"
45  * transaction-type="Bean"
46  * @ejb.transaction type="NotSupported"
47  */

48 public class UserTxSessionBean
49    implements SessionBean JavaDoc
50 {
51
52    /** The serialVersionUID */
53    private static final long serialVersionUID = 1L;
54    private SessionContext JavaDoc ctx;
55    private Logger log = Logger.getLogger(getClass());
56
57    public UserTxSessionBean()
58    {
59       
60    }
61    
62    /**
63     * Describe <code>testUserTxJndi</code> method here.
64     *
65     * @return a <code>boolean</code> value
66     *
67     * @ejb:interface-method
68     */

69    public boolean testUserTxJndi()
70    {
71       try
72       {
73          TestConnectionFactory tcf = (TestConnectionFactory)new InitialContext JavaDoc().lookup("java:/JBossTestCF");
74          TestConnection tc = (TestConnection)tcf.getConnection();
75          UserTransaction JavaDoc ut = (UserTransaction JavaDoc)new InitialContext JavaDoc().lookup("UserTransaction");
76          ut.begin();
77          boolean result = tc.isInTx();
78          log.info("Jndi test, inTx: " + result);
79          ut.commit();
80          tc.close();
81          return result;
82       }
83       catch (Exception JavaDoc e)
84       {
85          throw new EJBException JavaDoc(e.getMessage());
86       }
87       
88    }
89
90    /**
91     * Describe <code>testUserTxSessionCtx</code> method here.
92     *
93     * @return a <code>boolean</code> value
94     *
95     * @ejb:interface-method
96     */

97    public boolean testUserTxSessionCtx()
98    {
99       try
100       {
101          TestConnectionFactory tcf = (TestConnectionFactory)new InitialContext JavaDoc().lookup("java:/JBossTestCF");
102          TestConnection tc = (TestConnection)tcf.getConnection();
103          UserTransaction JavaDoc ut = ctx.getUserTransaction();
104          ut.begin();
105          boolean result = tc.isInTx();
106          log.info("ctx test, inTx: " + result);
107          ut.commit();
108          tc.close();
109          return result;
110       }
111       catch (Exception JavaDoc e)
112       {
113          throw new EJBException JavaDoc(e.getMessage());
114       }
115       
116    }
117    
118    /**
119     * @ejb:interface-method
120     */

121    public void testUnclosedError() throws Exception JavaDoc
122    {
123       TestConnectionFactory tcf = (TestConnectionFactory)new InitialContext JavaDoc().lookup("java:/JBossTestCF");
124       tcf.getConnection(); // DONT CLOSE
125
}
126
127    public void ejbCreate()
128    {
129    }
130
131    public void ejbActivate()
132    {
133     }
134
135    public void ejbPassivate()
136    {
137    }
138
139    public void ejbRemove()
140    {
141    }
142
143    public void setSessionContext(SessionContext JavaDoc ctx)
144    {
145       this.ctx = ctx;
146    }
147
148    public void unsetSessionContext()
149    {
150       this.ctx = null;
151    }
152
153 }
154
Popular Tags