KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > relation > mou > 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.7 2004/12/17 15:08:35 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.relation.mou;
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 S.Chassande-Barrioz
45  */

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

97     static protected Logger logger = null;
98     EntityContext JavaDoc ejbContext;
99
100     /**
101      * The Entity bean can define 0 or more ejbCreate methods.
102      *
103      * @throws CreateException Failure to create an entity EJB object.
104      * @throws DuplicateKeyException An object with the same key already exists.
105      */

106     public String JavaDoc ejbCreate(String JavaDoc id, String JavaDoc idb) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
107         logger.log(BasicLevel.DEBUG, "");
108
109         // Init here the bean fields
110
setId(id);
111
112         // In CMP, should return null.
113
return null;
114     }
115
116     /**
117      * There must be an ejbPostCreate par ejbCreate method
118      *
119      * @throws CreateException Failure to create an entity EJB object.
120      */

121     public void ejbPostCreate(String JavaDoc id, String JavaDoc idb) throws CreateException JavaDoc {
122         logger.log(BasicLevel.DEBUG, "id=" + id);
123         try {
124             assignB(idb);
125         } catch (FinderException JavaDoc e) {
126             throw new CreateException JavaDoc("Bad arg: " + idb);
127         }
128     }
129
130     /**
131      * The Entity bean can define 0 or more ejbCreate methods.
132      *
133      * @throws CreateException Failure to create an entity EJB object.
134      * @throws DuplicateKeyException An object with the same key already exists.
135      */

136     public String JavaDoc ejbCreate(String JavaDoc id) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
137         logger.log(BasicLevel.DEBUG, "");
138
139         // Init here the bean fields
140
setId(id);
141
142         // In CMP, should return null.
143
return null;
144     }
145
146     /**
147      * There must be an ejbPostCreate par ejbCreate method
148      *
149      * @throws CreateException Failure to create an entity EJB object.
150      */

151     public void ejbPostCreate(String JavaDoc id) throws CreateException JavaDoc {
152         logger.log(BasicLevel.DEBUG, "id=" + id);
153     }
154
155     /**
156      * The Entity bean can define 0 or more ejbCreate methods.
157      *
158      * @throws CreateException Failure to create an entity EJB object.
159      * @throws DuplicateKeyException An object with the same key already exists.
160      */

161     public String JavaDoc ejbCreate(String JavaDoc id, BLocal b) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
162         logger.log(BasicLevel.DEBUG, "");
163
164         // Init here the bean fields
165
setId(id);
166
167         // In CMP, should return null.
168
return null;
169     }
170
171     /**
172      * There must be an ejbPostCreate par ejbCreate method
173      *
174      * @throws CreateException Failure to create an entity EJB object.
175      */

176     public void ejbPostCreate(String JavaDoc id, BLocal b) throws CreateException JavaDoc {
177         logger.log(BasicLevel.DEBUG, "id=" + id);
178         setB(b);
179     }
180
181     /**
182      * Set the associated entity context. The container invokes this method
183      * on an instance after the instance has been created.
184      * This method is called in an unspecified transaction context.
185      *
186      * @param ctx - An EntityContext interface for the instance. The instance
187      * should store the reference to the context in an instance variable.
188      * @throws EJBException Thrown by the method to indicate a failure caused by a
189      * system-level error.
190      */

191     public void setEntityContext(EntityContext JavaDoc ctx) {
192         if (logger == null)
193             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
194         logger.log(BasicLevel.DEBUG, "");
195         ejbContext = ctx;
196         try {
197             Context JavaDoc ictx = new InitialContext JavaDoc();
198             bhl = (BHomeLocal) ictx.lookup("java:comp/env/ejb/b");
199         } catch (NamingException JavaDoc e) {
200             throw new EJBException JavaDoc("Impossible to fetch the ", e);
201         }
202     }
203
204     /**
205      * Unset the associated entity context. The container calls this method
206      * before removing the instance.
207      * This is the last method that the container invokes on the instance.
208      * The Java garbage collector will eventually invoke the finalize() method
209      * on the instance.
210      * This method is called in an unspecified transaction context.
211      *
212      * @throws EJBException Thrown by the method to indicate a failure caused by a
213      * system-level error.
214      */

215     public void unsetEntityContext() {
216         logger.log(BasicLevel.DEBUG, "");
217         ejbContext = null;
218     }
219
220     /**
221      * A container invokes this method before it removes the EJB object
222      * that is currently associated with the instance. This method is
223      * invoked when a client invokes a remove operation on the enterprise Bean's
224      * home interface or the EJB object's remote interface. This method
225      * transitions the instance from the ready state to the pool of available
226      * instances.
227      *
228      * This method is called in the transaction context of the remove operation.
229      * @throws RemoveException The enterprise Bean does not allow destruction of the object.
230      * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
231      * error.
232      */

233     public void ejbRemove() throws RemoveException JavaDoc {
234         logger.log(BasicLevel.DEBUG, "");
235     }
236
237     /**
238      * A container invokes this method to instruct the instance to synchronize
239      * its state by loading it state from the underlying database.
240      * This method always executes in the proper transaction context.
241      *
242      * @throws EJBException Thrown by the method to indicate a failure caused by
243      * a system-level error.
244      */

245     public void ejbLoad() {
246         logger.log(BasicLevel.DEBUG, "");
247     }
248
249     /**
250      * A container invokes this method to instruct the instance to synchronize
251      * its state by storing it to the underlying database.
252      * This method always executes in the proper transaction context.
253      *
254      * @throws EJBException Thrown by the method to indicate a failure caused by
255      * a system-level error.
256      */

257     public void ejbStore() {
258         logger.log(BasicLevel.DEBUG, "");
259     }
260
261     /**
262      * A container invokes this method on an instance before the instance
263      * becomes disassociated with a specific EJB object.
264      */

265     public void ejbPassivate() {
266         logger.log(BasicLevel.DEBUG, "");
267     }
268
269     /**
270      * A container invokes this method when the instance is taken out of
271      * the pool of available instances to become associated with a specific
272      * EJB object.
273      */

274     public void ejbActivate() {
275         logger.log(BasicLevel.DEBUG, "");
276     }
277
278 }
279
Popular Tags