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 javax.ejb.EJB;
025: import javax.ejb.Remote;
026: import javax.ejb.Remove;
027: import javax.ejb.Stateful;
028: import javax.ejb.TransactionAttribute;
029: import javax.ejb.TransactionAttributeType;
030: import javax.persistence.PersistenceContext;
031: import javax.persistence.PersistenceContextType;
032: import org.hibernate.Session;
033: import org.jboss.annotation.ejb.RemoteBinding;
034:
035: /**
036: * comment
037: *
038: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
039: */
040: @Stateful
041: @Remote(ShoppingCart.class)
042: @RemoteBinding(jndiBinding="HibernateShoppingCart")
043: public class HibernateShoppingCartBean implements ShoppingCart {
044: @PersistenceContext(type=PersistenceContextType.EXTENDED)
045: Session em;
046:
047: @EJB
048: StatelessLocal stateless;
049:
050: @EJB
051: private Contained contained;
052:
053: private Customer customer;
054:
055: public long createCustomer() {
056: customer = new Customer();
057: customer.setName("William");
058: em.save(customer);
059: System.out.println("********* created *****");
060: return customer.getId();
061: }
062:
063: public boolean isContainedActivated() {
064: return false;
065: }
066:
067: public void update() {
068: System.out.println("********* update() *****");
069: customer.setName("Bill");
070: }
071:
072: public void update2() {
073: customer.setName("Billy");
074: }
075:
076: public void update3() {
077: stateless.update(customer);
078: }
079:
080: public Customer find(long id) {
081: return (Customer) em.get(Customer.class, new Long(id));
082: }
083:
084: public void findAndUpdateStateless() {
085: stateless.findAndUpdate(customer.getId());
086: if (!customer.getName().equals("stateless modified"))
087: throw new RuntimeException(
088: "stateless didn't get propagated pc");
089: }
090:
091: @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
092: public void never() {
093: customer.setName("Bob");
094: }
095:
096: public void updateContained() {
097: contained.updateCustomer();
098: }
099:
100: public void setContainedCustomer() {
101: contained.setCustomer(customer.getId());
102: }
103:
104: public void checkContainedCustomer() {
105: if (contained.getCustomer() != customer)
106: throw new RuntimeException("not same customer");
107: }
108:
109: @Remove
110: public void checkout() {
111: System.out.println("HibernateShoppingCartBean.checkout");
112: // Wolf: with EJBTHREE-896 we become responsible for the lifecycle of nested beans
113: contained.checkout();
114: }
115: }
|