KickJava   Java API By Example, From Geeks To Geeks.

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


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: P2EC2.java,v 1.3 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 P2EC2 implements javax.ejb.EntityBean JavaDoc {
47
48     private P1HomeLocal p1home = null;
49
50     // ------------------------------------------------------------------
51
// Get and Set accessor methods of the bean's abstract schema
52
// ------------------------------------------------------------------
53
public abstract String JavaDoc getId();
54     public abstract void setId(String JavaDoc id);
55
56     public abstract P1Local getP1();
57     public abstract void setP1(P1Local p1);
58
59     // ------------------------------------------------------------------
60
// EntityBean implementation
61
// ------------------------------------------------------------------
62

63     static protected Logger logger = null;
64     EntityContext JavaDoc ejbContext;
65
66     /**
67      * The Entity bean can define 0 or more ejbCreate methods.
68      *
69      * @throws CreateException Failure to create an entity EJB object.
70      * @throws DuplicateKeyException An object with the same key already exists.
71      */

72     public String JavaDoc ejbCreate(String JavaDoc id) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
73         logger.log(BasicLevel.DEBUG, "");
74
75         // Init here the bean fields
76
setId(id);
77
78         // In CMP, should return null.
79
return null;
80     }
81
82     /**
83      * There must be an ejbPostCreate par ejbCreate method
84      * @throws CreateException Failure to create an entity EJB object.
85      */

86     public void ejbPostCreate(String JavaDoc id) throws CreateException JavaDoc {
87         logger.log(BasicLevel.DEBUG, "id=" + id);
88         try {
89             P1Local p1l = p1home.findByPrimaryKey(id);
90             setP1(p1l);
91         } catch (FinderException JavaDoc e) {
92             throw new CreateException JavaDoc("P2 cannot exist without matching P1");
93         }
94     }
95
96     /**
97      * Set the associated entity context. The container invokes this method
98      * on an instance after the instance has been created.
99      * This method is called in an unspecified transaction context.
100      *
101      * @param ctx - An EntityContext interface for the instance. The instance
102      * should store the reference to the context in an instance variable.
103      * @throws EJBException Thrown by the method to indicate a failure caused by a
104      * system-level error.
105      */

106     public void setEntityContext(EntityContext JavaDoc ctx) {
107         if (logger == null)
108             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
109         logger.log(BasicLevel.DEBUG, "");
110         ejbContext = ctx;
111         try {
112             Context JavaDoc ictx = new InitialContext JavaDoc();
113             p1home = (P1HomeLocal) ictx.lookup("java:comp/env/ejb/p1");
114         } catch (NamingException JavaDoc e) {
115             throw new EJBException JavaDoc("Impossible to get HomeLocal:", e);
116         }
117     }
118
119     /**
120      * Unset the associated entity context. The container calls this method
121      * before removing the instance.
122      * This is the last method that the container invokes on the instance.
123      * The Java garbage collector will eventually invoke the finalize() method
124      * on the instance.
125      * This method is called in an unspecified transaction context.
126      *
127      * @throws EJBException Thrown by the method to indicate a failure caused by a
128      * system-level error.
129      */

130     public void unsetEntityContext() {
131         logger.log(BasicLevel.DEBUG, "");
132         ejbContext = null;
133     }
134
135     /**
136      * A container invokes this method before it removes the EJB object
137      * that is currently associated with the instance. This method is
138      * invoked when a client invokes a remove operation on the enterprise Bean's
139      * home interface or the EJB object's remote interface. This method
140      * transitions the instance from the ready state to the pool of available
141      * instances.
142      *
143      * This method is called in the transaction context of the remove operation.
144      * @throws RemoveException The enterprise Bean does not allow destruction of the object.
145      * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
146      * error.
147      */

148     public void ejbRemove() throws RemoveException JavaDoc {
149         logger.log(BasicLevel.DEBUG, "");
150     }
151
152     /**
153      * A container invokes this method to instruct the instance to synchronize
154      * its state by loading it state from the underlying database.
155      * This method always executes in the proper transaction context.
156      *
157      * @throws EJBException Thrown by the method to indicate a failure caused by
158      * a system-level error.
159      */

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

172     public void ejbStore() {
173         logger.log(BasicLevel.DEBUG, "");
174     }
175
176     /**
177      * A container invokes this method on an instance before the instance
178      * becomes disassociated with a specific EJB object.
179      */

180     public void ejbPassivate() {
181         logger.log(BasicLevel.DEBUG, "");
182     }
183
184     /**
185      * A container invokes this method when the instance is taken out of
186      * the pool of available instances to become associated with a specific
187      * EJB object.
188      */

189     public void ejbActivate() {
190         logger.log(BasicLevel.DEBUG, "");
191     }
192
193     // ---------------------------------------------------------------------
194
// P1Remote Implementation
195
// ---------------------------------------------------------------------
196

197     /**
198      *
199      */

200     public String JavaDoc getP1Value() {
201         P1Local p1l = getP1();
202         return p1l.getPf1();
203     }
204 }
205
Popular Tags