KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > arjuna > StatefulTxBean


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.arjuna;
23
24 import javax.ejb.Remote JavaDoc;
25 import javax.ejb.Stateful JavaDoc;
26 import javax.ejb.TransactionAttribute JavaDoc;
27 import javax.ejb.TransactionAttributeType JavaDoc;
28 import javax.persistence.EntityManager;
29 import javax.persistence.PersistenceContext;
30 import javax.transaction.TransactionManager JavaDoc;
31
32 import org.jboss.annotation.JndiInject;
33 import org.jboss.annotation.ejb.RemoteBinding;
34 import org.jboss.ejb3.test.arjuna.Entity;
35 import org.jboss.logging.Logger;
36
37 /**
38  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
39  */

40 @Stateful JavaDoc(name="StatefulTx")
41 @Remote JavaDoc(StatefulTx.class)
42 @RemoteBinding(jndiBinding = "StatefulTx")
43 @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
44 public class StatefulTxBean implements StatefulTx
45 {
46    private static final Logger log = Logger.getLogger(StatefulTxBean.class);
47    
48    @JndiInject(jndiName="java:/TransactionManager") private TransactionManager JavaDoc tm;
49    
50    @PersistenceContext private EntityManager manager;
51    
52    @TransactionAttribute JavaDoc(TransactionAttributeType.REQUIRES_NEW)
53    public boolean clear(Entity entity) throws javax.transaction.SystemException JavaDoc
54    {
55      entity = manager.find(Entity.class, entity.getId());
56      if (entity != null)
57         manager.remove(entity);
58      
59      return getReturn();
60    }
61    
62    @TransactionAttribute JavaDoc(TransactionAttributeType.REQUIRES_NEW)
63    public boolean persist(Entity entity) throws javax.transaction.SystemException JavaDoc
64    {
65       manager.persist(entity);
66       
67       return getReturn();
68    }
69     
70    @TransactionAttribute JavaDoc(TransactionAttributeType.REQUIRED)
71    public boolean isArjunaTransactedRequired() throws javax.transaction.SystemException JavaDoc
72    {
73       return getReturn();
74    }
75    
76    @TransactionAttribute JavaDoc(TransactionAttributeType.REQUIRES_NEW)
77    public boolean isArjunaTransactedRequiresNew() throws javax.transaction.SystemException JavaDoc
78    {
79       return getReturn();
80    }
81    
82    protected boolean getReturn() throws javax.transaction.SystemException JavaDoc
83    {
84       if (tm.getTransaction() == null)
85          return false;
86       
87       if (!tm.getClass().toString().contains("arjuna"))
88          return false;
89       
90       if (!tm.getTransaction().getClass().toString().contains("arjuna"))
91          return false;
92       
93       return true;
94    }
95
96 }
97
Popular Tags