KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > standalone > flushmodenever > Stateful1Bean


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.standalone.flushmodenever;
23
24 import javax.ejb.Remote JavaDoc;
25 import javax.ejb.Remove JavaDoc;
26 import javax.ejb.Stateful JavaDoc;
27 import javax.ejb.TransactionAttribute JavaDoc;
28 import javax.ejb.TransactionAttributeType JavaDoc;
29 import javax.persistence.EntityManager;
30 import javax.persistence.PersistenceContext;
31 import javax.persistence.PersistenceContextType;
32 import javax.transaction.TransactionManager JavaDoc;
33 import javax.transaction.Transaction JavaDoc;
34 import javax.transaction.SystemException JavaDoc;
35 import org.jboss.annotation.JndiInject;
36 import org.jboss.ejb3.entity.ExtendedEntityManager;
37
38 /**
39  * Comment
40  *
41  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
42  * @version $Revision: 42263 $
43  */

44 @Stateful JavaDoc
45 @Remote JavaDoc(Stateful1.class)
46 public class Stateful1Bean implements Stateful1, java.io.Serializable JavaDoc
47 {
48    @PersistenceContext(unitName="manager1", type =PersistenceContextType.EXTENDED) EntityManager manager1;
49    @PersistenceContext(unitName = "../flushmodenever-session2.jar#manager2", type =PersistenceContextType.EXTENDED) EntityManager manager2;
50
51    Entity1 one;
52    Entity2 two;
53
54    @JndiInject(jndiName="java:/TransactionManager") TransactionManager JavaDoc tm;
55
56    public int create1()
57    {
58       one = new Entity1();
59       one.setString("oneManager");
60       if (!(manager1 instanceof ExtendedEntityManager)) throw new RuntimeException JavaDoc("assert failed");
61       manager1.persist(one);
62       return one.getId();
63    }
64
65    public int create2()
66    {
67       two = new Entity2();
68       two.setString("twoManager");
69       manager2.persist(two);
70       return two.getId();
71    }
72
73    public void update1()
74    {
75       if (!manager1.contains(one)) throw new RuntimeException JavaDoc("assert failed");
76       one.setString("changed");
77    }
78
79    public void update2()
80    {
81       if (!manager2.contains(two)) throw new RuntimeException JavaDoc("assert failed");
82       two.setString("changed");
83    }
84
85    @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
86    public void never()
87    {
88       one.setString("never");
89       two.setString("never");
90    }
91
92    @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
93    public void never2(Entity1 uno, Entity2 dos)
94    {
95       Transaction JavaDoc tx = null;
96       try
97       {
98          tx = tm.getTransaction();
99       }
100       catch (SystemException JavaDoc e)
101       {
102          throw new RuntimeException JavaDoc(e);
103       }
104       if (tx != null) throw new RuntimeException JavaDoc("TRANSACTION IS NOT NULL!");
105       if (manager1.merge(uno) != one) throw new RuntimeException JavaDoc("NOT EQUAL!!");
106       if (!uno.getString().equals("never2")) throw new RuntimeException JavaDoc("NOT_EQUAL");
107       if (manager2.merge(dos) != two) throw new RuntimeException JavaDoc("NOT EQUAL!");
108       if (!dos.getString().equals("never2")) throw new RuntimeException JavaDoc("NOT_EQUAL");
109    }
110
111    @Remove JavaDoc
112    public void checkout()
113    {
114       /*
115       Entity1 uno = manager1.find(Entity1.class, one.getId());
116       if (uno != one) throw new RuntimeException("NOT EQUAL");
117       if (!uno.equals("never2")) throw new RuntimeException("NOT EQUAL");
118       manager1.flush();
119       manager2.flush();
120       */

121    }
122
123
124 }
125
Popular Tags