1 package org.apache.jetspeed.om.security.turbine;
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 * This class was autogenerated by Torque on:
27 *
28 * [Thu Apr 22 23:12:36 EDT 2004]
29 *
30 * You should not use this class directly. It should not even be
31 * extended all references should be to TurbinePermission
32 */
33 public abstract class BaseTurbinePermission extends BaseObject
34 {
35 /*** The Peer class */
36 private static final TurbinePermissionPeer peer =
37 new TurbinePermissionPeer();
38
39
40 /*** The value for the permissionId field */
41 private int permissionId;
42
43 /*** The value for the permissionName field */
44 private String permissionName;
45
46 /*** The value for the objectdata field */
47 private byte[] objectdata;
48
49
50 /***
51 * Get the PermissionId
52 * @return int
53 */
54 public int getPermissionId()
55 {
56 return permissionId;
57 }
58
59
60 /***
61 * Set the value of PermissionId
62 */
63 public void setPermissionId(int v ) throws TorqueException
64 {
65
66 if (this.permissionId != v)
67 {
68 this.permissionId = v;
69 setModified(true);
70 }
71
72
73
74
75 if (collTurbineRolePermissions != null )
76 {
77 for (int i = 0; i < collTurbineRolePermissions.size(); i++)
78 {
79 ((TurbineRolePermission)collTurbineRolePermissions.get(i))
80 .setPermissionId(v);
81 }
82 }
83 }
84
85
86 /***
87 * Get the PermissionName
88 * @return String
89 */
90 public String getPermissionName()
91 {
92 return permissionName;
93 }
94
95
96 /***
97 * Set the value of PermissionName
98 */
99 public void setPermissionName(String v )
100 {
101
102 if (!ObjectUtils.equals(this.permissionName, v))
103 {
104 this.permissionName = v;
105 setModified(true);
106 }
107
108
109 }
110
111
112 /***
113 * Get the Objectdata
114 * @return byte[]
115 */
116 public byte[] getObjectdata()
117 {
118 return objectdata;
119 }
120
121
122 /***
123 * Set the value of Objectdata
124 */
125 public void setObjectdata(byte[] v )
126 {
127
128 if (!ObjectUtils.equals(this.objectdata, v))
129 {
130 this.objectdata = v;
131 setModified(true);
132 }
133
134
135 }
136
137
138
139
140
141 /***
142 * Collection to store aggregation of collTurbineRolePermissions
143 */
144 protected List collTurbineRolePermissions;
145
146 /***
147 * Temporary storage of collTurbineRolePermissions to save a possible db hit in
148 * the event objects are add to the collection, but the
149 * complete collection is never requested.
150 */
151 protected void initTurbineRolePermissions()
152 {
153 if (collTurbineRolePermissions == null)
154 {
155 collTurbineRolePermissions = new ArrayList();
156 }
157 }
158
159
160 /***
161 * Method called to associate a TurbineRolePermission object to this object
162 * through the TurbineRolePermission foreign key attribute
163 *
164 * @param TurbineRolePermission l
165 */
166 public void addTurbineRolePermission(TurbineRolePermission l) throws TorqueException
167 {
168 getTurbineRolePermissions().add(l);
169 l.setTurbinePermission((TurbinePermission)this);
170 }
171
172 /***
173 * The criteria used to select the current contents of collTurbineRolePermissions
174 */
175 private Criteria lastTurbineRolePermissionsCriteria = null;
176
177 /***
178 * If this collection has already been initialized, returns
179 * the collection. Otherwise returns the results of
180 * getTurbineRolePermissions(new Criteria())
181 */
182 public List getTurbineRolePermissions() throws TorqueException
183 {
184 if (collTurbineRolePermissions == null)
185 {
186 collTurbineRolePermissions = getTurbineRolePermissions(new Criteria(10));
187 }
188 return collTurbineRolePermissions;
189 }
190
191 /***
192 * If this collection has already been initialized with
193 * an identical criteria, it returns the collection.
194 * Otherwise if this TurbinePermission has previously
195 * been saved, it will retrieve related TurbineRolePermissions from storage.
196 * If this TurbinePermission is new, it will return
197 * an empty collection or the current collection, the criteria
198 * is ignored on a new object.
199 */
200 public List getTurbineRolePermissions(Criteria criteria) throws TorqueException
201 {
202 if (collTurbineRolePermissions == null)
203 {
204 if (isNew())
205 {
206 collTurbineRolePermissions = new ArrayList();
207 }
208 else
209 {
210 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() );
211 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria);
212 }
213 }
214 else
215 {
216
217 if (!isNew())
218 {
219
220
221
222 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() );
223 if (!lastTurbineRolePermissionsCriteria.equals(criteria))
224 {
225 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria);
226 }
227 }
228 }
229 lastTurbineRolePermissionsCriteria = criteria;
230
231 return collTurbineRolePermissions;
232 }
233
234 /***
235 * If this collection has already been initialized, returns
236 * the collection. Otherwise returns the results of
237 * getTurbineRolePermissions(new Criteria(),Connection)
238 * This method takes in the Connection also as input so that
239 * referenced objects can also be obtained using a Connection
240 * that is taken as input
241 */
242 public List getTurbineRolePermissions(Connection con) throws TorqueException
243 {
244 if (collTurbineRolePermissions == null)
245 {
246 collTurbineRolePermissions = getTurbineRolePermissions(new Criteria(10),con);
247 }
248 return collTurbineRolePermissions;
249 }
250
251 /***
252 * If this collection has already been initialized with
253 * an identical criteria, it returns the collection.
254 * Otherwise if this TurbinePermission has previously
255 * been saved, it will retrieve related TurbineRolePermissions from storage.
256 * If this TurbinePermission is new, it will return
257 * an empty collection or the current collection, the criteria
258 * is ignored on a new object.
259 * This method takes in the Connection also as input so that
260 * referenced objects can also be obtained using a Connection
261 * that is taken as input
262 */
263 public List getTurbineRolePermissions(Criteria criteria,Connection con) throws TorqueException
264 {
265 if (collTurbineRolePermissions == null)
266 {
267 if (isNew())
268 {
269 collTurbineRolePermissions = new ArrayList();
270 }
271 else
272 {
273 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() );
274 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria,con);
275 }
276 }
277 else
278 {
279
280 if (!isNew())
281 {
282
283
284
285 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() );
286 if (!lastTurbineRolePermissionsCriteria.equals(criteria))
287 {
288 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria,con);
289 }
290 }
291 }
292 lastTurbineRolePermissionsCriteria = criteria;
293
294 return collTurbineRolePermissions;
295 }
296
297
298
299
300
301
302
303
304
305
306
307
308 /***
309 * If this collection has already been initialized with
310 * an identical criteria, it returns the collection.
311 * Otherwise if this TurbinePermission is new, it will return
312 * an empty collection; or if this TurbinePermission has previously
313 * been saved, it will retrieve related TurbineRolePermissions from storage.
314 *
315 * This method is protected by default in order to keep the public
316 * api reasonable. You can provide public methods for those you
317 * actually need in TurbinePermission.
318 */
319 protected List getTurbineRolePermissionsJoinTurbineRole(Criteria criteria)
320 throws TorqueException
321 {
322 if (collTurbineRolePermissions == null)
323 {
324 if (isNew())
325 {
326 collTurbineRolePermissions = new ArrayList();
327 }
328 else
329 {
330 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() );
331 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria);
332 }
333 }
334 else
335 {
336
337
338
339 boolean newCriteria = true;
340 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() );
341 if (!lastTurbineRolePermissionsCriteria.equals(criteria))
342 {
343 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria);
344 }
345 }
346 lastTurbineRolePermissionsCriteria = criteria;
347
348 return collTurbineRolePermissions;
349 }
350
351
352
353
354
355
356
357
358
359 /***
360 * If this collection has already been initialized with
361 * an identical criteria, it returns the collection.
362 * Otherwise if this TurbinePermission is new, it will return
363 * an empty collection; or if this TurbinePermission has previously
364 * been saved, it will retrieve related TurbineRolePermissions from storage.
365 *
366 * This method is protected by default in order to keep the public
367 * api reasonable. You can provide public methods for those you
368 * actually need in TurbinePermission.
369 */
370 protected List getTurbineRolePermissionsJoinTurbinePermission(Criteria criteria)
371 throws TorqueException
372 {
373 if (collTurbineRolePermissions == null)
374 {
375 if (isNew())
376 {
377 collTurbineRolePermissions = new ArrayList();
378 }
379 else
380 {
381 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() );
382 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria);
383 }
384 }
385 else
386 {
387
388
389
390 boolean newCriteria = true;
391 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() );
392 if (!lastTurbineRolePermissionsCriteria.equals(criteria))
393 {
394 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria);
395 }
396 }
397 lastTurbineRolePermissionsCriteria = criteria;
398
399 return collTurbineRolePermissions;
400 }
401
402
403
404
405 private static List fieldNames = null;
406
407 /***
408 * Generate a list of field names.
409 */
410 public static synchronized List getFieldNames()
411 {
412 if (fieldNames == null)
413 {
414 fieldNames = new ArrayList();
415 fieldNames.add("PermissionId");
416 fieldNames.add("PermissionName");
417 fieldNames.add("Objectdata");
418 fieldNames = Collections.unmodifiableList(fieldNames);
419 }
420 return fieldNames;
421 }
422
423 /***
424 * Retrieves a field from the object by name passed in
425 * as a String.
426 */
427 public Object getByName(String name)
428 {
429 if (name.equals("PermissionId"))
430 {
431 return new Integer(getPermissionId());
432 }
433 if (name.equals("PermissionName"))
434 {
435 return getPermissionName();
436 }
437 if (name.equals("Objectdata"))
438 {
439 return getObjectdata();
440 }
441 return null;
442 }
443
444 /***
445 * Retrieves a field from the object by name passed in
446 * as a String. The String must be one of the static
447 * Strings defined in this Class' Peer.
448 */
449 public Object getByPeerName(String name)
450 {
451 if (name.equals(TurbinePermissionPeer.PERMISSION_ID ))
452 {
453 return new Integer(getPermissionId());
454 }
455 if (name.equals(TurbinePermissionPeer.PERMISSION_NAME ))
456 {
457 return getPermissionName();
458 }
459 if (name.equals(TurbinePermissionPeer.OBJECTDATA ))
460 {
461 return getObjectdata();
462 }
463 return null;
464 }
465
466 /***
467 * Retrieves a field from the object by Position as specified
468 * in the xml schema. Zero-based.
469 */
470 public Object getByPosition(int pos)
471 {
472 if ( pos == 0 )
473 {
474 return new Integer(getPermissionId());
475 }
476 if ( pos == 1 )
477 {
478 return getPermissionName();
479 }
480 if ( pos == 2 )
481 {
482 return getObjectdata();
483 }
484 return null;
485 }
486
487 /***
488 * Stores the object in the database. If the object is new,
489 * it inserts it; otherwise an update is performed.
490 */
491 public void save() throws Exception
492 {
493 save(TurbinePermissionPeer.getMapBuilder()
494 .getDatabaseMap().getName());
495 }
496
497 /***
498 * Stores the object in the database. If the object is new,
499 * it inserts it; otherwise an update is performed.
500 * Note: this code is here because the method body is
501 * auto-generated conditionally and therefore needs to be
502 * in this file instead of in the super class, BaseObject.
503 */
504 public void save(String dbName) throws TorqueException
505 {
506 Connection con = null;
507 try
508 {
509 con = Transaction.begin(dbName);
510 save(con);
511 Transaction.commit(con);
512 }
513 catch(TorqueException e)
514 {
515 Transaction.safeRollback(con);
516 throw e;
517 }
518 }
519
520 /*** flag to prevent endless save loop, if this object is referenced
521 by another object which falls in this transaction. */
522 private boolean alreadyInSave = false;
523 /***
524 * Stores the object in the database. If the object is new,
525 * it inserts it; otherwise an update is performed. This method
526 * is meant to be used as part of a transaction, otherwise use
527 * the save() method and the connection details will be handled
528 * internally
529 */
530 public void save(Connection con) throws TorqueException
531 {
532 if (!alreadyInSave)
533 {
534 alreadyInSave = true;
535
536
537
538
539 if (isModified())
540 {
541 if (isNew())
542 {
543 TurbinePermissionPeer.doInsert((TurbinePermission)this, con);
544 setNew(false);
545 }
546 else
547 {
548 TurbinePermissionPeer.doUpdate((TurbinePermission)this, con);
549 }
550
551 if (isCacheOnSave())
552 {
553 TurbinePermissionManager.putInstance(this);
554 }
555 }
556
557
558 if (collTurbineRolePermissions != null )
559 {
560 for (int i = 0; i < collTurbineRolePermissions.size(); i++)
561 {
562 ((TurbineRolePermission)collTurbineRolePermissions.get(i)).save(con);
563 }
564 }
565 alreadyInSave = false;
566 }
567 }
568
569 /***
570 * Specify whether to cache the object after saving to the db.
571 * This method returns false
572 */
573 protected boolean isCacheOnSave()
574 {
575 return true;
576 }
577
578
579 /***
580 * Set the PrimaryKey using ObjectKey.
581 *
582 * @param ObjectKey permissionId
583 */
584 public void setPrimaryKey(ObjectKey permissionId)
585 throws TorqueException {
586 setPermissionId(((NumberKey)permissionId).intValue());
587 }
588
589 /***
590 * Set the PrimaryKey using a String.
591 */
592 public void setPrimaryKey(String key) throws TorqueException
593 {
594 setPermissionId(Integer.parseInt(key));
595 }
596
597
598 /***
599 * returns an id that differentiates this object from others
600 * of its class.
601 */
602 public ObjectKey getPrimaryKey()
603 {
604 return SimpleKey.keyFor(getPermissionId());
605 }
606
607
608 /***
609 * Makes a copy of this object.
610 * It creates a new object filling in the simple attributes.
611 * It then fills all the association collections.
612 */
613 public TurbinePermission copy() throws TorqueException
614 {
615 TurbinePermission copyObj = new TurbinePermission();
616 copyObj.setPermissionId(permissionId);
617 copyObj.setPermissionName(permissionName);
618 copyObj.setObjectdata(objectdata);
619
620 copyObj.setPermissionId(0);
621
622
623
624 List v = getTurbineRolePermissions();
625 for (int i = 0; i < v.size(); i++)
626 {
627 TurbineRolePermission obj = (TurbineRolePermission) v.get(i);
628 copyObj.addTurbineRolePermission(obj.copy());
629 }
630 return copyObj;
631 }
632
633 /***
634 * returns a peer instance associated with this om. Since Peer classes
635 * are not to have any instance attributes, this method returns the
636 * same instance for all member of this class. The method could therefore
637 * be static, but this would prevent one from overriding the behavior.
638 */
639 public TurbinePermissionPeer getPeer()
640 {
641 return peer;
642 }
643 }