KickJava   Java API By Example, From Geeks To Geeks.

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


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: P3EC2.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 P3EC2 implements javax.ejb.EntityBean JavaDoc {
47
48     private P1HomeLocal p1home = null;
49     private P4HomeLocal p4home = null;
50
51     // ------------------------------------------------------------------
52
// Get and Set accessor methods of the bean's abstract schema
53
// ------------------------------------------------------------------
54
public abstract String JavaDoc getId3();
55     public abstract void setId3(String JavaDoc id3);
56
57     public abstract String JavaDoc getId();
58     public abstract void setId(String JavaDoc id);
59
60     public abstract P1Local getP1();
61     public abstract void setP1(P1Local p1);
62     public abstract P4Local getP4();
63     public abstract void setP4(P4Local p4);
64
65     // ------------------------------------------------------------------
66
// EntityBean implementation
67
// ------------------------------------------------------------------
68

69     static protected Logger logger = null;
70     EntityContext JavaDoc ejbContext;
71
72     /**
73      * The Entity bean can define 0 or more ejbCreate methods.
74      *
75      * @throws CreateException Failure to create an entity EJB object.
76      * @throws DuplicateKeyException An object with the same key already exists.
77      */

78     public String JavaDoc ejbCreate(String JavaDoc id3, String JavaDoc id) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
79         logger.log(BasicLevel.DEBUG, "");
80
81         // Init here the bean fields
82
setId3(id3);
83         setId(id);
84
85         // In CMP, should return null.
86
return null;
87     }
88
89     /**
90      * There must be an ejbPostCreate par ejbCreate method
91      * @throws CreateException Failure to create an entity EJB object.
92      */

93     public void ejbPostCreate(String JavaDoc id3, String JavaDoc id) throws CreateException JavaDoc {
94         logger.log(BasicLevel.DEBUG, "id3=" + id3 + " id=" + id);
95         try {
96             P1Local p1l = p1home.findByPrimaryKey(id);
97             setP1(p1l);
98         } catch (FinderException JavaDoc e) {
99             throw new CreateException JavaDoc("P3 cannot exist without matching P1");
100         }
101         try {
102             P4PK pk4 = new P4PK(id);
103             P4Local p4l = p4home.findByPrimaryKey(pk4);
104             setP4(p4l);
105         } catch (FinderException JavaDoc e) {
106             throw new CreateException JavaDoc("P3 cannot exist without matching P4");
107         }
108     }
109
110     /**
111      * Set the associated entity context. The container invokes this method
112      * on an instance after the instance has been created.
113      * This method is called in an unspecified transaction context.
114      *
115      * @param ctx - An EntityContext interface for the instance. The instance
116      * should store the reference to the context in an instance variable.
117      * @throws EJBException Thrown by the method to indicate a failure caused by a
118      * system-level error.
119      */

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

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

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

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

187     public void ejbStore() {
188         logger.log(BasicLevel.DEBUG, "");
189     }
190
191     /**
192      * A container invokes this method on an instance before the instance
193      * becomes disassociated with a specific EJB object.
194      */

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

204     public void ejbActivate() {
205         logger.log(BasicLevel.DEBUG, "");
206     }
207
208     // ---------------------------------------------------------------------
209
// P3Remote Implementation
210
// ---------------------------------------------------------------------
211

212     /**
213      *
214      */

215     public String JavaDoc getP1Value() {
216         P1Local p1l = getP1();
217         return p1l.getPf1();
218     }
219
220     public String JavaDoc getP4Value() {
221         P4Local p4l = getP4();
222         return p4l.getPf4();
223     }
224 }
225
Popular Tags