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 BaseTurbineGroup extends BaseObject
38 {
39
40 private static final long serialVersionUID = 1308842746584L;
41
42
43 private static final TurbineGroupPeer peer =
44 new TurbineGroupPeer();
45
46
47
48 private int groupId;
49
50
51 private String name;
52
53
54
55
56
57
58
59 public int getGroupId()
60 {
61 return groupId;
62 }
63
64
65
66
67
68
69
70 public void setGroupId(int v) throws TorqueException
71 {
72
73 if (this.groupId != v)
74 {
75 this.groupId = v;
76 setModified(true);
77 }
78
79
80
81
82 if (collTurbineUserGroupRoles != null)
83 {
84 for (int i = 0; i < collTurbineUserGroupRoles.size(); i++)
85 {
86 ((TurbineUserGroupRole) collTurbineUserGroupRoles.get(i))
87 .setGroupId(v);
88 }
89 }
90 }
91
92
93
94
95
96
97 public String getName()
98 {
99 return name;
100 }
101
102
103
104
105
106
107
108 public void setName(String v)
109 {
110
111 if (!ObjectUtils.equals(this.name, v))
112 {
113 this.name = v;
114 setModified(true);
115 }
116
117
118 }
119
120
121
122
123
124
125
126 protected List<TurbineUserGroupRole> collTurbineUserGroupRoles;
127
128
129
130
131
132
133 protected void initTurbineUserGroupRoles()
134 {
135 if (collTurbineUserGroupRoles == null)
136 {
137 collTurbineUserGroupRoles = new ArrayList<TurbineUserGroupRole>();
138 }
139 }
140
141
142
143
144
145
146
147
148
149 public void addTurbineUserGroupRole(TurbineUserGroupRole l) throws TorqueException
150 {
151 getTurbineUserGroupRoles().add(l);
152 l.setTurbineGroup((TurbineGroup) this);
153 }
154
155
156
157
158
159
160
161
162 public void addTurbineUserGroupRole(TurbineUserGroupRole l, Connection con) throws TorqueException
163 {
164 getTurbineUserGroupRoles(con).add(l);
165 l.setTurbineGroup((TurbineGroup) this);
166 }
167
168
169
170
171 private Criteria lastTurbineUserGroupRolesCriteria = null;
172
173
174
175
176
177
178
179
180
181 public List<TurbineUserGroupRole> getTurbineUserGroupRoles()
182 throws TorqueException
183 {
184 if (collTurbineUserGroupRoles == null)
185 {
186 collTurbineUserGroupRoles = getTurbineUserGroupRoles(new Criteria(10));
187 }
188 return collTurbineUserGroupRoles;
189 }
190
191
192
193
194
195
196
197
198
199
200
201
202 public List<TurbineUserGroupRole> getTurbineUserGroupRoles(Criteria criteria) throws TorqueException
203 {
204 if (collTurbineUserGroupRoles == null)
205 {
206 if (isNew())
207 {
208 collTurbineUserGroupRoles = new ArrayList<TurbineUserGroupRole>();
209 }
210 else
211 {
212 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId() );
213 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelect(criteria);
214 }
215 }
216 else
217 {
218
219 if (!isNew())
220 {
221
222
223
224 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
225 if (!lastTurbineUserGroupRolesCriteria.equals(criteria))
226 {
227 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelect(criteria);
228 }
229 }
230 }
231 lastTurbineUserGroupRolesCriteria = criteria;
232
233 return collTurbineUserGroupRoles;
234 }
235
236
237
238
239
240
241
242
243
244 public List<TurbineUserGroupRole> getTurbineUserGroupRoles(Connection con) throws TorqueException
245 {
246 if (collTurbineUserGroupRoles == null)
247 {
248 collTurbineUserGroupRoles = getTurbineUserGroupRoles(new Criteria(10), con);
249 }
250 return collTurbineUserGroupRoles;
251 }
252
253
254
255
256
257
258
259
260
261
262
263
264
265 public List<TurbineUserGroupRole> getTurbineUserGroupRoles(Criteria criteria, Connection con)
266 throws TorqueException
267 {
268 if (collTurbineUserGroupRoles == null)
269 {
270 if (isNew())
271 {
272 collTurbineUserGroupRoles = new ArrayList<TurbineUserGroupRole>();
273 }
274 else
275 {
276 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
277 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelect(criteria, con);
278 }
279 }
280 else
281 {
282
283 if (!isNew())
284 {
285
286
287
288 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
289 if (!lastTurbineUserGroupRolesCriteria.equals(criteria))
290 {
291 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelect(criteria, con);
292 }
293 }
294 }
295 lastTurbineUserGroupRolesCriteria = criteria;
296
297 return collTurbineUserGroupRoles;
298 }
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321 protected List<TurbineUserGroupRole> getTurbineUserGroupRolesJoinTurbineUser(Criteria criteria)
322 throws TorqueException
323 {
324 if (collTurbineUserGroupRoles == null)
325 {
326 if (isNew())
327 {
328 collTurbineUserGroupRoles = new ArrayList<TurbineUserGroupRole>();
329 }
330 else
331 {
332 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
333 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineUser(criteria);
334 }
335 }
336 else
337 {
338
339
340
341 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
342 if (!lastTurbineUserGroupRolesCriteria.equals(criteria))
343 {
344 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineUser(criteria);
345 }
346 }
347 lastTurbineUserGroupRolesCriteria = criteria;
348
349 return collTurbineUserGroupRoles;
350 }
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371 protected List<TurbineUserGroupRole> getTurbineUserGroupRolesJoinTurbineGroup(Criteria criteria)
372 throws TorqueException
373 {
374 if (collTurbineUserGroupRoles == null)
375 {
376 if (isNew())
377 {
378 collTurbineUserGroupRoles = new ArrayList<TurbineUserGroupRole>();
379 }
380 else
381 {
382 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
383 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineGroup(criteria);
384 }
385 }
386 else
387 {
388
389
390
391 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
392 if (!lastTurbineUserGroupRolesCriteria.equals(criteria))
393 {
394 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineGroup(criteria);
395 }
396 }
397 lastTurbineUserGroupRolesCriteria = criteria;
398
399 return collTurbineUserGroupRoles;
400 }
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421 protected List<TurbineUserGroupRole> getTurbineUserGroupRolesJoinTurbineRole(Criteria criteria)
422 throws TorqueException
423 {
424 if (collTurbineUserGroupRoles == null)
425 {
426 if (isNew())
427 {
428 collTurbineUserGroupRoles = new ArrayList<TurbineUserGroupRole>();
429 }
430 else
431 {
432 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
433 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineRole(criteria);
434 }
435 }
436 else
437 {
438
439
440
441 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
442 if (!lastTurbineUserGroupRolesCriteria.equals(criteria))
443 {
444 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineRole(criteria);
445 }
446 }
447 lastTurbineUserGroupRolesCriteria = criteria;
448
449 return collTurbineUserGroupRoles;
450 }
451
452
453
454
455 private static List<String> fieldNames = null;
456
457
458
459
460
461
462 public static synchronized List<String> getFieldNames()
463 {
464 if (fieldNames == null)
465 {
466 fieldNames = new ArrayList<String>();
467 fieldNames.add("GroupId");
468 fieldNames.add("Name");
469 fieldNames = Collections.unmodifiableList(fieldNames);
470 }
471 return fieldNames;
472 }
473
474
475
476
477
478
479
480 public Object getByName(String name)
481 {
482 if (name.equals("GroupId"))
483 {
484 return new Integer(getGroupId());
485 }
486 if (name.equals("Name"))
487 {
488 return getName();
489 }
490 return null;
491 }
492
493
494
495
496
497
498
499
500
501
502 public boolean setByName(String name, Object value )
503 throws TorqueException, IllegalArgumentException
504 {
505 if (name.equals("GroupId"))
506 {
507 if (value == null || ! (Integer.class.isInstance(value)))
508 {
509 throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
510 }
511 setGroupId(((Integer) value).intValue());
512 return true;
513 }
514 if (name.equals("Name"))
515 {
516
517 if (value != null && ! String.class.isInstance(value))
518 {
519 throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
520 }
521 setName((String) value);
522 return true;
523 }
524 return false;
525 }
526
527
528
529
530
531
532
533
534
535 public Object getByPeerName(String name)
536 {
537 if (name.equals(TurbineGroupPeer.GROUP_ID))
538 {
539 return new Integer(getGroupId());
540 }
541 if (name.equals(TurbineGroupPeer.GROUP_NAME))
542 {
543 return getName();
544 }
545 return null;
546 }
547
548
549
550
551
552
553
554
555
556
557 public boolean setByPeerName(String name, Object value)
558 throws TorqueException, IllegalArgumentException
559 {
560 if (TurbineGroupPeer.GROUP_ID.equals(name))
561 {
562 return setByName("GroupId", value);
563 }
564 if (TurbineGroupPeer.GROUP_NAME.equals(name))
565 {
566 return setByName("Name", value);
567 }
568 return false;
569 }
570
571
572
573
574
575
576
577
578 public Object getByPosition(int pos)
579 {
580 if (pos == 0)
581 {
582 return new Integer(getGroupId());
583 }
584 if (pos == 1)
585 {
586 return getName();
587 }
588 return null;
589 }
590
591
592
593
594
595
596
597
598
599
600 public boolean setByPosition(int position, Object value)
601 throws TorqueException, IllegalArgumentException
602 {
603 if (position == 0)
604 {
605 return setByName("GroupId", value);
606 }
607 if (position == 1)
608 {
609 return setByName("Name", value);
610 }
611 return false;
612 }
613
614
615
616
617
618
619
620 public void save() throws Exception
621 {
622 save(TurbineGroupPeer.DATABASE_NAME);
623 }
624
625
626
627
628
629
630
631
632
633
634
635 public void save(String dbName) throws TorqueException
636 {
637 Connection con = null;
638 try
639 {
640 con = Transaction.begin(dbName);
641 save(con);
642 Transaction.commit(con);
643 }
644 catch(TorqueException e)
645 {
646 Transaction.safeRollback(con);
647 throw e;
648 }
649 }
650
651
652
653 private boolean alreadyInSave = false;
654
655
656
657
658
659
660
661
662
663
664 public void save(Connection con) throws TorqueException
665 {
666 if (!alreadyInSave)
667 {
668 alreadyInSave = true;
669
670
671
672
673 if (isModified())
674 {
675 if (isNew())
676 {
677 TurbineGroupPeer.doInsert((TurbineGroup) this, con);
678 setNew(false);
679 }
680 else
681 {
682 TurbineGroupPeer.doUpdate((TurbineGroup) this, con);
683 }
684 }
685
686
687 if (collTurbineUserGroupRoles != null)
688 {
689 for (int i = 0; i < collTurbineUserGroupRoles.size(); i++)
690 {
691 ((TurbineUserGroupRole) collTurbineUserGroupRoles.get(i)).save(con);
692 }
693 }
694 alreadyInSave = false;
695 }
696 }
697
698
699
700
701
702
703
704 public void setPrimaryKey(ObjectKey key)
705 throws TorqueException
706 {
707 setGroupId(((NumberKey) key).intValue());
708 }
709
710
711
712
713
714
715 public void setPrimaryKey(String key) throws TorqueException
716 {
717 setGroupId(Integer.parseInt(key));
718 }
719
720
721
722
723
724
725 public ObjectKey getPrimaryKey()
726 {
727 return SimpleKey.keyFor(getGroupId());
728 }
729
730
731
732
733
734
735
736
737 public TurbineGroup copy() throws TorqueException
738 {
739 return copy(true);
740 }
741
742
743
744
745
746
747
748
749
750 public TurbineGroup copy(Connection con) throws TorqueException
751 {
752 return copy(true, con);
753 }
754
755
756
757
758
759
760
761
762
763
764 public TurbineGroup copy(boolean deepcopy) throws TorqueException
765 {
766 return copyInto(new TurbineGroup(), deepcopy);
767 }
768
769
770
771
772
773
774
775
776
777
778
779 public TurbineGroup copy(boolean deepcopy, Connection con) throws TorqueException
780 {
781 return copyInto(new TurbineGroup(), deepcopy, con);
782 }
783
784
785
786
787
788
789
790 protected TurbineGroup copyInto(TurbineGroup copyObj) throws TorqueException
791 {
792 return copyInto(copyObj, true);
793 }
794
795
796
797
798
799
800
801
802
803 protected TurbineGroup copyInto(TurbineGroup copyObj, Connection con) throws TorqueException
804 {
805 return copyInto(copyObj, true, con);
806 }
807
808
809
810
811
812
813
814
815
816 protected TurbineGroup copyInto(TurbineGroup copyObj, boolean deepcopy) throws TorqueException
817 {
818 copyObj.setGroupId(groupId);
819 copyObj.setName(name);
820
821 copyObj.setGroupId( 0);
822
823 if (deepcopy)
824 {
825
826
827 List<TurbineUserGroupRole> vTurbineUserGroupRoles = getTurbineUserGroupRoles();
828 if (vTurbineUserGroupRoles != null)
829 {
830 for (int i = 0; i < vTurbineUserGroupRoles.size(); i++)
831 {
832 TurbineUserGroupRole obj = vTurbineUserGroupRoles.get(i);
833 copyObj.addTurbineUserGroupRole(obj.copy());
834 }
835 }
836 else
837 {
838 copyObj.collTurbineUserGroupRoles = null;
839 }
840 }
841 return copyObj;
842 }
843
844
845
846
847
848
849
850
851
852
853
854 protected TurbineGroup copyInto(TurbineGroup copyObj, boolean deepcopy, Connection con) throws TorqueException
855 {
856 copyObj.setGroupId(groupId);
857 copyObj.setName(name);
858
859 copyObj.setGroupId( 0);
860
861 if (deepcopy)
862 {
863
864
865 List<TurbineUserGroupRole> vTurbineUserGroupRoles = getTurbineUserGroupRoles(con);
866 if (vTurbineUserGroupRoles != null)
867 {
868 for (int i = 0; i < vTurbineUserGroupRoles.size(); i++)
869 {
870 TurbineUserGroupRole obj = vTurbineUserGroupRoles.get(i);
871 copyObj.addTurbineUserGroupRole(obj.copy(con), con);
872 }
873 }
874 else
875 {
876 copyObj.collTurbineUserGroupRoles = null;
877 }
878 }
879 return copyObj;
880 }
881
882
883
884
885
886
887
888
889
890 public TurbineGroupPeer getPeer()
891 {
892 return peer;
893 }
894
895
896
897
898
899
900
901 public TableMap getTableMap() throws TorqueException
902 {
903 return TurbineGroupPeer.getTableMap();
904 }
905
906
907 public String toString()
908 {
909 StringBuffer str = new StringBuffer();
910 str.append("TurbineGroup:\n");
911 str.append("GroupId = ")
912 .append(getGroupId())
913 .append("\n");
914 str.append("Name = ")
915 .append(getName())
916 .append("\n");
917 return(str.toString());
918 }
919 }