KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > ebasic > PersonEC2


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: PersonEC2.java,v 1.4 2004/07/06 10:04:09 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 /**
27  * This is an entity bean with "container managed persistence version 2.x".
28  * This bean is used to test an entity with an unknown primary key class at the development phase.
29  * @author Helene Joanin
30  */

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

47 public abstract class PersonEC2 implements EntityBean JavaDoc {
48
49     static protected Logger logger = null;
50     EntityContext JavaDoc ejbContext;
51
52     // ------------------------------------------------------------------
53
// Get and Set accessor methods of the bean's abstract schema
54
// ------------------------------------------------------------------
55
public abstract Integer JavaDoc getNumber();
56     public abstract void setNumber(Integer JavaDoc num);
57
58     public abstract String JavaDoc getName();
59     public abstract void setName(String JavaDoc name);
60
61     // ------------------------------------------------------------------
62
// EntityBean implementation
63
// ------------------------------------------------------------------
64

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

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

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

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

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

136     public void ejbStore() {
137         logger.log(BasicLevel.DEBUG, "");
138     }
139     
140     /**
141      * The Entity bean can define 0 or more ejbCreate methods.
142      *
143      * @throws CreateException Failure to create an entity EJB object.
144      * @throws DuplicateKeyException An object with the same key already exists.
145      */

146     public java.lang.Object JavaDoc ejbCreate(int i, String JavaDoc s) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
147         logger.log(BasicLevel.DEBUG, "");
148
149         // Init here the bean fields
150
setNumber(new Integer JavaDoc(i));
151         setName(new String JavaDoc(s));
152
153         // In CMP, should return null.
154
return null;
155     }
156     
157     /**
158      * There must be an ejbPostCreate par ejbCreate method
159      *
160      * @throws CreateException Failure to create an entity EJB object.
161      */

162     public void ejbPostCreate(int i, String JavaDoc s) throws CreateException JavaDoc {
163         logger.log(BasicLevel.DEBUG, "");
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
// Person implementation
185
// ------------------------------------------------------------------
186

187     /**
188      * getNumberPrimitive
189      */

190     public int getNumberPrimitive() {
191         logger.log(BasicLevel.DEBUG, "");
192         return getNumber().intValue();
193     }
194
195 }
196
Popular Tags