KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > factoryxml > 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.factoryxml;
23
24 import javax.persistence.EntityManager;
25 import javax.persistence.EntityManagerFactory;
26 import javax.persistence.PersistenceContext;
27 import javax.persistence.PersistenceUnit;
28 import org.hibernate.Session;
29 import org.hibernate.SessionFactory;
30
31 /**
32  * Comment
33  *
34  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
35  * @version $Revision: 40012 $
36  */

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