KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > message > MRecordEC


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: MRecordEC.java,v 1.5 2004/05/24 12:32:46 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 // MRecordEC.java
27

28 package org.objectweb.jonas.jtests.beans.message;
29
30 import java.rmi.RemoteException JavaDoc;
31 import javax.ejb.CreateException JavaDoc;
32 import javax.ejb.DuplicateKeyException JavaDoc;
33 import javax.ejb.EntityBean JavaDoc;
34 import javax.ejb.EntityContext JavaDoc;
35 import javax.ejb.RemoveException JavaDoc;
36
37
38 import org.objectweb.jonas.common.Log;
39 import org.objectweb.util.monolog.api.Logger;
40 import org.objectweb.util.monolog.api.BasicLevel;
41
42 /**
43  *
44  */

45 public class MRecordEC implements EntityBean JavaDoc {
46
47     protected static Logger logger = null;
48     EntityContext JavaDoc ejbContext;
49
50     // ------------------------------------------------------------------
51
// State of the bean.
52
// They must be public for Container Managed Persistance.
53
// ------------------------------------------------------------------
54
public String JavaDoc uuid;
55     public String JavaDoc dest;
56     public int value;
57     public int count;
58     public String JavaDoc mdb;
59
60     // ------------------------------------------------------------------
61
// EntityBean implementation
62
// ------------------------------------------------------------------
63

64     /**
65      * Set the associated entity context. The container invokes this method
66      * on an instance after the instance has been created.
67      * This method is called in an unspecified transaction context.
68      *
69      * @param ctx - An EntityContext interface for the instance. The instance
70      * should store the reference to the context in an instance variable.
71      * @throws EJBException Thrown by the method to indicate a failure caused by a
72      * system-level error.
73      */

74     public void setEntityContext(EntityContext JavaDoc ctx) {
75         if (logger == null) {
76             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
77         }
78         logger.log(BasicLevel.DEBUG, "");
79         ejbContext = ctx;
80     }
81
82     /**
83      * Unset the associated entity context. The container calls this method
84      * before removing the instance.
85      * This is the last method that the container invokes on the instance.
86      * The Java garbage collector will eventually invoke the finalize() method
87      * on the instance.
88      * This method is called in an unspecified transaction context.
89      *
90      * @throws EJBException Thrown by the method to indicate a failure caused by a
91      * system-level error.
92      */

93     public void unsetEntityContext() {
94         ejbContext = null;
95     }
96     
97     /**
98      * A container invokes this method before it removes the EJB object
99      * that is currently associated with the instance. This method is
100      * invoked when a client invokes a remove operation on the enterprise Bean's
101      * home interface or the EJB object's remote interface. This method
102      * transitions the instance from the ready state to the pool of available
103      * instances.
104      *
105      * This method is called in the transaction context of the remove operation.
106      * @throws RemoveException The enterprise Bean does not allow destruction of the object.
107      * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
108      * error.
109      */

110     public void ejbRemove() throws RemoveException JavaDoc {
111         logger.log(BasicLevel.DEBUG, "");
112     }
113
114     /**
115      * A container invokes this method to instruct the instance to synchronize
116      * its state by loading it state from the underlying database.
117      * This method always executes in the proper transaction context.
118      *
119      * @throws EJBException Thrown by the method to indicate a failure caused by
120      * a system-level error.
121      */

122     public void ejbLoad() {
123         logger.log(BasicLevel.DEBUG, "");
124     }
125
126     /**
127      * A container invokes this method to instruct the instance to synchronize
128      * its state by storing it to the underlying database.
129      * This method always executes in the proper transaction context.
130      *
131      * @throws EJBException Thrown by the method to indicate a failure caused by
132      * a system-level error.
133      */

134     public void ejbStore() {
135         logger.log(BasicLevel.DEBUG, "");
136     }
137
138     /**
139      * There must be an ejbPostCreate par ejbCreate method
140      *
141      * @throws CreateException Failure to create an entity EJB object.
142      */

143     public void ejbPostCreate(String JavaDoc uuid, String JavaDoc dest, int value, String JavaDoc mdb) throws CreateException JavaDoc {
144         logger.log(BasicLevel.DEBUG, "");
145     }
146
147     /**
148      * The Entity bean can define 0 or more ejbCreate methods.
149      *
150      * @throws CreateException Failure to create an entity EJB object.
151      * @throws DuplicateKeyException An object with the same key already exists.
152      */

153     public MRecordPK ejbCreate(String JavaDoc uuid, String JavaDoc dest, int value, String JavaDoc mdb) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
154         logger.log(BasicLevel.DEBUG, "");
155         // Init here the bean fields
156
this.uuid = uuid;
157         this.dest = dest;
158         this.value = value;
159         this.mdb = mdb;
160         this.count = 1;
161
162         // In CMP, should return null.
163
return null;
164     }
165
166     /**
167      * A container invokes this method on an instance before the instance
168      * becomes disassociated with a specific EJB object.
169      */

170     public void ejbPassivate() {
171         logger.log(BasicLevel.DEBUG, "");
172     }
173
174     /**
175      * A container invokes this method when the instance is taken out of
176      * the pool of available instances to become associated with a specific
177      * EJB object.
178      */

179     public void ejbActivate() {
180         logger.log(BasicLevel.DEBUG, "");
181     }
182     
183     // ------------------------------------------------------------------
184
// MRecord implementation
185
// ------------------------------------------------------------------
186

187     /**
188      * returns UUID
189      */

190     public String JavaDoc getUUID() throws RemoteException JavaDoc {
191         return uuid;
192     }
193
194     /**
195      * returns dest
196      */

197     public String JavaDoc getDest() throws RemoteException JavaDoc {
198         return dest;
199     }
200
201     /**
202      * returns value
203      */

204     public int getValue() throws RemoteException JavaDoc {
205         return value;
206     }
207
208     /**
209      * returns count
210      */

211     public int getCount() throws RemoteException JavaDoc {
212         return count;
213     }
214
215     /**
216      * Add 1 to the count
217      */

218     public void updateCount() throws RemoteException JavaDoc {
219         count++;
220     }
221
222     /**
223      * returns MDB
224      */

225     public String JavaDoc getMDB() throws RemoteException JavaDoc {
226         return mdb;
227     }
228
229 }
230
Popular Tags