KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > longlived > HibernateShoppingCartBean


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.longlived;
23
24 import javax.ejb.EJB JavaDoc;
25 import javax.ejb.Remote JavaDoc;
26 import javax.ejb.Remove JavaDoc;
27 import javax.ejb.Stateful JavaDoc;
28 import javax.ejb.TransactionAttribute JavaDoc;
29 import javax.ejb.TransactionAttributeType JavaDoc;
30 import javax.persistence.PersistenceContext;
31 import javax.persistence.PersistenceContextType;
32 import org.hibernate.Session;
33 import org.jboss.annotation.ejb.RemoteBinding;
34
35 /**
36  * comment
37  *
38  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
39  */

40 @Stateful JavaDoc
41 @Remote JavaDoc(ShoppingCart.class)
42 @RemoteBinding(jndiBinding = "HibernateShoppingCart")
43 public class HibernateShoppingCartBean implements ShoppingCart
44 {
45    @PersistenceContext(type=PersistenceContextType.EXTENDED) Session em;
46
47    @EJB JavaDoc StatelessLocal stateless;
48
49    @EJB JavaDoc private Contained contained;
50
51    private Customer customer;
52
53    public long createCustomer()
54    {
55       customer = new Customer();
56       customer.setName("William");
57       em.save(customer);
58       System.out.println("********* created *****");
59       return customer.getId();
60    }
61
62    public boolean isContainedActivated()
63    {
64       return false;
65    }
66
67    public void update()
68    {
69       System.out.println("********* update() *****");
70       customer.setName("Bill");
71    }
72    public void update2()
73    {
74       customer.setName("Billy");
75    }
76
77    public void update3()
78    {
79       stateless.update(customer);
80    }
81
82    public Customer find(long id)
83    {
84       return (Customer)em.get(Customer.class, new Long JavaDoc(id));
85    }
86
87    public void findAndUpdateStateless()
88    {
89       stateless.findAndUpdate(customer.getId());
90       if (!customer.getName().equals("stateless modified")) throw new RuntimeException JavaDoc("stateless didn't get propagated pc");
91    }
92
93    @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
94    public void never()
95    {
96       customer.setName("Bob");
97    }
98
99    public void updateContained()
100    {
101       contained.updateCustomer();
102    }
103
104    public void setContainedCustomer()
105    {
106       contained.setCustomer(customer.getId());
107    }
108
109    public void checkContainedCustomer()
110    {
111       if (contained.getCustomer() != customer) throw new RuntimeException JavaDoc("not same customer");
112    }
113
114
115
116
117    @Remove JavaDoc
118    public void checkout() {}
119 }
120
Popular Tags