KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > olstore > entity > UserBean


1 /**
2  * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA
18  *
19  * Component of: Red Hat Application Server
20  *
21  * Initial Developers: Aizaz Ahmed
22  * Vivek Lakshmanan
23  * Andrew Overholt
24  * Matthew Wringe
25  *
26  */

27
28 /*
29  * UserBean.java
30  *
31  * Created on Aug 16, 2004
32  *
33  */

34 package olstore.entity;
35
36 import javax.ejb.EntityBean;
37
38 import olstore.entity.AddressLocal;
39
40 import java.util.Collection;
41
42 /**
43  * @ejb.bean name="User"
44  * description="This bean is used to store information about the user."
45  * type="CMP"
46  * schema="olstore_user"
47  * primkey-field="username"
48  * reentrant="false"
49  * cmp-version="2.x"
50  * view-type="local"
51  * local-jndi-name="UserLocal_L"
52  *
53  * @ejb.relation
54  * name="Friend-User"
55  * role-name"User-can-be-a-friend"
56  * target-ejb="Friend"
57  *
58  *
59  * @ejb.transaction
60  * type="Required"
61  *
62  *--
63  * This is needed for JOnAS.
64  * If you are not using JOnAS you can safely remove the tags below.
65  * @jonas.bean ejb-name="User"
66  * jndi-name="UserLocal"
67  * @jonas.jdbc-mapping jndi-name="jdbc_1" jdbc-table-name="olstore_user"
68  * --
69  *
70  * @ejb.persistence
71  *
72  * @ejb.finder
73  * query="SELECT OBJECT(a) FROM olstore_user as a"
74  * signature="java.util.Collection findAll()"
75  *
76  * @ejb.finder
77  * query="SELECT OBJECT(a) FROM olstore_user as a WHERE a.username = ?1"
78  * signature="olstore.entity.UserLocal findByUsername(java.lang.String username)"
79  *
80  * @ejb.finder
81  * query="SELECT f.user FROM olstore_user u, IN (u.friends) f WHERE u.username = ?1 AND ?2 MEMBER OF f.user.purchased"
82  * signature="java.util.Collection findByFriendsOfPurchased(java.lang.String username, olstore.entity.ItemLocal purchasedItem)"
83  *
84  *
85  *
86  *--
87  * This is needed for JOnAS.
88  * If you are not using JOnAS you can safely remove the tags below.
89  * @jonas.bean ejb-name="User"
90  * @jonas.finder-method-jdbc-mapping method-name="findAll"
91  * jdbc-where-clause=""
92  * @jonas.jdbc-mapping jndi-name="jdbc_1"
93  * jdbc-table-name="olstore_user"
94  *
95  *--
96  *
97  **/

98
99 public abstract class UserBean implements EntityBean {
100     
101     /**
102      * The ejbCreate method.
103      *
104      * @ejb.create-method
105      */

106     public java.lang.String ejbCreate(String username, String role,String lname, String fname, String emailAdd, String phoneNum, String passwd) throws javax.ejb.CreateException {
107         setUsername (username);
108         setLname (lname);
109         setFname (fname);
110         setEmailAdd (emailAdd);
111         setPhoneNum (phoneNum);
112         setPasswd (passwd);
113         setRole (role);
114         return null;
115     }
116     
117     /**
118      * The container invokes this method immediately after it calls ejbCreate.
119      *
120      */

121     public void ejbPostCreate(String username, String role, String lname, String fname, String emailAdd, String phoneNum, String passwd) throws javax.ejb.CreateException {
122     }
123     
124     /**
125      * Returns the username
126      * @return the username
127      *
128      * @ejb.persistent-field
129      * @ejb.persistence
130      * column-name="username"
131      * sql-type="VARCHAR"
132      * @ejb.pk-field
133      * @ejb.interface-method
134      *
135      */

136     public abstract java.lang.String getUsername();
137     
138     /**
139      * Sets the username
140      *
141      * @param java.lang.String the new username value
142      *
143      * @ejb.interface-method
144      */

145     public abstract void setUsername(java.lang.String username);
146     
147     /**
148      * Returns the fname
149      * @return the fname
150      *
151      * @ejb.persistent-field
152      * @ejb.persistence
153      * column-name="fname"
154      * sql-type="VARCHAR"
155      *
156      * @ejb.interface-method
157      *
158      */

159     public abstract java.lang.String getFname();
160     
161     /**
162      * Sets the fname
163      *
164      * @param java.lang.String the new fname value
165      *
166      * @ejb.interface-method
167      */

168     public abstract void setFname(java.lang.String fname);
169     
170     /**
171      * Returns the lname
172      * @return the lname
173      *
174      * @ejb.persistent-field
175      * @ejb.persistence
176      * column-name="lname"
177      * sql-type="VARCHAR"
178      *
179      * @ejb.interface-method
180      *
181      */

182     public abstract java.lang.String getLname();
183     
184     /**
185      * Sets the lname
186      *
187      * @param java.lang.String the new lname value
188      *
189      * @ejb.interface-method
190      */

191     public abstract void setLname(java.lang.String lname);
192     
193     /**
194      * Returns the emailAdd
195      * @return the emailAdd
196      *
197      * @ejb.persistent-field
198      * @ejb.persistence
199      * column-name="emailAdd"
200      * sql-type="VARCHAR"
201      *
202      * @ejb.interface-method
203      *
204      */

205     public abstract java.lang.String getEmailAdd();
206     
207     /**
208      * Sets the emailAdd
209      *
210      * @param java.lang.String the new emailAdd value
211      *
212      * @ejb.interface-method
213      */

214     public abstract void setEmailAdd(java.lang.String emailAdd);
215     
216     /**
217      * Returns the phoneNum
218      * @return the phoneNum
219      *
220      * @ejb.persistent-field
221      * @ejb.persistence
222      * column-name="phoneNum"
223      * sql-type="VARCHAR"
224      *
225      * @ejb.interface-method
226      *
227      */

228     public abstract java.lang.String getPhoneNum();
229     
230     /**
231      * Sets the phoneNum
232      *
233      * @param java.lang.String the new phoneNum value
234      *
235      * @ejb.interface-method
236      */

237     public abstract void setPhoneNum(java.lang.String phoneNum);
238     
239     /**
240      * Returns the passwd
241      * @return the passwd
242      *
243      * @ejb.persistent-field
244      * @ejb.persistence
245      * column-name="passwd"
246      * sql-type="VARCHAR"
247      *
248      * @ejb.interface-method
249      *
250      */

251     public abstract java.lang.String getPasswd();
252     
253     /**
254      * Sets the passwd
255      *
256      * @param java.lang.String the new passwd value
257      *
258      * @ejb.interface-method
259      */

260     public abstract void setPasswd(java.lang.String passwd);
261     
262     /**
263      * Returns the role
264      * @return the role
265      *
266      * @ejb.persistent-field
267      * @ejb.persistence
268      * column-name="role"
269      * sql-type="VARCHAR"
270      *
271      * @ejb.interface-method
272      *
273      */

274     public abstract java.lang.String getRole();
275     
276     /**
277      * Sets the role
278      *
279      * @param java.lang.String the new role value
280      *
281      * @ejb.interface-method
282      */

283     public abstract void setRole(java.lang.String role);
284     
285     /**
286      * Returns the User's Address
287      *
288      * @return the User's Address
289      *
290      * @ejb.interface-method
291      *
292      * @ejb.relation
293      * name="User-Address"
294      * role-name="User-has-an-Address"
295      * target-ejb="Address"
296      *
297      */

298     
299     public abstract AddressLocal getAddress ();
300     
301     /**
302      *
303      * @param userAddress
304      *
305      * @ejb.interface-method
306      *
307      */

308     
309     public abstract void setAddress (AddressLocal userAddress);
310     
311     /**
312      * Returns the User's Orders
313      *
314      * @return the User's Orders
315      *
316      * @ejb.interface-method
317      *
318      * @ejb.relation
319      * name="User-Order"
320      * role-name="User-has-many-Orders"
321      * target-ejb="Order"
322      *
323      */

324     
325     public abstract Collection getOrders ();
326     public abstract void setOrders (Collection orders);
327     
328     /**
329      * Returns the User's Friends
330      *
331      * @return the User's Friends
332      *
333      * @ejb.interface-method
334      *
335      * @ejb.relation
336      * name="User-Friend"
337      * role-name="User-has-many-Friends"
338      * target-ejb="Friend"
339      * target-multiple="yes"
340      *
341      */

342     
343     public abstract Collection getFriends ();
344     
345     /**
346      * Sets the User's friends
347      *
348      * @param java.util.Collection friends
349      *
350      * @ejb.interface-method
351      *
352      * @ejb.transaction
353      * type="Required"
354      *
355      */

356     
357     public abstract void setFriends (Collection friends);
358     
359     /**
360      * Returns the User's purchased Items
361      *
362      * @return the User's purchased Items
363      *
364      * @ejb.interface-method
365      *
366      * @ejb.relation
367      * name="User-Item"
368      * role-name="User-has-many-Items"
369      * target-ejb="Item"
370      * target-multiple="yes"
371      *
372      */

373     
374     public abstract Collection getPurchased ();
375     
376     /**
377      * Sets the purchased items
378      *
379      * @param java.util.Collection the User's purchased items
380      *
381      * @ejb.interface-method
382      */

383     
384     public abstract void setPurchased (Collection purchased);
385     
386     /**
387      *
388      * @return
389      *
390      * @ejb.interface-method
391      *
392      */

393     
394     public boolean isAdmin () {
395         String role = getRole();
396         if ( role != null && ! role.equals("") && role.equals( "admin" ) ) {
397             return true;
398         } else {
399             return false;
400         }
401     }
402     
403 }
404
Popular Tags