KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > passivation > ejb > RapidlyPassivatedEntityBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cmp2.passivation.ejb;
23
24 import java.rmi.RemoteException JavaDoc;
25
26 import javax.ejb.CreateException JavaDoc;
27 import javax.ejb.EJBException JavaDoc;
28 import javax.ejb.EntityBean JavaDoc;
29 import javax.ejb.EntityContext JavaDoc;
30 import javax.ejb.RemoveException JavaDoc;
31 import javax.ejb.EJBObject JavaDoc;
32 import javax.ejb.EJBLocalObject JavaDoc;
33
34 import org.jboss.logging.Logger;
35
36 /**
37  * An entity bean to test the entity activation/passivation mechanism
38  * provided by JBoss.
39  *
40  * It is associated with a container configuration which causes it to be passivated shortly
41  * after it has been accessed.
42  *
43  * It has been designed to expose the bug described at
44  * <a HREF="https://sourceforge.net/tracker/?group_id=22866&atid=376685&func=detail&aid=742197">
45  * Detail:769139 entityCtx.getEJBLocalObject() returns wrong instance</a>
46  * and
47  * <a HREF="https://sourceforge.net/tracker/?func=detail&atid=376685&aid=769139&group_id=22866">
48  * Detail:742197 getEJBLocalObject() bug</a>
49  *
50  * @ejb.bean
51  * name="RapidlyPassivatedEntity"
52  * jndi-name="ejb/remote/RapidlyPassivatedEntity"
53  * local-jndi-name="ejb/local/RapidlyPassivatedEntity"
54  * view-type="both"
55  * type="CMP"
56  * reentrant="false"
57  * cmp-version="2.x"
58  * @ejb.pk
59  * class="java.lang.Object"
60  * @jboss.create-table "true"
61  * @jboss.remove-table "true"
62  * @jboss.unknown-pk
63  * class="java.lang.String"
64  * @jboss.entity-command
65  * name="key-generator"
66  * @jboss.container-configuration
67  * name="Short lived CMP 2.0 Entity Bean"
68  *
69  * @author <a HREF="mailto:steve@resolvesw.com">Steve Coy</a>
70  */

71 public abstract class RapidlyPassivatedEntityBean implements EntityBean JavaDoc
72 {
73    // Attributes ----------------------------------------------------
74

75    private static Logger log = Logger.getLogger(RapidlyPassivatedEntityBean.class);
76
77    private EntityContext JavaDoc mEntityContext;
78
79    
80    // Entity Attributes ----------------------------------------------------
81

82    /**
83     * @ejb.persistent-field
84     * @ejb.interface-method
85     */

86    public abstract String JavaDoc getData();
87    public abstract void setData(String JavaDoc data);
88    
89
90    // Business Methods ----------------------------------------------------
91

92    /**
93     * Return the pk of the object returned by {@link EntityContext#getEJBLocalObject}
94     * @ejb.interface-method
95     */

96    public Object JavaDoc getIdViaEJBLocalObject()
97    {
98       Object JavaDoc key = mEntityContext.getPrimaryKey();
99       EJBLocalObject JavaDoc local = mEntityContext.getEJBLocalObject();
100       Object JavaDoc lkey = local.getPrimaryKey();
101       log.info("key: "+key+", lkey: "+lkey+", local: "+local);
102       return (Object JavaDoc)mEntityContext.getEJBLocalObject().getPrimaryKey();
103    }
104   
105
106    /**
107     * Return the pk of the object returned by {@link EntityContext#getEJBObject}
108     * @ejb.interface-method
109     */

110    public Object JavaDoc getIdViaEJBObject()
111    {
112       try
113       {
114          return (Object JavaDoc)mEntityContext.getEJBObject().getPrimaryKey();
115       }
116       catch (RemoteException JavaDoc e)
117       {
118          throw new EJBException JavaDoc(e);
119       }
120    }
121   
122
123    // EJB Implementation ----------------------------------------------------
124

125    /**
126     * @ejb.create-method
127     */

128    public Object JavaDoc ejbCreate(String JavaDoc s)
129       throws CreateException JavaDoc
130    {
131       setData(s);
132       return null; // as required by CMP 2.0 spec
133
}
134    
135    public void ejbPostCreate(String JavaDoc s)
136    {
137       log.info("ejbPostCreate, ctx:"+mEntityContext
138          +", pk:"+mEntityContext.getPrimaryKey()
139          +", local:"+mEntityContext.getEJBLocalObject());
140    }
141    
142   
143    public void ejbActivate() throws EJBException JavaDoc, RemoteException JavaDoc
144    {
145       log.info("ejbActivate, ctx:"+mEntityContext
146          +", pk:"+mEntityContext.getPrimaryKey()
147          +", local:"+mEntityContext.getEJBLocalObject());
148    }
149
150    public void ejbLoad() throws EJBException JavaDoc, RemoteException JavaDoc
151    {
152       log.info("ejbLoad, ctx:"+mEntityContext
153          +", pk:"+mEntityContext.getPrimaryKey()
154          +", local:"+mEntityContext.getEJBLocalObject());
155    }
156
157    public void ejbPassivate() throws EJBException JavaDoc, RemoteException JavaDoc
158    {
159       log.info("ejbPassivate, ctx:"+mEntityContext
160          +", pk:"+mEntityContext.getPrimaryKey()
161          +", local:"+mEntityContext.getEJBLocalObject());
162    }
163
164    public void ejbRemove()
165       throws RemoveException JavaDoc, EJBException JavaDoc, RemoteException JavaDoc
166    {
167    }
168
169    public void ejbStore() throws EJBException JavaDoc, RemoteException JavaDoc
170    {
171    }
172
173    public void setEntityContext(EntityContext JavaDoc ctx)
174       throws EJBException JavaDoc, RemoteException JavaDoc
175    {
176       mEntityContext = ctx;
177    }
178
179    public void unsetEntityContext() throws EJBException JavaDoc, RemoteException JavaDoc
180    {
181       mEntityContext = null;
182    }
183
184 }
185
Popular Tags