001: /*
002: * JBoss, Home of Professional Open Source
003: * Copyright 2005, JBoss Inc., and individual contributors as indicated
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * 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.stateful.nested.base.xpc;
023:
024: import java.rmi.dgc.VMID;
025:
026: import javax.ejb.EJB;
027: import javax.ejb.Remove;
028: import javax.ejb.TransactionAttribute;
029: import javax.ejb.TransactionAttributeType;
030: import javax.persistence.EntityManager;
031: import javax.persistence.PersistenceContext;
032: import javax.persistence.PersistenceContextType;
033:
034: import org.jboss.ejb3.test.stateful.nested.base.MidLevel;
035: import org.jboss.ejb3.test.stateful.nested.base.PassivationActivationWatcherBean;
036: import org.jboss.ejb3.test.stateful.nested.base.VMTracker;
037:
038: /**
039: * Base SFSB for use in ExtendedPersistenceContext testing.
040: *
041: * @author Ben Wang
042: */
043: public class ShoppingCartBean extends PassivationActivationWatcherBean
044: implements ShoppingCart {
045: /** The serialVersionUID */
046: private static final long serialVersionUID = 1L;
047:
048: @PersistenceContext(unitName="tempdb",type=PersistenceContextType.EXTENDED)
049: private EntityManager em;
050:
051: private Customer customer;
052:
053: @EJB(beanName="testShoppingCartContained")
054: private Contained contained;
055:
056: @EJB(beanName="testLocalShoppingCartContained")
057: private Contained localContained;
058:
059: @EJB
060: private NestedStatelessLocal stateless;
061:
062: public VMID getVMID() {
063: return VMTracker.VMID;
064: }
065:
066: public MidLevel getLocalNested() {
067: return localContained;
068: }
069:
070: public MidLevel getNested() {
071: return contained;
072: }
073:
074: public long createCustomer() {
075: customer = new Customer();
076: customer.setName("William");
077: em.persist(customer);
078: System.out.println("********* created *****");
079: return customer.getId();
080: }
081:
082: public void setCustomer(long id) {
083: customer = find(id);
084: }
085:
086: public void setContainedCustomer() {
087: localContained.setCustomer(customer.getId());
088: }
089:
090: public boolean checkContainedCustomer() {
091: return (localContained.getCustomer() == customer);
092: }
093:
094: public void updateContained() {
095: localContained.updateCustomer();
096: }
097:
098: public void update() {
099: System.out.println("********* update() *****");
100: customer.setName("Bill");
101: }
102:
103: public void update2() {
104: customer.setName("Billy");
105: }
106:
107: public void update3() {
108: stateless.update(customer);
109: }
110:
111: public void findAndUpdateStateless() {
112: stateless.findAndUpdate(customer.getId());
113: if (!customer.getName().equals("stateless modified"))
114: throw new RuntimeException(
115: "stateless didn't get propagated pc");
116: }
117:
118: public Customer find(long id) {
119: return em.find(Customer.class, id);
120: }
121:
122: @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
123: public void never() {
124: customer.setName("Bob");
125: }
126:
127: public void reset() {
128: super .reset();
129: contained.reset();
130: localContained.reset();
131: }
132:
133: @Remove
134: public void remove() {
135: }
136:
137: public void setUpFailover(String failover) {
138: // To setup the failover property
139: log.debug("Setting up failover property: " + failover);
140: System.setProperty("JBossCluster-DoFail", failover);
141: }
142: }
|