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.test.cmp2.passivation.ejb;
023:
024: import java.rmi.RemoteException;
025:
026: import javax.ejb.CreateException;
027: import javax.ejb.EJBException;
028: import javax.ejb.EntityBean;
029: import javax.ejb.EntityContext;
030: import javax.ejb.RemoveException;
031: import javax.ejb.EJBObject;
032: import javax.ejb.EJBLocalObject;
033:
034: import org.jboss.logging.Logger;
035:
036: /**
037: * An entity bean to test the entity activation/passivation mechanism
038: * provided by JBoss.
039: *
040: * It is associated with a container configuration which causes it to be passivated shortly
041: * after it has been accessed.
042: *
043: * It has been designed to expose the bug described at
044: * <a href="https://sourceforge.net/tracker/?group_id=22866&atid=376685&func=detail&aid=742197">
045: * Detail:769139 entityCtx.getEJBLocalObject() returns wrong instance</a>
046: * and
047: * <a href="https://sourceforge.net/tracker/?func=detail&atid=376685&aid=769139&group_id=22866">
048: * Detail:742197 getEJBLocalObject() bug</a>
049: *
050: * @ejb.bean
051: * name="RapidlyPassivatedEntity"
052: * jndi-name="ejb/remote/RapidlyPassivatedEntity"
053: * local-jndi-name="ejb/local/RapidlyPassivatedEntity"
054: * view-type="both"
055: * type="CMP"
056: * reentrant="false"
057: * cmp-version="2.x"
058: * @ejb.pk
059: * class="java.lang.Object"
060: * @jboss.create-table "true"
061: * @jboss.remove-table "true"
062: * @jboss.unknown-pk
063: * class="java.lang.String"
064: * @jboss.entity-command
065: * name="key-generator"
066: * @jboss.container-configuration
067: * name="Short lived CMP 2.0 Entity Bean"
068: *
069: * @author <a href="mailto:steve@resolvesw.com">Steve Coy</a>
070: */
071: public abstract class RapidlyPassivatedEntityBean implements EntityBean {
072: // Attributes ----------------------------------------------------
073:
074: private static Logger log = Logger
075: .getLogger(RapidlyPassivatedEntityBean.class);
076:
077: private EntityContext mEntityContext;
078:
079: // Entity Attributes ----------------------------------------------------
080:
081: /**
082: * @ejb.persistent-field
083: * @ejb.interface-method
084: */
085: public abstract String getData();
086:
087: public abstract void setData(String data);
088:
089: // Business Methods ----------------------------------------------------
090:
091: /**
092: * Return the pk of the object returned by {@link EntityContext#getEJBLocalObject}
093: * @ejb.interface-method
094: */
095: public Object getIdViaEJBLocalObject() {
096: Object key = mEntityContext.getPrimaryKey();
097: EJBLocalObject local = mEntityContext.getEJBLocalObject();
098: Object lkey = local.getPrimaryKey();
099: log.info("key: " + key + ", lkey: " + lkey + ", local: "
100: + local);
101: return (Object) mEntityContext.getEJBLocalObject()
102: .getPrimaryKey();
103: }
104:
105: /**
106: * Return the pk of the object returned by {@link EntityContext#getEJBObject}
107: * @ejb.interface-method
108: */
109: public Object getIdViaEJBObject() {
110: try {
111: return (Object) mEntityContext.getEJBObject()
112: .getPrimaryKey();
113: } catch (RemoteException e) {
114: throw new EJBException(e);
115: }
116: }
117:
118: // EJB Implementation ----------------------------------------------------
119:
120: /**
121: * @ejb.create-method
122: */
123: public Object ejbCreate(String s) throws CreateException {
124: setData(s);
125: return null; // as required by CMP 2.0 spec
126: }
127:
128: public void ejbPostCreate(String s) {
129: log.info("ejbPostCreate, ctx:" + mEntityContext + ", pk:"
130: + mEntityContext.getPrimaryKey() + ", local:"
131: + mEntityContext.getEJBLocalObject());
132: }
133:
134: public void ejbActivate() throws EJBException, RemoteException {
135: log.info("ejbActivate, ctx:" + mEntityContext + ", pk:"
136: + mEntityContext.getPrimaryKey() + ", local:"
137: + mEntityContext.getEJBLocalObject());
138: }
139:
140: public void ejbLoad() throws EJBException, RemoteException {
141: log.info("ejbLoad, ctx:" + mEntityContext + ", pk:"
142: + mEntityContext.getPrimaryKey() + ", local:"
143: + mEntityContext.getEJBLocalObject());
144: }
145:
146: public void ejbPassivate() throws EJBException, RemoteException {
147: log.info("ejbPassivate, ctx:" + mEntityContext + ", pk:"
148: + mEntityContext.getPrimaryKey() + ", local:"
149: + mEntityContext.getEJBLocalObject());
150: }
151:
152: public void ejbRemove() throws RemoveException, EJBException,
153: RemoteException {
154: }
155:
156: public void ejbStore() throws EJBException, RemoteException {
157: }
158:
159: public void setEntityContext(EntityContext ctx)
160: throws EJBException, RemoteException {
161: mEntityContext = ctx;
162: }
163:
164: public void unsetEntityContext() throws EJBException,
165: RemoteException {
166: mEntityContext = null;
167: }
168:
169: }
|