01: /*
02: * JBoss, Home of Professional Open Source
03: * Copyright 2005, JBoss Inc., and individual contributors as indicated
04: * by the @authors tag. See the copyright.txt in the distribution for a
05: * full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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;
25: import javax.ejb.Stateful;
26: import javax.ejb.TransactionAttribute;
27: import javax.ejb.TransactionAttributeType;
28: import javax.persistence.EntityManager;
29: import javax.persistence.PersistenceContext;
30: import javax.transaction.TransactionManager;
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(name="StatefulTx")
41: @Remote(StatefulTx.class)
42: @RemoteBinding(jndiBinding="StatefulTx")
43: @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
44: public class StatefulTxBean implements StatefulTx {
45: private static final Logger log = Logger
46: .getLogger(StatefulTxBean.class);
47:
48: @JndiInject(jndiName="java:/TransactionManager")
49: private TransactionManager tm;
50:
51: @PersistenceContext
52: private EntityManager manager;
53:
54: @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
55: public boolean clear(Entity entity)
56: throws javax.transaction.SystemException {
57: entity = manager.find(Entity.class, entity.getId());
58: if (entity != null)
59: manager.remove(entity);
60:
61: return getReturn();
62: }
63:
64: @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
65: public boolean persist(Entity entity)
66: throws javax.transaction.SystemException {
67: manager.persist(entity);
68:
69: return getReturn();
70: }
71:
72: @TransactionAttribute(TransactionAttributeType.REQUIRED)
73: public boolean isArjunaTransactedRequired()
74: throws javax.transaction.SystemException {
75: return getReturn();
76: }
77:
78: @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
79: public boolean isArjunaTransactedRequiresNew()
80: throws javax.transaction.SystemException {
81: return getReturn();
82: }
83:
84: protected boolean getReturn()
85: throws javax.transaction.SystemException {
86: if (tm.getTransaction() == null)
87: return false;
88:
89: if (!tm.getClass().toString().contains("arjuna"))
90: return false;
91:
92: if (!tm.getTransaction().getClass().toString().contains(
93: "arjuna"))
94: return false;
95:
96: return true;
97: }
98:
99: }
|