KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > initial > TestBean


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.ejb3.test.initial;
23
24 import java.util.Map JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import javax.ejb.Stateless JavaDoc;
27 import javax.ejb.TransactionAttribute JavaDoc;
28 import javax.ejb.TransactionAttributeType JavaDoc;
29 import javax.transaction.Transaction JavaDoc;
30 import javax.transaction.TransactionManager JavaDoc;
31 import org.jboss.annotation.JndiInject;
32
33 /**
34  * Comment
35  *
36  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
37  * @version $Revision: 37459 $
38  */

39 @Stateless JavaDoc
40 public class TestBean implements TestLocal, TestRemote
41 {
42    private TransactionManager JavaDoc tm;
43    public static Map JavaDoc obj = new HashMap JavaDoc();
44
45    public Map JavaDoc getObject()
46    {
47       return obj;
48    }
49
50    public Object JavaDoc echo(Object JavaDoc e)
51    {
52       return e;
53    }
54
55    @JndiInject(jndiName = "java:/TransactionManager")
56    public void setTransactionManager(TransactionManager JavaDoc tm)
57    {
58       this.tm = tm;
59       System.out.println("TransactionManager set: " + tm);
60    }
61
62    public String JavaDoc testMe(String JavaDoc echo)
63    {
64       System.out.println("JDK15 testMe worked");
65       return echo;
66    }
67
68    @TransactionAttribute JavaDoc(TransactionAttributeType.NEVER)
69    public void never()
70    {
71    }
72
73    @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
74    public void notSupported() throws Exception JavaDoc
75    {
76       if (tm.getTransaction() != null) throw new Exception JavaDoc("notsupported() method has tx set");
77    }
78
79    @TransactionAttribute JavaDoc(TransactionAttributeType.SUPPORTS)
80    public void supports(Transaction JavaDoc tx) throws Exception JavaDoc
81    {
82       Transaction JavaDoc tmTx = tm.getTransaction();
83       if (tx != tmTx) throw new Exception JavaDoc("supports didn't work");
84    }
85
86    @TransactionAttribute JavaDoc(TransactionAttributeType.REQUIRED)
87    public void required() throws Exception JavaDoc
88    {
89       if (tm.getTransaction() == null) throw new Exception JavaDoc("rquired() method has no tx set");
90    }
91
92
93    @TransactionAttribute JavaDoc(TransactionAttributeType.REQUIRES_NEW)
94    public void requiresNew(Transaction JavaDoc tx) throws Exception JavaDoc
95    {
96       Transaction JavaDoc tmTx = tm.getTransaction();
97       if (tx == tmTx || (tx != null && tx.equals(tmTx)))
98          throw new Exception JavaDoc("transactions shouldn't be equal");
99       if (tmTx == null) throw new Exception JavaDoc("tx is null in RequiresNew");
100    }
101
102
103    @TransactionAttribute JavaDoc(TransactionAttributeType.MANDATORY)
104    public void mandatory()
105    {
106    }
107 }
108
109
110
111
Popular Tags