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