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.persistence.PersistenceContext;
026: import javax.persistence.PersistenceContextType;
027: import javax.persistence.EntityManager;
028: import javax.annotation.PreDestroy;
029: import javax.ejb.Remove;
030: import javax.ejb.Stateful;
031: import javax.ejb.PrePassivate;
032: import javax.ejb.PostActivate;
033:
034: import org.jboss.annotation.ejb.cache.simple.CacheConfig;
035:
036: /**
037: * Comment
038: *
039: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
040: * @version $Revision: 61024 $
041: */
042: @Stateful
043: @CacheConfig(maxSize=1000,idleTimeoutSeconds=2)
044: public class ContainedBean implements Contained, Serializable {
045: private static final long serialVersionUID = 1L;
046:
047: @PersistenceContext(type=PersistenceContextType.EXTENDED)
048: EntityManager em;
049:
050: Customer customer;
051:
052: public Customer find(long id) {
053: return em.find(Customer.class, id);
054: }
055:
056: public void setCustomer(long id) {
057: customer = find(id);
058: }
059:
060: public Customer getCustomer() {
061: return customer;
062: }
063:
064: public void updateCustomer() {
065: customer.setName("contained modified");
066: }
067:
068: public boolean isActivated() {
069: return activated;
070: }
071:
072: public static boolean destroyed = false;
073: public static boolean passivated = false;
074: public static boolean activate = false;
075: private boolean activated = false;
076:
077: @PrePassivate
078: public void passivate() {
079: passivated = true;
080: }
081:
082: @PostActivate
083: public void activate() {
084: System.out.println("*********** ACTIVATED *****************");
085: if (activated)
086: throw new RuntimeException("ACTIVATED TWICE");
087: activated = true;
088: if (activate)
089: throw new RuntimeException(
090: "ACTIVATED TWIC IN TWO DIFFERENT INSTANCES");
091: activate = true;
092:
093: }
094:
095: @PreDestroy
096: public void preDestroy() {
097: System.out.println("ContainedBean.preDestroy");
098: destroyed = true;
099: }
100:
101: @Remove
102: public void checkout() {
103: System.out.println("ContainedBean.checkout");
104: }
105: }
|