KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > factory > 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.factory;
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
33 /**
34  * Comment
35  *
36  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
37  * @version $Revision: 40012 $
38  */

39 @Stateful JavaDoc
40 @Remote JavaDoc(Stateful1.class)
41 public class Stateful1Bean implements Stateful1, java.io.Serializable JavaDoc
42 {
43    @PersistenceContext(unitName="manager1", type =PersistenceContextType.EXTENDED) EntityManager manager1;
44    @PersistenceContext(unitName = "../session2.jar#manager2", type =PersistenceContextType.EXTENDED) EntityManager manager2;
45
46    Entity1 one;
47    Entity2 two;
48
49    public int create1()
50    {
51       one = new Entity1();
52       one.setString("oneManager");
53       manager1.persist(one);
54       return one.getId();
55    }
56
57    public int create2()
58    {
59       two = new Entity2();
60       two.setString("twoManager");
61       manager2.persist(two);
62       return two.getId();
63    }
64
65    public void update1()
66    {
67       one.setString("changed");
68    }
69
70    public void update2()
71    {
72       two.setString("changed");
73    }
74
75    @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
76    public void never()
77    {
78       one.setString("never");
79       two.setString("never");
80    }
81
82    @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
83    public void never2(Entity1 uno, Entity2 dos)
84    {
85       if (manager1.merge(uno) != one) throw new RuntimeException JavaDoc("NOT EQUAL!!");
86       if (!uno.getString().equals("never2")) throw new RuntimeException JavaDoc("NOT_EQUAL");
87       if (manager2.merge(dos) != two) throw new RuntimeException JavaDoc("NOT EQUAL!");
88       if (!dos.getString().equals("never2")) throw new RuntimeException JavaDoc("NOT_EQUAL");
89    }
90
91    @Remove JavaDoc
92    public void checkout()
93    {
94       /*
95       Entity1 uno = manager1.find(Entity1.class, one.getId());
96       if (uno != one) throw new RuntimeException("NOT EQUAL");
97       if (!uno.equals("never2")) throw new RuntimeException("NOT EQUAL");
98       manager1.flush();
99       manager2.flush();
100       */

101    }
102
103
104 }
105
Popular Tags