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
31
32
33
34
35
36
37 public abstract class BaseTurbineUserGroupRole extends BaseObject
38 {
39
40 private static final long serialVersionUID = 1308842746584L;
41
42
43 private static final TurbineUserGroupRolePeer peer =
44 new TurbineUserGroupRolePeer();
45
46
47
48 private int userId;
49
50
51 private int groupId;
52
53
54 private int roleId;
55
56
57
58
59
60
61
62 public int getUserId()
63 {
64 return userId;
65 }
66
67
68
69
70
71
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
92
93
94
95 public int getGroupId()
96 {
97 return groupId;
98 }
99
100
101
102
103
104
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
125
126
127
128 public int getRoleId()
129 {
130 return roleId;
131 }
132
133
134
135
136
137
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
164
165
166
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
184
185
186
187
188
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
202
203
204
205
206
207
208
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
222
223
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
239
240
241
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
259
260
261
262
263
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
277
278
279
280
281
282
283
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
297
298
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
314
315
316
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
334
335
336
337
338
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
352
353
354
355
356
357
358
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
372
373
374
375
376 public void setTurbineRoleKey(ObjectKey key) throws TorqueException
377 {
378
379 setRoleId(((NumberKey) key).intValue());
380 }
381
382
383 private static List<String> fieldNames = null;
384
385
386
387
388
389
390 public static synchronized List<String> getFieldNames()
391 {
392 if (fieldNames == null)
393 {
394 fieldNames = new ArrayList<String>();
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
405
406
407
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
428
429
430
431
432
433
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
470
471
472
473
474
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
495
496
497
498
499
500
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
522
523
524
525
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
546
547
548
549
550
551
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
573
574
575
576
577 public void save() throws Exception
578 {
579 save(TurbineUserGroupRolePeer.DATABASE_NAME);
580 }
581
582
583
584
585
586
587
588
589
590
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
609
610 private boolean alreadyInSave = false;
611
612
613
614
615
616
617
618
619
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
654
655
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
667
668
669
670
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
682
683 public void setPrimaryKey(String key) throws TorqueException
684 {
685 setPrimaryKey(new ComboKey(key));
686 }
687
688
689
690
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
703
704
705
706
707 public TurbineUserGroupRole copy() throws TorqueException
708 {
709 return copy(true);
710 }
711
712
713
714
715
716
717
718
719
720 public TurbineUserGroupRole copy(Connection con) throws TorqueException
721 {
722 return copy(true, con);
723 }
724
725
726
727
728
729
730
731
732
733
734 public TurbineUserGroupRole copy(boolean deepcopy) throws TorqueException
735 {
736 return copyInto(new TurbineUserGroupRole(), deepcopy);
737 }
738
739
740
741
742
743
744
745
746
747
748
749 public TurbineUserGroupRole copy(boolean deepcopy, Connection con) throws TorqueException
750 {
751 return copyInto(new TurbineUserGroupRole(), deepcopy, con);
752 }
753
754
755
756
757
758
759
760 protected TurbineUserGroupRole copyInto(TurbineUserGroupRole copyObj) throws TorqueException
761 {
762 return copyInto(copyObj, true);
763 }
764
765
766
767
768
769
770
771
772
773 protected TurbineUserGroupRole copyInto(TurbineUserGroupRole copyObj, Connection con) throws TorqueException
774 {
775 return copyInto(copyObj, true, con);
776 }
777
778
779
780
781
782
783
784
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
805
806
807
808
809
810
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
832
833
834
835
836 public TurbineUserGroupRolePeer getPeer()
837 {
838 return peer;
839 }
840
841
842
843
844
845
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 }