KickJava   Java API By Example, From Geeks To Geeks.

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

25
26 package org.objectweb.jonas.jtests.beans.relation.s2pkcomp;
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 Helene Joanin
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 Pk getId(){
54     return (Pk)ejbContext.getPrimaryKey();
55     }
56
57     public void assignB(Pk c) throws FinderException JavaDoc {
58         logger.log(BasicLevel.DEBUG, "param=" + c.toString());
59         if (c != null) {
60             BLocal bl = null;
61             bl = bhl.findByPrimaryKey(c);
62             setB(bl);
63         } else {
64             setB(null);
65     }
66     }
67     public void assignBInNewTx(Pk c) throws FinderException JavaDoc {
68         assignB(c);
69     }
70
71     public Pk retrieveB() {
72         BLocal lejbB = getB();
73         if (lejbB == null) {
74             logger.log(BasicLevel.DEBUG, "return null");
75             return null;
76         } else {
77             logger.log(BasicLevel.DEBUG, "return " + lejbB.getId());
78             return lejbB.getId();
79         }
80     }
81
82     public Pk retrieveBInNewTx() {
83         return retrieveB();
84     }
85
86     // ------------------------------------------------------------------
87
// Get and Set accessor methods of the bean's abstract schema
88
// ------------------------------------------------------------------
89
public abstract String JavaDoc getId1();
90     public abstract void setId1(String JavaDoc id1);
91     public abstract int getId2();
92     public abstract void setId2(int id2);
93     public abstract BLocal getB();
94     public abstract void setB(BLocal bl);
95
96     // ------------------------------------------------------------------
97
// EntityBean implementation
98
// ------------------------------------------------------------------
99

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

109     public Pk ejbCreate(String JavaDoc id1, int id2) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
110         logger.log(BasicLevel.DEBUG, "");
111
112         // Init here the bean fields
113
setId1(id1);
114         setId2(id2);
115
116         // In CMP, should return null.
117
return null;
118     }
119
120     /**
121      * Set the associated entity context. The container invokes this method
122      * on an instance after the instance has been created.
123      * This method is called in an unspecified transaction context.
124      *
125      * @param ctx - An EntityContext interface for the instance. The instance
126      * should store the reference to the context in an instance variable.
127      * @throws EJBException Thrown by the method to indicate a failure caused by a
128      * system-level error.
129      */

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

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

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

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

196     public void ejbStore() {
197         logger.log(BasicLevel.DEBUG, "");
198     }
199
200     /**
201      * There must be an ejbPostCreate par ejbCreate method
202      *
203      * @throws CreateException Failure to create an entity EJB object.
204      */

205     public void ejbPostCreate(String JavaDoc id1, int id2) throws CreateException JavaDoc {
206         logger.log(BasicLevel.DEBUG, "id1="+id1+", id2="+id2);
207     }
208
209     /**
210      * A container invokes this method on an instance before the instance
211      * becomes disassociated with a specific EJB object.
212      */

213     public void ejbPassivate() {
214         logger.log(BasicLevel.DEBUG, "");
215     }
216
217     /**
218      * A container invokes this method when the instance is taken out of
219      * the pool of available instances to become associated with a specific
220      * EJB object.
221      */

222     public void ejbActivate() {
223         logger.log(BasicLevel.DEBUG, "");
224     }
225
226 }
227
Popular Tags