KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > cluster > IdentityEC


1 package org.objectweb.jonas.jtests.beans.cluster;
2
3 import javax.ejb.CreateException JavaDoc;
4 import javax.ejb.DuplicateKeyException JavaDoc;
5 import javax.ejb.EntityBean JavaDoc;
6 import javax.ejb.EntityContext JavaDoc;
7 import javax.ejb.RemoveException JavaDoc;
8
9 import org.objectweb.jonas.common.Log;
10 import org.objectweb.util.monolog.api.BasicLevel;
11 import org.objectweb.util.monolog.api.Logger;
12
13 public class IdentityEC implements EntityBean JavaDoc {
14
15     static private Logger logger = null;
16     EntityContext JavaDoc ejbContext;
17
18     // ------------------------------------------------------------------
19
// State of the bean.
20
// They must be public for Container Managed Persistence.
21
// ------------------------------------------------------------------
22
public String JavaDoc name;
23     public int number;
24
25     // ------------------------------------------------------------------
26
// EntityBean implementation
27
// ------------------------------------------------------------------
28

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

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

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

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

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

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

109     public String JavaDoc ejbCreate(String JavaDoc s, int i) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
110
111     // Init here the bean fields
112
name = s;
113     number = i;
114     logger.log(BasicLevel.DEBUG, "="+number);
115
116     // In CMP, should return null.
117
return null;
118     }
119     
120     /**
121      * There must be an ejbPostCreate par ejbCreate method
122      *
123      * @throws CreateException Failure to create an entity EJB object.
124      */

125     public void ejbPostCreate(String JavaDoc s, int i) throws CreateException JavaDoc {
126     logger.log(BasicLevel.DEBUG, "="+number);
127     }
128
129     /**
130      * A container invokes this method on an instance before the instance
131      * becomes disassociated with a specific EJB object.
132      */

133     public void ejbPassivate() {
134     logger.log(BasicLevel.DEBUG, "="+number);
135     }
136
137     /**
138      * A container invokes this method when the instance is taken out of
139      * the pool of available instances to become associated with a specific
140      * EJB object.
141      */

142     public void ejbActivate() {
143     logger.log(BasicLevel.DEBUG, "="+number);
144     }
145     
146     // ------------------------------------------------------------------
147
// Identity implementation
148
// ------------------------------------------------------------------
149

150     /**
151      * getName
152      */

153     public String JavaDoc getName() {
154     logger.log(BasicLevel.DEBUG, "="+number);
155     return name;
156     }
157
158     /**
159      * getNumber
160      */

161     public int getNumber() {
162     logger.log(BasicLevel.DEBUG, "="+number);
163     return number;
164     }
165
166     /**
167      * setNumber
168      */

169     public void setNumber(int val) {
170     number = val;
171     logger.log(BasicLevel.DEBUG, "="+number);
172     }
173
174 }
175
Popular Tags