KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > relation > rcycle > PersonEC2


1 // PersonEC2.java
2

3 package org.objectweb.jonas.jtests.beans.relation.rcycle;
4
5 import java.util.ArrayList JavaDoc;
6 import java.util.Collection JavaDoc;
7 import java.util.Iterator JavaDoc;
8
9 import javax.ejb.FinderException JavaDoc;
10
11 import org.objectweb.jonas.common.Log;
12 import org.objectweb.util.monolog.api.BasicLevel;
13 import org.objectweb.util.monolog.api.Logger;
14
15
16 /**
17  * Class implementation of bean Person which is a CMP2 entity. <br>
18  * This bean Person have several bidirectional relation-ships with itself. <br>
19  * The CMP fields are: <br>
20  * - id <br>
21  * - name <br>
22  * - sex (male or female). <br>
23  * The CMR fields are: <br>
24  * - spouse, (One-One-bi relation), <br>
25  * - parents and children, (Many-Many-bi relation), <br>
26  * - guardian and is-guardian-of, (One-Many-bi relation). <br>
27  *
28  * @author Helene Joanin
29  */

30 public abstract class PersonEC2 implements javax.ejb.EntityBean JavaDoc {
31
32     private static Logger logger = null;
33     private javax.ejb.EntityContext JavaDoc ejbContext;
34     private PersonHomeLocal plHome = null;
35
36
37     // ---------------------------------------------------------------------
38
// Get and Set accessor methods of cmp and cmr fields
39
// ---------------------------------------------------------------------
40

41     public abstract Integer JavaDoc getId();
42     public abstract void setId(Integer JavaDoc id);
43
44     public abstract String JavaDoc getName();
45     public abstract void setName(String JavaDoc name);
46
47     public abstract int getSex();
48     public abstract void setSex(int sex);
49
50     public abstract PersonLocal getSpouse();
51     public abstract void setSpouse(PersonLocal spouse);
52
53     public abstract Collection JavaDoc getParents();
54     public abstract void setParents(Collection JavaDoc parents);
55
56     public abstract Collection JavaDoc getChildren();
57     public abstract void setChildren(Collection JavaDoc parents);
58
59     public abstract PersonLocal getGuardian();
60     public abstract void setGuardian(PersonLocal guardian);
61
62     public abstract Collection JavaDoc getGuardianOf();
63     public abstract void setGuardianOf(Collection JavaDoc guardianOf);
64
65
66     // ---------------------------------------------------------------------
67
// Call back methods for those defined in the bean interfaces.
68
// ---------------------------------------------------------------------
69

70     public java.lang.String JavaDoc ejbCreate(Integer JavaDoc id, String JavaDoc name, int sex)
71         throws javax.ejb.CreateException JavaDoc {
72         logger.log(BasicLevel.DEBUG, "id = " + id + ", name = " + name + ", sex = " + sex);
73         // Init here the bean fields
74
setId(id);
75         setName(name);
76         setSex(sex);
77         return null;
78     }
79
80     public void ejbPostCreate(Integer JavaDoc id, String JavaDoc name, int sex) {
81         logger.log(BasicLevel.DEBUG, "");
82     }
83
84     public Integer JavaDoc retrieveSpouse() {
85         PersonLocal spouse = getSpouse();
86         if (spouse == null) {
87             logger.log(BasicLevel.DEBUG, "return null");
88             return null;
89         } else {
90             logger.log(BasicLevel.DEBUG, "return " + spouse.getId());
91             return spouse.getId();
92         }
93     }
94
95     public void assignSpouse(Integer JavaDoc id) throws FinderException JavaDoc {
96         logger.log(BasicLevel.DEBUG, "param=" + id);
97         if (id != null) {
98             PersonLocal spouse = plHome.findByPrimaryKey(id);
99             setSpouse(spouse);
100         } else {
101             setSpouse(null);
102         }
103     }
104
105     public Collection JavaDoc retrieveParents() {
106         Collection JavaDoc ps = getParents();
107         ArrayList JavaDoc result;
108         if (ps.size() <= 0) {
109             result = new ArrayList JavaDoc();
110         } else {
111             result = new ArrayList JavaDoc(ps.size());
112         }
113         for (Iterator JavaDoc it = ps.iterator(); it.hasNext();) {
114             result.add(((PersonLocal) it.next()).getPrimaryKey());
115         }
116         logger.log(BasicLevel.DEBUG, "return=" + result);
117         return result;
118     }
119
120     public void assignParents(Collection JavaDoc c) throws FinderException JavaDoc {
121         logger.log(BasicLevel.DEBUG, "param=" + c);
122         ArrayList JavaDoc al;
123         if (c == null) {
124             al = new ArrayList JavaDoc();
125         } else {
126             if (c.size() <= 0) {
127                 al = new ArrayList JavaDoc();
128             } else {
129                 al = new ArrayList JavaDoc(c.size());
130                 for (Iterator JavaDoc it = c.iterator(); it.hasNext();) {
131                     al.add(plHome.findByPrimaryKey((Integer JavaDoc) it.next()));
132                 }
133             }
134         }
135         setParents(al);
136     }
137
138     public void addInParents(Integer JavaDoc id) throws FinderException JavaDoc {
139         logger.log(BasicLevel.DEBUG, "param=" + id);
140         getParents().add(plHome.findByPrimaryKey(id));
141     }
142
143     public Collection JavaDoc retrieveChildren() {
144         Collection JavaDoc ps = getChildren();
145         ArrayList JavaDoc result;
146         if (ps.size() <= 0) {
147             result = new ArrayList JavaDoc();
148         } else {
149             result = new ArrayList JavaDoc(ps.size());
150         }
151         for (Iterator JavaDoc it = ps.iterator(); it.hasNext();) {
152             result.add(((PersonLocal) it.next()).getPrimaryKey());
153         }
154         logger.log(BasicLevel.DEBUG, "return=" + result);
155         return result;
156     }
157
158     public Collection JavaDoc retrieveChildrenNames() {
159         Collection JavaDoc ps = getChildren();
160         ArrayList JavaDoc result;
161         if (ps.size() <= 0) {
162             result = new ArrayList JavaDoc();
163         } else {
164             result = new ArrayList JavaDoc(ps.size());
165         }
166         for (Iterator JavaDoc it = ps.iterator(); it.hasNext();) {
167             result.add(((PersonLocal) it.next()).getName());
168         }
169         logger.log(BasicLevel.DEBUG, "return=" + result);
170         return result;
171     }
172
173     public void assignChildren(Collection JavaDoc c) throws FinderException JavaDoc {
174         logger.log(BasicLevel.DEBUG, "param=" + c);
175         ArrayList JavaDoc al;
176         if (c == null) {
177             al = new ArrayList JavaDoc();
178         } else {
179             if (c.size() <= 0) {
180                 al = new ArrayList JavaDoc();
181             } else {
182                 al = new ArrayList JavaDoc(c.size());
183                 for (Iterator JavaDoc it = c.iterator(); it.hasNext();) {
184                     al.add(plHome.findByPrimaryKey((Integer JavaDoc) it.next()));
185                 }
186             }
187         }
188         setChildren(al);
189     }
190
191     public void addInChildren(Integer JavaDoc id) throws FinderException JavaDoc {
192         logger.log(BasicLevel.DEBUG, "param=" + id);
193         getChildren().add(plHome.findByPrimaryKey(id));
194     }
195
196
197     public Integer JavaDoc retrieveGuardian() {
198         PersonLocal guardian = getGuardian();
199         if (guardian == null) {
200             logger.log(BasicLevel.DEBUG, "return null");
201             return null;
202         } else {
203             logger.log(BasicLevel.DEBUG, "return " + guardian.getId());
204             return guardian.getId();
205         }
206     }
207
208     public void assignGuardian(Integer JavaDoc id) throws FinderException JavaDoc {
209         logger.log(BasicLevel.DEBUG, "param=" + id);
210         if (id != null) {
211             PersonLocal guardian = plHome.findByPrimaryKey(id);
212             setGuardian(guardian);
213         } else {
214             setGuardian(null);
215         }
216     }
217
218     public Collection JavaDoc retrieveGuardianOf() {
219         Collection JavaDoc ps = getGuardianOf();
220         ArrayList JavaDoc result;
221         if (ps.size() <= 0) {
222             result = new ArrayList JavaDoc();
223         } else {
224             result = new ArrayList JavaDoc(ps.size());
225         }
226         for (Iterator JavaDoc it = ps.iterator(); it.hasNext();) {
227             result.add(((PersonLocal) it.next()).getPrimaryKey());
228         }
229         logger.log(BasicLevel.DEBUG, "return=" + result);
230         return result;
231     }
232
233     public void assignInGuardianOf(Collection JavaDoc c) throws FinderException JavaDoc {
234         logger.log(BasicLevel.DEBUG, "param=" + c);
235         ArrayList JavaDoc al;
236         if (c == null) {
237             al = new ArrayList JavaDoc();
238         } else {
239             if (c.size() <= 0) {
240                 al = new ArrayList JavaDoc();
241             } else {
242                 al = new ArrayList JavaDoc(c.size());
243                 for (Iterator JavaDoc it = c.iterator(); it.hasNext();) {
244                     al.add(plHome.findByPrimaryKey((Integer JavaDoc) it.next()));
245                 }
246             }
247         }
248         setGuardianOf(al);
249     }
250
251     public void addInGuardianOf(Integer JavaDoc id) throws FinderException JavaDoc {
252         logger.log(BasicLevel.DEBUG, "param=" + id);
253         getGuardianOf().add(plHome.findByPrimaryKey(id));
254     }
255
256     public boolean testCmrNull() throws FinderException JavaDoc {
257         PersonLocal g = plHome.findByPrimaryKey(new Integer JavaDoc(3));
258         PersonLocal sg = g.getSpouse();
259         if (sg == null) {
260             return true;
261         } else {
262             return false;
263         }
264     }
265
266     // ---------------------------------------------------------------------
267
// Standard call back methods of those defined in javax.ejb.EntityBean
268
// ---------------------------------------------------------------------
269

270     public void setEntityContext(javax.ejb.EntityContext JavaDoc ctx) {
271         // init the logger
272
if (logger == null) {
273             logger = Log.getLogger("org.objectweb.jonas_tests");
274         }
275         logger.log(BasicLevel.DEBUG, "");
276         // save the given EntityContext
277
ejbContext = ctx;
278         // get the PersonHomeLocal (local home of the current bean
279
plHome = (PersonHomeLocal) ejbContext.getEJBLocalHome();
280     }
281
282     public void unsetEntityContext() {
283         logger.log(BasicLevel.DEBUG, "");
284         ejbContext = null;
285     }
286
287     public void ejbRemove() throws javax.ejb.RemoveException JavaDoc {
288         logger.log(BasicLevel.DEBUG, "");
289     }
290
291
292     public void ejbLoad() {
293         logger.log(BasicLevel.DEBUG, "");
294     }
295
296
297     public void ejbStore() {
298         logger.log(BasicLevel.DEBUG, "");
299     }
300
301
302     public void ejbPassivate() {
303         logger.log(BasicLevel.DEBUG, "");
304     }
305
306
307     public void ejbActivate() {
308         logger.log(BasicLevel.DEBUG, "");
309     }
310
311 }
312
313
314
315
Popular Tags