KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clusterDemo > BankAccountECL


1 // BankAccountECL.java
2

3 package org.objectweb.clusterDemo;
4
5 import javax.ejb.CreateException JavaDoc;
6 import javax.ejb.DuplicateKeyException JavaDoc;
7 import javax.ejb.EntityBean JavaDoc;
8 import javax.ejb.EntityContext JavaDoc;
9 import javax.ejb.RemoveException JavaDoc;
10
11 import org.objectweb.jonas.common.Log;
12 import org.objectweb.util.monolog.api.Logger;
13 import org.objectweb.util.monolog.api.BasicLevel;
14
15 /**
16  *
17  */

18 public abstract class BankAccountECL implements EntityBean JavaDoc {
19
20     static private Logger logger = null;
21
22     EntityContext JavaDoc ejbContext;
23
24     // ------------------------------------------------------------------
25
// EntityBean implementation
26
// ------------------------------------------------------------------
27

28     /**
29      * Set the associated entity context. The container invokes this method on
30      * an instance after the instance has been created. This method is called in
31      * an unspecified transaction context.
32      * @param ctx - An EntityContext interface for the instance. The instance
33      * should store the reference to the context in an instance variable.
34      * @throws EJBException Thrown by the method to indicate a failure caused by
35      * a system-level error.
36      */

37     public void setEntityContext(EntityContext JavaDoc ctx) {
38         if (logger == null) {
39             logger = Log.getLogger("org.objectweb.jonas_tests");
40         }
41         logger.log(BasicLevel.DEBUG, "");
42         ejbContext = ctx;
43     }
44
45     /**
46      * Unset the associated entity context. The container calls this method
47      * before removing the instance. This is the last method that the container
48      * invokes on the instance. The Java garbage collector will eventually
49      * invoke the finalize() method on the instance. This method is called in an
50      * unspecified transaction context.
51      * @throws EJBException Thrown by the method to indicate a failure caused by
52      * a system-level error.
53      */

54     public void unsetEntityContext() {
55         logger.log(BasicLevel.DEBUG, "");
56         ejbContext = null;
57     }
58
59     /**
60      * A container invokes this method before it removes the EJB object that is
61      * currently associated with the instance. This method is invoked when a
62      * client invokes a remove operation on the enterprise Bean's home interface
63      * or the EJB object's remote interface. This method transitions the
64      * instance from the ready state to the pool of available instances. This
65      * method is called in the transaction context of the remove operation.
66      * @throws RemoveException The enterprise Bean does not allow destruction of
67      * the object.
68      * @throws EJBException - Thrown by the method to indicate a failure caused
69      * by a system-level error.
70      */

71     public void ejbRemove() throws RemoveException JavaDoc {
72         logger.log(BasicLevel.DEBUG, "");
73     }
74
75     /**
76      * A container invokes this method to instruct the instance to synchronize
77      * its state by loading it state from the underlying database. This method
78      * always executes in the proper transaction context.
79      * @throws EJBException Thrown by the method to indicate a failure caused by
80      * a system-level error.
81      */

82     public void ejbLoad() {
83         logger.log(BasicLevel.DEBUG, "");
84     }
85
86     /**
87      * A container invokes this method to instruct the instance to synchronize
88      * its state by storing it to the underlying database. This method always
89      * executes in the proper transaction context.
90      * @throws EJBException Thrown by the method to indicate a failure caused by
91      * a system-level error.
92      */

93     public void ejbStore() {
94         logger.log(BasicLevel.DEBUG, "");
95     }
96
97     /**
98      * There must be an ejbPostCreate par ejbCreate method
99      * @throws CreateException Failure to create an entity EJB object.
100      */

101     public void ejbPostCreate(int b, String JavaDoc n) throws CreateException JavaDoc {
102         logger.log(BasicLevel.DEBUG, "");
103     }
104
105     /**
106      * The Entity bean can define 0 or more ejbCreate methods.
107      * @throws CreateException Failure to create an entity EJB object.
108      * @throws DuplicateKeyException An object with the same key already exists.
109      */

110     public java.lang.String JavaDoc ejbCreate(int b, String JavaDoc n) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
111         logger.log(BasicLevel.DEBUG, "");
112
113         // Init here the bean fields
114
setBalance(b);
115         setName(n);
116
117         // In CMP, should return null.
118
return null;
119     }
120
121     /**
122      * A container invokes this method on an instance before the instance
123      * becomes disassociated with a specific EJB object.
124      */

125     public void ejbPassivate() {
126         logger.log(BasicLevel.DEBUG, "");
127     }
128
129     /**
130      * A container invokes this method when the instance is taken out of the
131      * pool of available instances to become associated with a specific EJB
132      * object.
133      */

134     public void ejbActivate() {
135         logger.log(BasicLevel.DEBUG, "");
136     }
137
138     // ------------------------------------------------------------------
139
// BankAccount implementation
140
// ------------------------------------------------------------------
141

142     /**
143      * credit method
144      */

145     public void putMoney(int value) {
146         logger.log(BasicLevel.DEBUG, "");
147         setBalance(getBalance() + value);
148     }
149
150     /**
151      * credit method
152      */

153     public void getMoney(int value) {
154         logger.log(BasicLevel.DEBUG, "");
155         setBalance(getBalance() - value);
156     }
157
158     public abstract String JavaDoc getName();
159
160     public abstract void setName(String JavaDoc name);
161
162     public abstract double getBalance();
163
164     public abstract void setBalance(double balance);
165
166 }
Popular Tags