KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > extended > bean > ShoppingCartBean


1 package org.jboss.tutorial.extended.bean;
2
3 import javax.annotation.EJB;
4 import javax.ejb.Remote JavaDoc;
5 import javax.ejb.Remove JavaDoc;
6 import javax.ejb.Stateful JavaDoc;
7 import javax.persistence.EntityManager;
8 import javax.persistence.FlushMode;
9 import javax.persistence.FlushModeType;
10 import javax.persistence.PersistenceContext;
11 import javax.persistence.PersistenceContextType;
12
13 /**
14  * comment
15  *
16  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
17  */

18 @Stateful JavaDoc
19 @Remote JavaDoc(ShoppingCart.class)
20 public class ShoppingCartBean implements ShoppingCart
21 {
22    @PersistenceContext(type=PersistenceContextType.EXTENDED) EntityManager em;
23
24    @EJB StatelessLocal stateless;
25
26    private Customer customer;
27
28    public long createCustomer()
29    {
30       customer = new Customer();
31       customer.setName("William");
32       em.persist(customer);
33       return customer.getId();
34    }
35
36    public void update()
37    {
38       customer.setName("Bill");
39    }
40    public void update2()
41    {
42       customer.setName("Billy");
43    }
44
45    public void update3()
46    {
47       stateless.update(customer);
48    }
49
50    public Customer find(long id)
51    {
52       return em.find(Customer.class, id);
53    }
54
55    @FlushMode(FlushModeType.NEVER)
56    public void never()
57    {
58       customer.setName("Bob");
59    }
60
61    
62
63    @Remove JavaDoc
64    public void checkout()
65    {
66       em.flush();
67    }
68 }
69
Popular Tags