1 package org.apache.turbine.services.security.torque.om;
2
3
4 import java.math.BigDecimal;
5 import java.sql.Connection;
6 import java.util.ArrayList;
7 import java.util.Collections;
8 import java.util.Date;
9 import java.util.List;
10
11 import org.apache.commons.lang.ObjectUtils;
12 import org.apache.torque.TorqueException;
13 import org.apache.torque.om.BaseObject;
14 import org.apache.torque.om.ComboKey;
15 import org.apache.torque.om.DateKey;
16 import org.apache.torque.om.NumberKey;
17 import org.apache.torque.om.ObjectKey;
18 import org.apache.torque.om.SimpleKey;
19 import org.apache.torque.om.StringKey;
20 import org.apache.torque.om.Persistent;
21 import org.apache.torque.util.Criteria;
22 import org.apache.torque.util.Transaction;
23
24
25
26
27
28 /***
29 * This class was autogenerated by Torque on:
30 *
31 * [Mon May 28 10:17:20 EST 2007]
32 *
33 * You should not use this class directly. It should not even be
34 * extended all references should be to TurbineUserGroupRole
35 */
36 public abstract class BaseTurbineUserGroupRole extends BaseObject
37 {
38 /*** The Peer class */
39 private static final TurbineUserGroupRolePeer peer =
40 new TurbineUserGroupRolePeer();
41
42
43 /*** The value for the userId field */
44 private int userId;
45
46 /*** The value for the groupId field */
47 private int groupId;
48
49 /*** The value for the roleId field */
50 private int roleId;
51
52
53 /***
54 * Get the UserId
55 *
56 * @return int
57 */
58 public int getUserId()
59 {
60 return userId;
61 }
62
63
64 /***
65 * Set the value of UserId
66 *
67 * @param v new value
68 */
69 public void setUserId(int v) throws TorqueException
70 {
71
72 if (this.userId != v)
73 {
74 this.userId = v;
75 setModified(true);
76 }
77
78
79 if (aTurbineUser != null && !(aTurbineUser.getUserId() == v))
80 {
81 aTurbineUser = null;
82 }
83
84 }
85
86 /***
87 * Get the GroupId
88 *
89 * @return int
90 */
91 public int getGroupId()
92 {
93 return groupId;
94 }
95
96
97 /***
98 * Set the value of GroupId
99 *
100 * @param v new value
101 */
102 public void setGroupId(int v) throws TorqueException
103 {
104
105 if (this.groupId != v)
106 {
107 this.groupId = v;
108 setModified(true);
109 }
110
111
112 if (aTurbineGroup != null && !(aTurbineGroup.getGroupId() == v))
113 {
114 aTurbineGroup = null;
115 }
116
117 }
118
119 /***
120 * Get the RoleId
121 *
122 * @return int
123 */
124 public int getRoleId()
125 {
126 return roleId;
127 }
128
129
130 /***
131 * Set the value of RoleId
132 *
133 * @param v new value
134 */
135 public void setRoleId(int v) throws TorqueException
136 {
137
138 if (this.roleId != v)
139 {
140 this.roleId = v;
141 setModified(true);
142 }
143
144
145 if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v))
146 {
147 aTurbineRole = null;
148 }
149
150 }
151
152
153
154
155
156 private TurbineUser aTurbineUser;
157
158 /***
159 * Declares an association between this object and a TurbineUser object
160 *
161 * @param v TurbineUser
162 * @throws TorqueException
163 */
164 public void setTurbineUser(TurbineUser v) throws TorqueException
165 {
166 if (v == null)
167 {
168 setUserId( 0);
169 }
170 else
171 {
172 setUserId(v.getUserId());
173 }
174 aTurbineUser = v;
175 }
176
177
178 /***
179 * Returns the associated TurbineUser object.
180 * If it was not retrieved before, the object is retrieved from
181 * the database
182 *
183 * @return the associated TurbineUser object
184 * @throws TorqueException
185 */
186 public TurbineUser getTurbineUser()
187 throws TorqueException
188 {
189 if (aTurbineUser == null && (this.userId != 0))
190 {
191 aTurbineUser = TurbineUserPeer.retrieveByPK(SimpleKey.keyFor(this.userId));
192
193
194
195
196
197
198
199
200
201
202 }
203 return aTurbineUser;
204 }
205
206 /***
207 * Return the associated TurbineUser object
208 * If it was not retrieved before, the object is retrieved from
209 * the database using the passed connection
210 *
211 * @param connection the connection used to retrieve the associated object
212 * from the database, if it was not retrieved before
213 * @return the associated TurbineUser object
214 * @throws TorqueException
215 */
216 public TurbineUser getTurbineUser(Connection connection)
217 throws TorqueException
218 {
219 if (aTurbineUser == null && (this.userId != 0))
220 {
221 aTurbineUser = TurbineUserPeer.retrieveByPK(SimpleKey.keyFor(this.userId), connection);
222
223
224
225
226
227
228
229
230
231
232 }
233 return aTurbineUser;
234 }
235
236 /***
237 * Provides convenient way to set a relationship based on a
238 * ObjectKey, for example
239 * <code>bar.setFooKey(foo.getPrimaryKey())</code>
240 *
241 */
242 public void setTurbineUserKey(ObjectKey key) throws TorqueException
243 {
244
245 setUserId(((NumberKey) key).intValue());
246 }
247
248
249
250
251 private TurbineGroup aTurbineGroup;
252
253 /***
254 * Declares an association between this object and a TurbineGroup object
255 *
256 * @param v TurbineGroup
257 * @throws TorqueException
258 */
259 public void setTurbineGroup(TurbineGroup v) throws TorqueException
260 {
261 if (v == null)
262 {
263 setGroupId( 0);
264 }
265 else
266 {
267 setGroupId(v.getGroupId());
268 }
269 aTurbineGroup = v;
270 }
271
272
273 /***
274 * Returns the associated TurbineGroup object.
275 * If it was not retrieved before, the object is retrieved from
276 * the database
277 *
278 * @return the associated TurbineGroup object
279 * @throws TorqueException
280 */
281 public TurbineGroup getTurbineGroup()
282 throws TorqueException
283 {
284 if (aTurbineGroup == null && (this.groupId != 0))
285 {
286 aTurbineGroup = TurbineGroupPeer.retrieveByPK(SimpleKey.keyFor(this.groupId));
287
288
289
290
291
292
293
294
295
296
297 }
298 return aTurbineGroup;
299 }
300
301 /***
302 * Return the associated TurbineGroup object
303 * If it was not retrieved before, the object is retrieved from
304 * the database using the passed connection
305 *
306 * @param connection the connection used to retrieve the associated object
307 * from the database, if it was not retrieved before
308 * @return the associated TurbineGroup object
309 * @throws TorqueException
310 */
311 public TurbineGroup getTurbineGroup(Connection connection)
312 throws TorqueException
313 {
314 if (aTurbineGroup == null && (this.groupId != 0))
315 {
316 aTurbineGroup = TurbineGroupPeer.retrieveByPK(SimpleKey.keyFor(this.groupId), connection);
317
318
319
320
321
322
323
324
325
326
327 }
328 return aTurbineGroup;
329 }
330
331 /***
332 * Provides convenient way to set a relationship based on a
333 * ObjectKey, for example
334 * <code>bar.setFooKey(foo.getPrimaryKey())</code>
335 *
336 */
337 public void setTurbineGroupKey(ObjectKey key) throws TorqueException
338 {
339
340 setGroupId(((NumberKey) key).intValue());
341 }
342
343
344
345
346 private TurbineRole aTurbineRole;
347
348 /***
349 * Declares an association between this object and a TurbineRole object
350 *
351 * @param v TurbineRole
352 * @throws TorqueException
353 */
354 public void setTurbineRole(TurbineRole v) throws TorqueException
355 {
356 if (v == null)
357 {
358 setRoleId( 0);
359 }
360 else
361 {
362 setRoleId(v.getRoleId());
363 }
364 aTurbineRole = v;
365 }
366
367
368 /***
369 * Returns the associated TurbineRole object.
370 * If it was not retrieved before, the object is retrieved from
371 * the database
372 *
373 * @return the associated TurbineRole object
374 * @throws TorqueException
375 */
376 public TurbineRole getTurbineRole()
377 throws TorqueException
378 {
379 if (aTurbineRole == null && (this.roleId != 0))
380 {
381 aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId));
382
383
384
385
386
387
388
389
390
391
392 }
393 return aTurbineRole;
394 }
395
396 /***
397 * Return the associated TurbineRole object
398 * If it was not retrieved before, the object is retrieved from
399 * the database using the passed connection
400 *
401 * @param connection the connection used to retrieve the associated object
402 * from the database, if it was not retrieved before
403 * @return the associated TurbineRole object
404 * @throws TorqueException
405 */
406 public TurbineRole getTurbineRole(Connection connection)
407 throws TorqueException
408 {
409 if (aTurbineRole == null && (this.roleId != 0))
410 {
411 aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId), connection);
412
413
414
415
416
417
418
419
420
421
422 }
423 return aTurbineRole;
424 }
425
426 /***
427 * Provides convenient way to set a relationship based on a
428 * ObjectKey, for example
429 * <code>bar.setFooKey(foo.getPrimaryKey())</code>
430 *
431 */
432 public void setTurbineRoleKey(ObjectKey key) throws TorqueException
433 {
434
435 setRoleId(((NumberKey) key).intValue());
436 }
437
438
439 private static List fieldNames = null;
440
441 /***
442 * Generate a list of field names.
443 *
444 * @return a list of field names
445 */
446 public static synchronized List getFieldNames()
447 {
448 if (fieldNames == null)
449 {
450 fieldNames = new ArrayList();
451 fieldNames.add("UserId");
452 fieldNames.add("GroupId");
453 fieldNames.add("RoleId");
454 fieldNames = Collections.unmodifiableList(fieldNames);
455 }
456 return fieldNames;
457 }
458
459 /***
460 * Retrieves a field from the object by name passed in as a String.
461 *
462 * @param name field name
463 * @return value
464 */
465 public Object getByName(String name)
466 {
467 if (name.equals("UserId"))
468 {
469 return new Integer(getUserId());
470 }
471 if (name.equals("GroupId"))
472 {
473 return new Integer(getGroupId());
474 }
475 if (name.equals("RoleId"))
476 {
477 return new Integer(getRoleId());
478 }
479 return null;
480 }
481
482 /***
483 * Retrieves a field from the object by name passed in
484 * as a String. The String must be one of the static
485 * Strings defined in this Class' Peer.
486 *
487 * @param name peer name
488 * @return value
489 */
490 public Object getByPeerName(String name)
491 {
492 if (name.equals(TurbineUserGroupRolePeer.USER_ID))
493 {
494 return new Integer(getUserId());
495 }
496 if (name.equals(TurbineUserGroupRolePeer.GROUP_ID))
497 {
498 return new Integer(getGroupId());
499 }
500 if (name.equals(TurbineUserGroupRolePeer.ROLE_ID))
501 {
502 return new Integer(getRoleId());
503 }
504 return null;
505 }
506
507 /***
508 * Retrieves a field from the object by Position as specified
509 * in the xml schema. Zero-based.
510 *
511 * @param pos position in xml schema
512 * @return value
513 */
514 public Object getByPosition(int pos)
515 {
516 if (pos == 0)
517 {
518 return new Integer(getUserId());
519 }
520 if (pos == 1)
521 {
522 return new Integer(getGroupId());
523 }
524 if (pos == 2)
525 {
526 return new Integer(getRoleId());
527 }
528 return null;
529 }
530
531 /***
532 * Stores the object in the database. If the object is new,
533 * it inserts it; otherwise an update is performed.
534 *
535 * @throws Exception
536 */
537 public void save() throws Exception
538 {
539 save(TurbineUserGroupRolePeer.getMapBuilder()
540 .getDatabaseMap().getName());
541 }
542
543 /***
544 * Stores the object in the database. If the object is new,
545 * it inserts it; otherwise an update is performed.
546 * Note: this code is here because the method body is
547 * auto-generated conditionally and therefore needs to be
548 * in this file instead of in the super class, BaseObject.
549 *
550 * @param dbName
551 * @throws TorqueException
552 */
553 public void save(String dbName) throws TorqueException
554 {
555 Connection con = null;
556 try
557 {
558 con = Transaction.begin(dbName);
559 save(con);
560 Transaction.commit(con);
561 }
562 catch(TorqueException e)
563 {
564 Transaction.safeRollback(con);
565 throw e;
566 }
567 }
568
569 /*** flag to prevent endless save loop, if this object is referenced
570 by another object which falls in this transaction. */
571 private boolean alreadyInSave = false;
572 /***
573 * Stores the object in the database. If the object is new,
574 * it inserts it; otherwise an update is performed. This method
575 * is meant to be used as part of a transaction, otherwise use
576 * the save() method and the connection details will be handled
577 * internally
578 *
579 * @param con
580 * @throws TorqueException
581 */
582 public void save(Connection con) throws TorqueException
583 {
584 if (!alreadyInSave)
585 {
586 alreadyInSave = true;
587
588
589
590
591 if (isModified())
592 {
593 if (isNew())
594 {
595 TurbineUserGroupRolePeer.doInsert((TurbineUserGroupRole) this, con);
596 setNew(false);
597 }
598 else
599 {
600 TurbineUserGroupRolePeer.doUpdate((TurbineUserGroupRole) this, con);
601 }
602 }
603
604 alreadyInSave = false;
605 }
606 }
607
608
609
610 private final SimpleKey[] pks = new SimpleKey[3];
611 private final ComboKey comboPK = new ComboKey(pks);
612
613 /***
614 * Set the PrimaryKey with an ObjectKey
615 *
616 * @param key
617 */
618 public void setPrimaryKey(ObjectKey key) throws TorqueException
619 {
620 SimpleKey[] keys = (SimpleKey[]) key.getValue();
621 SimpleKey tmpKey = null;
622 setUserId(((NumberKey)keys[0]).intValue());
623 setGroupId(((NumberKey)keys[1]).intValue());
624 setRoleId(((NumberKey)keys[2]).intValue());
625 }
626
627 /***
628 * Set the PrimaryKey using SimpleKeys.
629 *
630 * @param userId int
631 * @param groupId int
632 * @param roleId int
633 */
634 public void setPrimaryKey( int userId, int groupId, int roleId)
635 throws TorqueException
636 {
637 setUserId(userId);
638 setGroupId(groupId);
639 setRoleId(roleId);
640 }
641
642 /***
643 * Set the PrimaryKey using a String.
644 */
645 public void setPrimaryKey(String key) throws TorqueException
646 {
647 setPrimaryKey(new ComboKey(key));
648 }
649
650 /***
651 * returns an id that differentiates this object from others
652 * of its class.
653 */
654 public ObjectKey getPrimaryKey()
655 {
656 pks[0] = SimpleKey.keyFor(getUserId());
657 pks[1] = SimpleKey.keyFor(getGroupId());
658 pks[2] = SimpleKey.keyFor(getRoleId());
659 return comboPK;
660 }
661
662
663 /***
664 * Makes a copy of this object.
665 * It creates a new object filling in the simple attributes.
666 * It then fills all the association collections and sets the
667 * related objects to isNew=true.
668 */
669 public TurbineUserGroupRole copy() throws TorqueException
670 {
671 return copyInto(new TurbineUserGroupRole());
672 }
673
674 protected TurbineUserGroupRole copyInto(TurbineUserGroupRole copyObj) throws TorqueException
675 {
676 copyObj.setUserId(userId);
677 copyObj.setGroupId(groupId);
678 copyObj.setRoleId(roleId);
679
680 copyObj.setUserId( 0);
681 copyObj.setGroupId( 0);
682 copyObj.setRoleId( 0);
683
684 return copyObj;
685 }
686
687 /***
688 * returns a peer instance associated with this om. Since Peer classes
689 * are not to have any instance attributes, this method returns the
690 * same instance for all member of this class. The method could therefore
691 * be static, but this would prevent one from overriding the behavior.
692 */
693 public TurbineUserGroupRolePeer getPeer()
694 {
695 return peer;
696 }
697
698
699 public String toString()
700 {
701 StringBuffer str = new StringBuffer();
702 str.append("TurbineUserGroupRole:\n");
703 str.append("UserId = ")
704 .append(getUserId())
705 .append("\n");
706 str.append("GroupId = ")
707 .append(getGroupId())
708 .append("\n");
709 str.append("RoleId = ")
710 .append(getRoleId())
711 .append("\n");
712 return(str.toString());
713 }
714 }