KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > eb > AccountImpl2Bean


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 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: AccountImpl2Bean.java,v 1.3 2004/04/19 06:39:29 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package eb;
27
28 /**
29  * Accountbean is an entity bean with "container managed persistence version 2".
30  * The state of an instance is stored into a relational database. The following
31  * table should exist: create table ACCOUNT (ACCNO integer primary key, CUSTOMER
32  * varchar(30), BALANCE number(15,4));
33  * @author Christophe Ney cney@batisseurs.com
34  */

35
36
37 import javax.ejb.CreateException;
38 import javax.ejb.EntityBean;
39 import javax.ejb.EntityContext;
40 import javax.ejb.RemoveException;
41
42 public abstract class AccountImpl2Bean implements EntityBean {
43
44     // Keep the reference on the EntityContext
45
protected EntityContext entityContext;
46
47     /* ========================= ejbCreate methods ============================ */
48
49     /**
50      * There must be one ejbCreate() method per create() method on the Home
51      * interface, and with the same signature.
52      * @param accno account number
53      * @param customer customer name
54      * @param balance initial balance
55      * @return pk primary key set to null
56      */

57     public Integer ejbCreate(int val_accno, String val_customer, double val_balance) throws CreateException {
58
59         // Init object state
60
setAccno(val_accno);
61         setCustomer(val_customer);
62         setBalance(val_balance);
63         return null;
64     }
65
66     /**
67      * Each ejbCreate method should have a matching ejbPostCreate method
68      */

69     public void ejbPostCreate(int val_accno, String val_customer, double val_balance) {
70         // Nothing to be done for this simple example.
71
}
72
73     /*
74      * ====================== javax.ejb.EntityBean implementation
75      * =================
76      */

77
78     /**
79      * A container invokes this method when the instance is taken out of the
80      * pool of available instances to become associated with a specific EJB
81      * object. This method transitions the instance to the ready state. This
82      * method executes in an unspecified transaction context.
83      * @exception EJBException Thrown by the method to indicate a failure caused
84      * by a system-level error.
85      */

86     public void ejbActivate() {
87         // Nothing to be done for this simple example.
88
}
89
90     /**
91      * A container invokes this method to instruct the instance to synchronize
92      * its state by loading it state from the underlying database. This method
93      * always executes in the proper transaction context.
94      * @exception EJBException Thrown by the method to indicate a failure caused
95      * by a system-level error.
96      * @exception RemoteException - This exception is defined in the method
97      * signature to provide backward compatibility for enterprise
98      * beans written for the EJB 1.0 specification. Enterprise beans
99      * written for the EJB 1.1 and higher specification should throw
100      * the javax.ejb.EJBException instead of this exception.
101      */

102     public void ejbLoad() {
103         // Nothing to be done for this simple example, in implicit persistance.
104
}
105
106     /**
107      * A container invokes this method on an instance before the instance
108      * becomes disassociated with a specific EJB object. After this method
109      * completes, the container will place the instance into the pool of
110      * available instances. This method executes in an unspecified transaction
111      * context.
112      * @exception EJBException Thrown by the method to indicate a failure caused
113      * by a system-level error.
114      */

115     public void ejbPassivate() {
116         // Nothing to be done for this simple example.
117
}
118
119     /**
120      * A container invokes this method before it removes the EJB object that is
121      * currently associated with the instance. This method is invoked when a
122      * client invokes a remove operation on the enterprise Bean's home interface
123      * or the EJB object's remote interface. This method transitions the
124      * instance from the ready state to the pool of available instances. This
125      * method is called in the transaction context of the remove operation.
126      * @exception EJBException Thrown by the method to indicate a failure caused
127      * by a system-level error.
128      * @exception RemoteException - This exception is defined in the method
129      * signature to provide backward compatibility for enterprise
130      * beans written for the EJB 1.0 specification. Enterprise beans
131      * written for the EJB 1.1 and higher specification should throw
132      * the javax.ejb.EJBException instead of this exception.
133      * @exception RemoveException The enterprise Bean does not allow destruction
134      * of the object.
135      */

136     public void ejbRemove() throws RemoveException {
137         // Nothing to be done for this simple example, in implicit persistance.
138
}
139
140     /**
141      * A container invokes this method to instruct the instance to synchronize
142      * its state by storing it to the underlying database. This method always
143      * executes in the proper transaction context.
144      * @exception EJBException Thrown by the method to indicate a failure caused
145      * by a system-level error.
146      * @exception RemoteException - This exception is defined in the method
147      * signature to provide backward compatibility for enterprise
148      * beans written for the EJB 1.0 specification. Enterprise beans
149      * written for the EJB 1.1 and higher specification should throw
150      * the javax.ejb.EJBException instead of this exception.
151      */

152     public void ejbStore() {
153         // Nothing to be done for this simple example, in implicit persistance.
154
}
155
156     /**
157      * Sets the associated entity context. The container invokes this method on
158      * an instance after the instance has been created. This method is called in
159      * an unspecified transaction context.
160      * @param ctx - An EntityContext interface for the instance. The instance
161      * should store the reference to the context in an instance variable.
162      * @exception EJBException Thrown by the method to indicate a failure caused
163      * by a system-level error.
164      * @exception RemoteException - This exception is defined in the method
165      * signature to provide backward compatibility for enterprise
166      * beans written for the EJB 1.0 specification. Enterprise beans
167      * written for the EJB 1.1 and higher specification should throw
168      * the javax.ejb.EJBException instead of this exception.
169      */

170     public void setEntityContext(EntityContext ctx) {
171
172         // Keep the entity context in object
173
entityContext = ctx;
174     }
175
176     /**
177      * Unsets the associated entity context. The container calls this method
178      * before removing the instance. This is the last method that the container
179      * invokes on the instance. The Java garbage collector will eventually
180      * invoke the finalize() method on the instance. This method is called in an
181      * unspecified transaction context.
182      * @exception EJBException Thrown by the method to indicate a failure caused
183      * by a system-level error.
184      * @exception RemoteException - This exception is defined in the method
185      * signature to provide backward compatibility for enterprise
186      * beans written for the EJB 1.0 specification. Enterprise beans
187      * written for the EJB 1.1 and higher specification should throw
188      * the javax.ejb.EJBException instead of this exception.
189      */

190     public void unsetEntityContext() {
191         entityContext = null;
192     }
193
194     /**
195      * Business method to get the Account number
196      */

197     public int getNumber() {
198         return getAccno();
199     }
200
201     /*
202      * ========================= Account implementation
203      * ============================
204      */

205
206     public abstract String getCustomer();
207
208     public abstract void setCustomer(String customer);
209
210     public abstract double getBalance();
211
212     public abstract void setBalance(double balance);
213
214     public abstract int getAccno();
215
216     public abstract void setAccno(int accno);
217
218 }
Popular Tags