KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > relation > omb > BEC2


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: BEC2.java,v 1.8 2005/04/15 14:41:10 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.relation.omb;
27
28 import org.objectweb.util.monolog.api.Logger;
29 import org.objectweb.util.monolog.api.BasicLevel;
30 import org.objectweb.jonas.common.Log;
31
32 import javax.ejb.EntityContext JavaDoc;
33 import javax.ejb.CreateException JavaDoc;
34 import javax.ejb.DuplicateKeyException JavaDoc;
35 import javax.ejb.EJBException JavaDoc;
36 import javax.ejb.FinderException JavaDoc;
37 import javax.ejb.RemoveException JavaDoc;
38
39 import javax.naming.Context JavaDoc;
40 import javax.naming.InitialContext JavaDoc;
41 import javax.naming.NamingException JavaDoc;
42 import javax.rmi.PortableRemoteObject JavaDoc;
43
44 /**
45  * @author S.Chassande-Barrioz, Helene Joanin
46  */

47 public abstract class BEC2 implements javax.ejb.EntityBean JavaDoc {
48
49     private AHomeLocal ahl = null;
50
51     public void m1() {
52     }
53
54     public void testSetCmrWithDeleted() throws EJBException JavaDoc {
55         logger.log(BasicLevel.DEBUG, "");
56         ALocal ax9;
57         try {
58             ax9 = ahl.create("ax9");
59             ax9.remove();
60         } catch (Exception JavaDoc e) {
61             throw new EJBException JavaDoc("Initial state creation problem: " + e);
62         }
63         try {
64             this.setA(ax9);
65             throw new EJBException JavaDoc("entity was not deleted, expected IllegalArgumentException");
66         } catch (IllegalArgumentException JavaDoc e) {
67             // Pass
68
} catch (Exception JavaDoc e) {
69             throw new EJBException JavaDoc("Caugth unexpected exception: " + e);
70         }
71     }
72
73     public void assignA(String JavaDoc pkA) throws FinderException JavaDoc {
74         logger.log(BasicLevel.DEBUG, "param=" + pkA);
75         ALocal a = null;
76         if (pkA != null) {
77             a = ahl.findByPrimaryKey(pkA);
78         }
79         logger.log(BasicLevel.DEBUG, "assign:" + a);
80         setA(a);
81     }
82
83     public void assignAInNewTx(String JavaDoc pkA) throws FinderException JavaDoc {
84         assignA(pkA);
85     }
86
87     public String JavaDoc retrieveA() {
88         if (getA() == null) {
89             logger.log(BasicLevel.DEBUG, "return null");
90             return null;
91         }
92         logger.log(BasicLevel.DEBUG, "return : " + getA().getPrimaryKey());
93         return (String JavaDoc) (getA().getPrimaryKey());
94     }
95
96     public String JavaDoc retrieveAInNewTx() {
97         return retrieveA();
98     }
99
100     public boolean equalsRelA(String JavaDoc pka) throws FinderException JavaDoc {
101         return (pka == retrieveA());
102     }
103
104     // ------------------------------------------------------------------
105
// Get and Set accessor methods of the bean's abstract schema
106
// ------------------------------------------------------------------
107
public abstract String JavaDoc getId();
108     public abstract void setId(String JavaDoc id);
109
110     // This cmp field with an utility class type Product
111
// to test that this Product class can be resolved in the JORM adapter
112
public abstract Product getProduct();
113     public abstract void setProduct(Product p);
114
115
116     public abstract ALocal getA();
117     public abstract void setA(ALocal a);
118
119     // ------------------------------------------------------------------
120
// EntityBean implementation
121
// ------------------------------------------------------------------
122

123     static protected Logger logger = null;
124
125     EntityContext JavaDoc ejbContext;
126
127     /**
128      * The Entity bean can define 0 or more ejbCreate methods.
129      * @throws CreateException Failure to create an entity EJB object.
130      * @throws DuplicateKeyException An object with the same key already exists.
131      */

132     public String JavaDoc ejbCreate(String JavaDoc id) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
133         logger.log(BasicLevel.DEBUG, "");
134
135         // Init here the bean fields
136
setId(id);
137         setProduct(new Product());
138
139         // In CMP, should return null.
140
return null;
141     }
142
143     /**
144      * Set the associated entity context. The container invokes this method on
145      * an instance after the instance has been created. This method is called in
146      * an unspecified transaction context.
147      * @param ctx - An EntityContext interface for the instance. The instance
148      * should store the reference to the context in an instance variable.
149      * @throws EJBException Thrown by the method to indicate a failure caused by
150      * a system-level error.
151      */

152     public void setEntityContext(EntityContext JavaDoc ctx) {
153         if (logger == null) logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
154         logger.log(BasicLevel.DEBUG, "");
155         ejbContext = ctx;
156         try {
157             Context JavaDoc ictx = new InitialContext JavaDoc();
158             ahl = (AHomeLocal) ictx.lookup("java:comp/env/ejb/a");
159         } catch (NamingException JavaDoc e) {
160             throw new EJBException JavaDoc("Impossible to fetch the ", e);
161         }
162     }
163
164     /**
165      * Unset the associated entity context. The container calls this method
166      * before removing the instance. This is the last method that the container
167      * invokes on the instance. The Java garbage collector will eventually
168      * invoke the finalize() method on the instance. This method is called in an
169      * unspecified transaction context.
170      * @throws EJBException Thrown by the method to indicate a failure caused by
171      * a system-level error.
172      */

173     public void unsetEntityContext() {
174         logger.log(BasicLevel.DEBUG, "");
175         ejbContext = null;
176     }
177
178     /**
179      * A container invokes this method before it removes the EJB object that is
180      * currently associated with the instance. This method is invoked when a
181      * client invokes a remove operation on the enterprise Bean's home interface
182      * or the EJB object's remote interface. This method transitions the
183      * instance from the ready state to the pool of available instances. This
184      * method is called in the transaction context of the remove operation.
185      * @throws RemoveException The enterprise Bean does not allow destruction of
186      * the object.
187      * @throws EJBException - Thrown by the method to indicate a failure caused
188      * by a system-level error.
189      */

190     public void ejbRemove() throws RemoveException JavaDoc {
191         logger.log(BasicLevel.DEBUG, "");
192     }
193
194     /**
195      * A container invokes this method to instruct the instance to synchronize
196      * its state by loading it state from the underlying database. This method
197      * always executes in the proper transaction context.
198      * @throws EJBException Thrown by the method to indicate a failure caused by
199      * a system-level error.
200      */

201     public void ejbLoad() {
202         logger.log(BasicLevel.DEBUG, "");
203     }
204
205     /**
206      * A container invokes this method to instruct the instance to synchronize
207      * its state by storing it to the underlying database. This method always
208      * executes in the proper transaction context.
209      * @throws EJBException Thrown by the method to indicate a failure caused by
210      * a system-level error.
211      */

212     public void ejbStore() {
213         logger.log(BasicLevel.DEBUG, "");
214     }
215
216     /**
217      * There must be an ejbPostCreate par ejbCreate method
218      * @throws CreateException Failure to create an entity EJB object.
219      */

220     public void ejbPostCreate(String JavaDoc id) throws CreateException JavaDoc {
221         logger.log(BasicLevel.DEBUG, "id=" + id);
222         setA(null);
223     }
224
225     /**
226      * A container invokes this method on an instance before the instance
227      * becomes disassociated with a specific EJB object.
228      */

229     public void ejbPassivate() {
230         logger.log(BasicLevel.DEBUG, "");
231     }
232
233     /**
234      * A container invokes this method when the instance is taken out of the
235      * pool of available instances to become associated with a specific EJB
236      * object.
237      */

238     public void ejbActivate() {
239         logger.log(BasicLevel.DEBUG, "");
240     }
241
242 }
243
244
Popular Tags