KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > relation > oou > 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.oou;
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     public void assignBInNewTx(String JavaDoc c) throws FinderException JavaDoc {
62         assignB(c);
63     }
64
65     public String JavaDoc retrieveB() {
66       BLocal lejbB = getB();
67       if (lejbB==null)
68       return null;
69       else
70           return lejbB.getId();
71     }
72
73     public String JavaDoc retrieveBInNewTx() {
74         return retrieveB();
75     }
76
77     // ------------------------------------------------------------------
78
// Get and Set accessor methods of the bean's abstract schema
79
// ------------------------------------------------------------------
80
public abstract String JavaDoc getId();
81
82     public abstract void setId(String JavaDoc id);
83
84     public abstract BLocal getB();
85
86     public abstract void setB(BLocal bl);
87
88
89     // ------------------------------------------------------------------
90
// EntityBean implementation
91
// ------------------------------------------------------------------
92

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

102     public String JavaDoc ejbCreate(String JavaDoc id) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
103         logger.log(BasicLevel.DEBUG, "");
104
105         // Init here the bean fields
106
setId(id);
107
108         // In CMP, should return null.
109
return null;
110     }
111
112     /**
113      * Set the associated entity context. The container invokes this method
114      * on an instance after the instance has been created.
115      * This method is called in an unspecified transaction context.
116      *
117      * @param ctx - An EntityContext interface for the instance. The instance
118      * should store the reference to the context in an instance variable.
119      * @throws EJBException Thrown by the method to indicate a failure caused by a
120      * system-level error.
121      */

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

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

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

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

188     public void ejbStore() {
189         logger.log(BasicLevel.DEBUG, "");
190     }
191
192     /**
193      * There must be an ejbPostCreate par ejbCreate method
194      *
195      * @throws CreateException Failure to create an entity EJB object.
196      */

197     public void ejbPostCreate(String JavaDoc id) throws CreateException JavaDoc {
198         logger.log(BasicLevel.DEBUG, "id=" + id);
199     }
200
201     /**
202      * A container invokes this method on an instance before the instance
203      * becomes disassociated with a specific EJB object.
204      */

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

214     public void ejbActivate() {
215         logger.log(BasicLevel.DEBUG, "");
216     }
217
218 }
219
Popular Tags