KickJava   Java API By Example, From Geeks To Geeks.

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


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

25
26 package org.objectweb.jonas.jtests.beans.ebasic;
27
28 import javax.ejb.CreateException JavaDoc;
29 import javax.ejb.DuplicateKeyException JavaDoc;
30 import javax.ejb.EntityBean JavaDoc;
31 import javax.ejb.EntityContext JavaDoc;
32 import javax.ejb.RemoveException JavaDoc;
33
34 import org.objectweb.jonas.common.Log;
35 import org.objectweb.util.monolog.api.BasicLevel;
36 import org.objectweb.util.monolog.api.Logger;
37
38 /**
39  * This is an entity bean with "container managed persistence version 2.x".
40  * This bean is used to test an entity with a primary key that maps a java.lang.Integer
41  * single field.
42  * @author Helene Joanin
43  */

44 public abstract class AccountEC2 implements EntityBean JavaDoc {
45
46     static protected Logger logger = null;
47     EntityContext JavaDoc ejbContext;
48
49     // ------------------------------------------------------------------
50
// Get and Set accessor methods of the bean's abstract schema
51
// ------------------------------------------------------------------
52
public abstract Integer JavaDoc getNumber();
53     public abstract void setNumber(Integer JavaDoc numtest);
54
55     public abstract String JavaDoc getCustomer();
56     public abstract void setCustomer(String JavaDoc customer);
57
58     // ------------------------------------------------------------------
59
// EntityBean implementation
60
// ------------------------------------------------------------------
61

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

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

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

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

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

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

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

158     public void ejbPostCreate(int num, String JavaDoc s) throws CreateException JavaDoc {
159         logger.log(BasicLevel.DEBUG, "");
160     }
161
162     /**
163      * A container invokes this method on an instance before the instance
164      * becomes disassociated with a specific EJB object.
165      */

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

175     public void ejbActivate() {
176         logger.log(BasicLevel.DEBUG, "");
177     }
178     
179     // ------------------------------------------------------------------
180
// Account implementation
181
// ------------------------------------------------------------------
182

183     /**
184      * getNumberPrimitive()
185      */

186     public int getNumberPrimitive() {
187         logger.log(BasicLevel.DEBUG, "");
188         return getNumber().intValue();
189     }
190
191 }
192
Popular Tags