KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > relation > dass > AEC2


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: AEC2.java,v 1.4 2004/12/17 15:08:35 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.relation.dass;
27
28 import javax.ejb.CreateException JavaDoc;
29 import javax.ejb.DuplicateKeyException JavaDoc;
30 import javax.ejb.EJBException JavaDoc;
31 import javax.ejb.EntityContext JavaDoc;
32 import javax.ejb.FinderException JavaDoc;
33 import javax.ejb.RemoveException JavaDoc;
34 import javax.naming.Context JavaDoc;
35 import javax.naming.InitialContext JavaDoc;
36 import javax.naming.NamingException JavaDoc;
37 import javax.rmi.PortableRemoteObject JavaDoc;
38
39 import org.objectweb.jonas.common.Log;
40 import org.objectweb.util.monolog.api.BasicLevel;
41 import org.objectweb.util.monolog.api.Logger;
42
43 /**
44  * @author Ph Durieux
45  */

46 public abstract class AEC2 implements javax.ejb.EntityBean JavaDoc {
47
48     private BHomeLocal bhl = null;
49
50
51     public void assignB(String JavaDoc c) throws FinderException JavaDoc {
52         logger.log(BasicLevel.DEBUG, "");
53         if (c != null) {
54             BLocal bl = null;
55             bl = bhl.findByPrimaryKey(c);
56             setB(bl);
57         } else
58             setB(null);
59     }
60
61     public String JavaDoc retrieveB() {
62         logger.log(BasicLevel.DEBUG, "");
63         BLocal lejbB = getB();
64         if (lejbB == null) {
65             return null;
66         } else {
67             return lejbB.getId();
68         }
69     }
70
71     // ------------------------------------------------------------------
72
// Get and Set accessor methods of the bean's abstract schema
73
// ------------------------------------------------------------------
74
public abstract String JavaDoc getId();
75     public abstract void setId(String JavaDoc id);
76
77     public abstract String JavaDoc getBcmrvalue();
78     public abstract void setBcmrvalue(String JavaDoc id);
79
80     public abstract BLocal getB();
81     public abstract void setB(BLocal bl);
82
83
84     // ------------------------------------------------------------------
85
// EntityBean implementation
86
// ------------------------------------------------------------------
87

88     static protected Logger logger = null;
89     EntityContext JavaDoc ejbContext;
90
91     /**
92      * The Entity bean can define 0 or more ejbCreate methods.
93      *
94      * @throws CreateException Failure to create an entity EJB object.
95      * @throws DuplicateKeyException An object with the same key already exists.
96      */

97     public String JavaDoc ejbCreate(String JavaDoc id) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
98         logger.log(BasicLevel.DEBUG, "");
99
100         // Init here the bean fields
101
setId(id);
102
103         // In CMP, should return null.
104
return null;
105     }
106
107     /**
108      * There must be an ejbPostCreate par ejbCreate method
109      *
110      * @throws CreateException Failure to create an entity EJB object.
111      */

112     public void ejbPostCreate(String JavaDoc id) throws CreateException JavaDoc {
113         logger.log(BasicLevel.DEBUG, "id=" + id);
114     }
115
116     /**
117      * Set the associated entity context. The container invokes this method
118      * on an instance after the instance has been created.
119      * This method is called in an unspecified transaction context.
120      *
121      * @param ctx - An EntityContext interface for the instance. The instance
122      * should store the reference to the context in an instance variable.
123      * @throws EJBException Thrown by the method to indicate a failure caused by a
124      * system-level error.
125      */

126     public void setEntityContext(EntityContext JavaDoc ctx) {
127         if (logger == null)
128             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
129         logger.log(BasicLevel.DEBUG, "");
130         ejbContext = ctx;
131         try {
132             Context JavaDoc ictx = new InitialContext JavaDoc();
133             bhl = (BHomeLocal) ictx.lookup("java:comp/env/ejb/b");
134         } catch (NamingException JavaDoc e) {
135             throw new EJBException JavaDoc("Impossible to fetch the ", e);
136         }
137     }
138
139     /**
140      * Unset the associated entity context. The container calls this method
141      * before removing the instance.
142      * This is the last method that the container invokes on the instance.
143      * The Java garbage collector will eventually invoke the finalize() method
144      * on the instance.
145      * This method is called in an unspecified transaction context.
146      *
147      * @throws EJBException Thrown by the method to indicate a failure caused by a
148      * system-level error.
149      */

150     public void unsetEntityContext() {
151         logger.log(BasicLevel.DEBUG, "");
152         ejbContext = null;
153     }
154
155     /**
156      * A container invokes this method before it removes the EJB object
157      * that is currently associated with the instance. This method is
158      * invoked when a client invokes a remove operation on the enterprise Bean's
159      * home interface or the EJB object's remote interface. This method
160      * transitions the instance from the ready state to the pool of available
161      * instances.
162      *
163      * This method is called in the transaction context of the remove operation.
164      * @throws RemoveException The enterprise Bean does not allow destruction of the object.
165      * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
166      * error.
167      */

168     public void ejbRemove() throws RemoveException JavaDoc {
169         logger.log(BasicLevel.DEBUG, "");
170     }
171
172     /**
173      * A container invokes this method to instruct the instance to synchronize
174      * its state by loading it state from the underlying database.
175      * This method always executes in the proper transaction context.
176      *
177      * @throws EJBException Thrown by the method to indicate a failure caused by
178      * a system-level error.
179      */

180     public void ejbLoad() {
181         logger.log(BasicLevel.DEBUG, "");
182     }
183
184     /**
185      * A container invokes this method to instruct the instance to synchronize
186      * its state by storing it to the underlying database.
187      * This method always executes in the proper transaction context.
188      *
189      * @throws EJBException Thrown by the method to indicate a failure caused by
190      * a system-level error.
191      */

192     public void ejbStore() {
193         logger.log(BasicLevel.DEBUG, "");
194     }
195
196     /**
197      * A container invokes this method on an instance before the instance
198      * becomes disassociated with a specific EJB object.
199      */

200     public void ejbPassivate() {
201         logger.log(BasicLevel.DEBUG, "");
202     }
203
204     /**
205      * A container invokes this method when the instance is taken out of
206      * the pool of available instances to become associated with a specific
207      * EJB object.
208      */

209     public void ejbActivate() {
210         logger.log(BasicLevel.DEBUG, "");
211     }
212
213 }
214
Popular Tags