KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > clusteredsession > 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.clusteredsession;
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 import org.jboss.annotation.ejb.Clustered;
37
38 /**
39  * comment
40  *
41  * @author Ben Wang
42  */

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