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