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 BaseTurbineRolePermission extends BaseObject
38 {
39
40 private static final long serialVersionUID = 1308842746584L;
41
42
43 private static final TurbineRolePermissionPeer peer =
44 new TurbineRolePermissionPeer();
45
46
47
48 private int roleId;
49
50
51 private int permissionId;
52
53
54
55
56
57
58
59 public int getRoleId()
60 {
61 return roleId;
62 }
63
64
65
66
67
68
69
70 public void setRoleId(int v) throws TorqueException
71 {
72
73 if (this.roleId != v)
74 {
75 this.roleId = v;
76 setModified(true);
77 }
78
79
80 if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v))
81 {
82 aTurbineRole = null;
83 }
84
85 }
86
87
88
89
90
91
92 public int getPermissionId()
93 {
94 return permissionId;
95 }
96
97
98
99
100
101
102
103 public void setPermissionId(int v) throws TorqueException
104 {
105
106 if (this.permissionId != v)
107 {
108 this.permissionId = v;
109 setModified(true);
110 }
111
112
113 if (aTurbinePermission != null && !(aTurbinePermission.getPermissionId() == v))
114 {
115 aTurbinePermission = null;
116 }
117
118 }
119
120
121
122
123
124 private TurbineRole aTurbineRole;
125
126
127
128
129
130
131
132 public void setTurbineRole(TurbineRole v) throws TorqueException
133 {
134 if (v == null)
135 {
136 setRoleId( 0);
137 }
138 else
139 {
140 setRoleId(v.getRoleId());
141 }
142 aTurbineRole = v;
143 }
144
145
146
147
148
149
150
151
152
153
154 public TurbineRole getTurbineRole()
155 throws TorqueException
156 {
157 if (aTurbineRole == null && (this.roleId != 0))
158 {
159 aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId));
160 }
161 return aTurbineRole;
162 }
163
164
165
166
167
168
169
170
171
172
173
174 public TurbineRole getTurbineRole(Connection connection)
175 throws TorqueException
176 {
177 if (aTurbineRole == null && (this.roleId != 0))
178 {
179 aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId), connection);
180 }
181 return aTurbineRole;
182 }
183
184
185
186
187
188
189
190 public void setTurbineRoleKey(ObjectKey key) throws TorqueException
191 {
192
193 setRoleId(((NumberKey) key).intValue());
194 }
195
196
197
198
199 private TurbinePermission aTurbinePermission;
200
201
202
203
204
205
206
207 public void setTurbinePermission(TurbinePermission v) throws TorqueException
208 {
209 if (v == null)
210 {
211 setPermissionId( 0);
212 }
213 else
214 {
215 setPermissionId(v.getPermissionId());
216 }
217 aTurbinePermission = v;
218 }
219
220
221
222
223
224
225
226
227
228
229 public TurbinePermission getTurbinePermission()
230 throws TorqueException
231 {
232 if (aTurbinePermission == null && (this.permissionId != 0))
233 {
234 aTurbinePermission = TurbinePermissionPeer.retrieveByPK(SimpleKey.keyFor(this.permissionId));
235 }
236 return aTurbinePermission;
237 }
238
239
240
241
242
243
244
245
246
247
248
249 public TurbinePermission getTurbinePermission(Connection connection)
250 throws TorqueException
251 {
252 if (aTurbinePermission == null && (this.permissionId != 0))
253 {
254 aTurbinePermission = TurbinePermissionPeer.retrieveByPK(SimpleKey.keyFor(this.permissionId), connection);
255 }
256 return aTurbinePermission;
257 }
258
259
260
261
262
263
264
265 public void setTurbinePermissionKey(ObjectKey key) throws TorqueException
266 {
267
268 setPermissionId(((NumberKey) key).intValue());
269 }
270
271
272 private static List<String> fieldNames = null;
273
274
275
276
277
278
279 public static synchronized List<String> getFieldNames()
280 {
281 if (fieldNames == null)
282 {
283 fieldNames = new ArrayList<String>();
284 fieldNames.add("RoleId");
285 fieldNames.add("PermissionId");
286 fieldNames = Collections.unmodifiableList(fieldNames);
287 }
288 return fieldNames;
289 }
290
291
292
293
294
295
296
297 public Object getByName(String name)
298 {
299 if (name.equals("RoleId"))
300 {
301 return new Integer(getRoleId());
302 }
303 if (name.equals("PermissionId"))
304 {
305 return new Integer(getPermissionId());
306 }
307 return null;
308 }
309
310
311
312
313
314
315
316
317
318
319 public boolean setByName(String name, Object value )
320 throws TorqueException, IllegalArgumentException
321 {
322 if (name.equals("RoleId"))
323 {
324 if (value == null || ! (Integer.class.isInstance(value)))
325 {
326 throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
327 }
328 setRoleId(((Integer) value).intValue());
329 return true;
330 }
331 if (name.equals("PermissionId"))
332 {
333 if (value == null || ! (Integer.class.isInstance(value)))
334 {
335 throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
336 }
337 setPermissionId(((Integer) value).intValue());
338 return true;
339 }
340 return false;
341 }
342
343
344
345
346
347
348
349
350
351 public Object getByPeerName(String name)
352 {
353 if (name.equals(TurbineRolePermissionPeer.ROLE_ID))
354 {
355 return new Integer(getRoleId());
356 }
357 if (name.equals(TurbineRolePermissionPeer.PERMISSION_ID))
358 {
359 return new Integer(getPermissionId());
360 }
361 return null;
362 }
363
364
365
366
367
368
369
370
371
372
373 public boolean setByPeerName(String name, Object value)
374 throws TorqueException, IllegalArgumentException
375 {
376 if (TurbineRolePermissionPeer.ROLE_ID.equals(name))
377 {
378 return setByName("RoleId", value);
379 }
380 if (TurbineRolePermissionPeer.PERMISSION_ID.equals(name))
381 {
382 return setByName("PermissionId", value);
383 }
384 return false;
385 }
386
387
388
389
390
391
392
393
394 public Object getByPosition(int pos)
395 {
396 if (pos == 0)
397 {
398 return new Integer(getRoleId());
399 }
400 if (pos == 1)
401 {
402 return new Integer(getPermissionId());
403 }
404 return null;
405 }
406
407
408
409
410
411
412
413
414
415
416 public boolean setByPosition(int position, Object value)
417 throws TorqueException, IllegalArgumentException
418 {
419 if (position == 0)
420 {
421 return setByName("RoleId", value);
422 }
423 if (position == 1)
424 {
425 return setByName("PermissionId", value);
426 }
427 return false;
428 }
429
430
431
432
433
434
435
436 public void save() throws Exception
437 {
438 save(TurbineRolePermissionPeer.DATABASE_NAME);
439 }
440
441
442
443
444
445
446
447
448
449
450
451 public void save(String dbName) throws TorqueException
452 {
453 Connection con = null;
454 try
455 {
456 con = Transaction.begin(dbName);
457 save(con);
458 Transaction.commit(con);
459 }
460 catch(TorqueException e)
461 {
462 Transaction.safeRollback(con);
463 throw e;
464 }
465 }
466
467
468
469 private boolean alreadyInSave = false;
470
471
472
473
474
475
476
477
478
479
480 public void save(Connection con) throws TorqueException
481 {
482 if (!alreadyInSave)
483 {
484 alreadyInSave = true;
485
486
487
488
489 if (isModified())
490 {
491 if (isNew())
492 {
493 TurbineRolePermissionPeer.doInsert((TurbineRolePermission) this, con);
494 setNew(false);
495 }
496 else
497 {
498 TurbineRolePermissionPeer.doUpdate((TurbineRolePermission) this, con);
499 }
500 }
501
502 alreadyInSave = false;
503 }
504 }
505
506
507
508 private final SimpleKey[] pks = new SimpleKey[2];
509 private final ComboKey comboPK = new ComboKey(pks);
510
511
512
513
514
515
516 public void setPrimaryKey(ObjectKey key) throws TorqueException
517 {
518 SimpleKey[] keys = (SimpleKey[]) key.getValue();
519 setRoleId(((NumberKey)keys[0]).intValue());
520 setPermissionId(((NumberKey)keys[1]).intValue());
521 }
522
523
524
525
526
527
528
529 public void setPrimaryKey( int roleId, int permissionId)
530 throws TorqueException
531 {
532 setRoleId(roleId);
533 setPermissionId(permissionId);
534 }
535
536
537
538
539 public void setPrimaryKey(String key) throws TorqueException
540 {
541 setPrimaryKey(new ComboKey(key));
542 }
543
544
545
546
547
548 public ObjectKey getPrimaryKey()
549 {
550 pks[0] = SimpleKey.keyFor(getRoleId());
551 pks[1] = SimpleKey.keyFor(getPermissionId());
552 return comboPK;
553 }
554
555
556
557
558
559
560
561
562 public TurbineRolePermission copy() throws TorqueException
563 {
564 return copy(true);
565 }
566
567
568
569
570
571
572
573
574
575 public TurbineRolePermission copy(Connection con) throws TorqueException
576 {
577 return copy(true, con);
578 }
579
580
581
582
583
584
585
586
587
588
589 public TurbineRolePermission copy(boolean deepcopy) throws TorqueException
590 {
591 return copyInto(new TurbineRolePermission(), deepcopy);
592 }
593
594
595
596
597
598
599
600
601
602
603
604 public TurbineRolePermission copy(boolean deepcopy, Connection con) throws TorqueException
605 {
606 return copyInto(new TurbineRolePermission(), deepcopy, con);
607 }
608
609
610
611
612
613
614
615 protected TurbineRolePermission copyInto(TurbineRolePermission copyObj) throws TorqueException
616 {
617 return copyInto(copyObj, true);
618 }
619
620
621
622
623
624
625
626
627
628 protected TurbineRolePermission copyInto(TurbineRolePermission copyObj, Connection con) throws TorqueException
629 {
630 return copyInto(copyObj, true, con);
631 }
632
633
634
635
636
637
638
639
640
641 protected TurbineRolePermission copyInto(TurbineRolePermission copyObj, boolean deepcopy) throws TorqueException
642 {
643 copyObj.setRoleId(roleId);
644 copyObj.setPermissionId(permissionId);
645
646 copyObj.setRoleId( 0);
647 copyObj.setPermissionId( 0);
648
649 if (deepcopy)
650 {
651 }
652 return copyObj;
653 }
654
655
656
657
658
659
660
661
662
663
664
665 protected TurbineRolePermission copyInto(TurbineRolePermission copyObj, boolean deepcopy, Connection con) throws TorqueException
666 {
667 copyObj.setRoleId(roleId);
668 copyObj.setPermissionId(permissionId);
669
670 copyObj.setRoleId( 0);
671 copyObj.setPermissionId( 0);
672
673 if (deepcopy)
674 {
675 }
676 return copyObj;
677 }
678
679
680
681
682
683
684
685
686
687 public TurbineRolePermissionPeer getPeer()
688 {
689 return peer;
690 }
691
692
693
694
695
696
697
698 public TableMap getTableMap() throws TorqueException
699 {
700 return TurbineRolePermissionPeer.getTableMap();
701 }
702
703
704 public String toString()
705 {
706 StringBuffer str = new StringBuffer();
707 str.append("TurbineRolePermission:\n");
708 str.append("RoleId = ")
709 .append(getRoleId())
710 .append("\n");
711 str.append("PermissionId = ")
712 .append(getPermissionId())
713 .append("\n");
714 return(str.toString());
715 }
716 }