001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3.test.longlived;
023:
024: import java.io.Serializable;
025: import javax.ejb.EJB;
026: import javax.ejb.Remote;
027: import javax.ejb.Remove;
028: import javax.ejb.Stateful;
029: import javax.ejb.TransactionAttribute;
030: import javax.ejb.TransactionAttributeType;
031: import javax.ejb.PostActivate;
032: import javax.persistence.EntityManager;
033: import javax.persistence.PersistenceContext;
034: import javax.persistence.PersistenceContextType;
035: import org.jboss.annotation.ejb.cache.simple.CacheConfig;
036:
037: /**
038: * comment
039: *
040: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
041: */
042: @Stateful
043: @Remote(ShoppingCart.class)
044: @CacheConfig(maxSize=1000,idleTimeoutSeconds=2)
045: public class ShoppingCartBean implements ShoppingCart, Serializable {
046: @PersistenceContext(type=PersistenceContextType.EXTENDED)
047: EntityManager em;
048:
049: @EJB
050: StatelessLocal stateless;
051:
052: private Customer customer;
053:
054: @EJB
055: private Contained contained;
056:
057: public long createCustomer() {
058: customer = new Customer();
059: customer.setName("William");
060: em.persist(customer);
061: System.out.println("********* created *****");
062: return customer.getId();
063: }
064:
065: public void setContainedCustomer() {
066: contained.setCustomer(customer.getId());
067: }
068:
069: public void checkContainedCustomer() {
070: if (contained.getCustomer() != customer)
071: throw new RuntimeException("not same customer");
072: }
073:
074: public boolean isContainedActivated() {
075: return contained.isActivated();
076: }
077:
078: public void updateContained() {
079: contained.updateCustomer();
080: }
081:
082: public void update() {
083: System.out.println("********* update() *****");
084: customer.setName("Bill");
085: }
086:
087: public void update2() {
088: customer.setName("Billy");
089: }
090:
091: public void update3() {
092: stateless.update(customer);
093: }
094:
095: public void findAndUpdateStateless() {
096: stateless.findAndUpdate(customer.getId());
097: if (!customer.getName().equals("stateless modified"))
098: throw new RuntimeException(
099: "stateless didn't get propagated pc");
100: }
101:
102: public Customer find(long id) {
103: return em.find(Customer.class, id);
104: }
105:
106: @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
107: public void never() {
108: customer.setName("Bob");
109: }
110:
111: @PostActivate
112: public void activate() {
113: System.out.println("*********** ACTIVATED *****************");
114: }
115:
116: @Remove
117: public void checkout() {
118: contained.checkout();
119: }
120: }
|