KickJava   Java API By Example, From Geeks To Geeks.

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


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.Stateless JavaDoc;
26 import javax.ejb.EJB JavaDoc;
27 import javax.persistence.EntityManager;
28 import javax.persistence.EntityManagerFactory;
29 import javax.persistence.PersistenceContext;
30 import javax.persistence.PersistenceUnit;
31 import org.hibernate.SessionFactory;
32 import org.hibernate.Session;
33
34 /**
35  * Comment
36  *
37  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
38  * @version $Revision: 45473 $
39  */

40 @Stateless JavaDoc
41 @Remote JavaDoc(Session1.class)
42 public class Session1Bean implements Session1
43 {
44    @PersistenceContext(unitName="manager1") Session manager1;
45    @PersistenceContext(unitName="../flushmodenever-session2.jar#manager2") EntityManager manager2;
46    @PersistenceUnit(unitName="manager1") SessionFactory factory1;
47    @PersistenceUnit(unitName="../flushmodenever-session2.jar#manager2") EntityManagerFactory factory2;
48    @EJB JavaDoc Session2 session2;
49
50    public int create1FromManager()
51    {
52       Entity1 one = new Entity1();
53       one.setString("oneManager");
54       manager1.save(one);
55       return one.getId();
56    }
57    public int create1FromFactory()
58    {
59       Entity1 one = new Entity1();
60       Session m = factory1.openSession();
61       m.save(one);
62       // leak m.close();
63
return one.getId();
64    }
65
66    public int create2FromManager()
67    {
68       Entity2 two = new Entity2();
69       two.setString("twoManager");
70       manager2.persist(two);
71       return two.getId();
72    }
73    public int create2FromFactory()
74    {
75       Entity2 two = new Entity2();
76       EntityManager m = factory2.createEntityManager();
77       m.persist(two);
78       // leak m.close();
79
return two.getId();
80    }
81
82    public void doUtil(Util ux)
83    {
84       Util u = new Util();
85       u.setId(1);
86       u.setName("one");
87       manager1.persist(u);
88
89       u = new Util();
90       u.setId(2);
91       u.setName("two");
92       manager2.persist(u);
93    }
94
95 }
96
Popular Tags