KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.Serializable JavaDoc;
25 import javax.ejb.EJB JavaDoc;
26 import javax.ejb.Remote JavaDoc;
27 import javax.ejb.Remove JavaDoc;
28 import javax.ejb.Stateful JavaDoc;
29 import javax.ejb.TransactionAttribute JavaDoc;
30 import javax.ejb.TransactionAttributeType JavaDoc;
31 import javax.ejb.PostActivate JavaDoc;
32 import javax.persistence.EntityManager;
33 import javax.persistence.PersistenceContext;
34 import javax.persistence.PersistenceContextType;
35 import org.jboss.annotation.ejb.cache.simple.CacheConfig;
36
37 /**
38  * comment
39  *
40  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
41  */

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