KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > campware > cream > om > BaseTurbinePermission


1 package org.campware.cream.om;
2
3
4 import java.math.BigDecimal JavaDoc;
5 import java.sql.Connection JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Collections JavaDoc;
8 import java.util.Date JavaDoc;
9 import java.util.List JavaDoc;
10
11 import org.apache.commons.lang.ObjectUtils;
12 import org.apache.turbine.om.Retrievable;
13 import org.apache.torque.TorqueException;
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  * This class was autogenerated by Torque on:
28  *
29  * [Wed May 04 09:10:56 CEST 2005]
30  *
31  * You should not use this class directly. It should not even be
32  * extended all references should be to TurbinePermission
33  */

34 public abstract class BaseTurbinePermission extends BaseObject
35     implements org.apache.turbine.om.Retrievable
36 {
37     /** The Peer class */
38     private static final TurbinePermissionPeer peer =
39         new TurbinePermissionPeer();
40
41         
42     /** The value for the permissionId field */
43     private int permissionId;
44       
45     /** The value for the name field */
46     private String JavaDoc name;
47   
48     
49     /**
50      * Get the PermissionId
51      *
52      * @return int
53      */

54     public int getPermissionId()
55     {
56         return permissionId;
57     }
58
59                                               
60     /**
61      * Set the value of PermissionId
62      *
63      * @param v new value
64      */

65     public void setPermissionId(int v) throws TorqueException
66     {
67     
68                   if (this.permissionId != v)
69               {
70             this.permissionId = v;
71             setModified(true);
72         }
73     
74           
75                                   
76                   // update associated TurbineRolePermission
77
if (collTurbineRolePermissions != null)
78         {
79             for (int i = 0; i < collTurbineRolePermissions.size(); i++)
80             {
81                 ((TurbineRolePermission) collTurbineRolePermissions.get(i))
82                     .setPermissionId(v);
83             }
84         }
85                                 }
86   
87     /**
88      * Get the Name
89      *
90      * @return String
91      */

92     public String JavaDoc getName()
93     {
94         return name;
95     }
96
97                         
98     /**
99      * Set the value of Name
100      *
101      * @param v new value
102      */

103     public void setName(String JavaDoc v)
104     {
105     
106                   if (!ObjectUtils.equals(this.name, v))
107               {
108             this.name = v;
109             setModified(true);
110         }
111     
112           
113               }
114   
115          
116                                 
117             
118           /**
119      * Collection to store aggregation of collTurbineRolePermissions
120      */

121     protected List JavaDoc collTurbineRolePermissions;
122
123     /**
124      * Temporary storage of collTurbineRolePermissions to save a possible db hit in
125      * the event objects are add to the collection, but the
126      * complete collection is never requested.
127      */

128     protected void initTurbineRolePermissions()
129     {
130         if (collTurbineRolePermissions == null)
131         {
132             collTurbineRolePermissions = new ArrayList JavaDoc();
133         }
134     }
135
136     /**
137      * Method called to associate a TurbineRolePermission object to this object
138      * through the TurbineRolePermission foreign key attribute
139      *
140      * @param l TurbineRolePermission
141      * @throws TorqueException
142      */

143     public void addTurbineRolePermission(TurbineRolePermission l) throws TorqueException
144     {
145         getTurbineRolePermissions().add(l);
146         l.setTurbinePermission((TurbinePermission) this);
147     }
148
149     /**
150      * The criteria used to select the current contents of collTurbineRolePermissions
151      */

152     private Criteria lastTurbineRolePermissionsCriteria = null;
153       
154     /**
155      * If this collection has already been initialized, returns
156      * the collection. Otherwise returns the results of
157      * getTurbineRolePermissions(new Criteria())
158      *
159      * @throws TorqueException
160      */

161     public List JavaDoc getTurbineRolePermissions() throws TorqueException
162     {
163               if (collTurbineRolePermissions == null)
164         {
165             collTurbineRolePermissions = getTurbineRolePermissions(new Criteria(10));
166         }
167         return collTurbineRolePermissions;
168           }
169
170     /**
171      * If this collection has already been initialized with
172      * an identical criteria, it returns the collection.
173      * Otherwise if this TurbinePermission has previously
174      * been saved, it will retrieve related TurbineRolePermissions from storage.
175      * If this TurbinePermission is new, it will return
176      * an empty collection or the current collection, the criteria
177      * is ignored on a new object.
178      *
179      * @throws TorqueException
180      */

181     public List JavaDoc getTurbineRolePermissions(Criteria criteria) throws TorqueException
182     {
183               if (collTurbineRolePermissions == null)
184         {
185             if (isNew())
186             {
187                collTurbineRolePermissions = new ArrayList JavaDoc();
188             }
189             else
190             {
191                         criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() );
192                         collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria);
193             }
194         }
195         else
196         {
197             // criteria has no effect for a new object
198
if (!isNew())
199             {
200                 // the following code is to determine if a new query is
201
// called for. If the criteria is the same as the last
202
// one, just return the collection.
203
criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
204                             if (!lastTurbineRolePermissionsCriteria.equals(criteria))
205                 {
206                     collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria);
207                 }
208             }
209         }
210         lastTurbineRolePermissionsCriteria = criteria;
211
212         return collTurbineRolePermissions;
213           }
214
215     /**
216      * If this collection has already been initialized, returns
217      * the collection. Otherwise returns the results of
218      * getTurbineRolePermissions(new Criteria(),Connection)
219      * This method takes in the Connection also as input so that
220      * referenced objects can also be obtained using a Connection
221      * that is taken as input
222      */

223     public List JavaDoc getTurbineRolePermissions(Connection JavaDoc con) throws TorqueException
224     {
225               if (collTurbineRolePermissions == null)
226         {
227             collTurbineRolePermissions = getTurbineRolePermissions(new Criteria(10), con);
228         }
229         return collTurbineRolePermissions;
230           }
231
232     /**
233      * If this collection has already been initialized with
234      * an identical criteria, it returns the collection.
235      * Otherwise if this TurbinePermission has previously
236      * been saved, it will retrieve related TurbineRolePermissions from storage.
237      * If this TurbinePermission is new, it will return
238      * an empty collection or the current collection, the criteria
239      * is ignored on a new object.
240      * This method takes in the Connection also as input so that
241      * referenced objects can also be obtained using a Connection
242      * that is taken as input
243      */

244     public List JavaDoc getTurbineRolePermissions(Criteria criteria, Connection JavaDoc con)
245             throws TorqueException
246     {
247               if (collTurbineRolePermissions == null)
248         {
249             if (isNew())
250             {
251                collTurbineRolePermissions = new ArrayList JavaDoc();
252             }
253             else
254             {
255                          criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
256                          collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria, con);
257              }
258          }
259          else
260          {
261              // criteria has no effect for a new object
262
if (!isNew())
263              {
264                  // the following code is to determine if a new query is
265
// called for. If the criteria is the same as the last
266
// one, just return the collection.
267
criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
268                              if (!lastTurbineRolePermissionsCriteria.equals(criteria))
269                  {
270                      collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria, con);
271                  }
272              }
273          }
274          lastTurbineRolePermissionsCriteria = criteria;
275
276          return collTurbineRolePermissions;
277            }
278
279                         
280               
281                     
282                     
283                                 
284                                                               
285                                         
286                     
287                     
288           
289     /**
290      * If this collection has already been initialized with
291      * an identical criteria, it returns the collection.
292      * Otherwise if this TurbinePermission is new, it will return
293      * an empty collection; or if this TurbinePermission has previously
294      * been saved, it will retrieve related TurbineRolePermissions from storage.
295      *
296      * This method is protected by default in order to keep the public
297      * api reasonable. You can provide public methods for those you
298      * actually need in TurbinePermission.
299      */

300     protected List JavaDoc getTurbineRolePermissionsJoinTurbineRole(Criteria criteria)
301         throws TorqueException
302     {
303                     if (collTurbineRolePermissions == null)
304         {
305             if (isNew())
306             {
307                collTurbineRolePermissions = new ArrayList JavaDoc();
308             }
309             else
310             {
311                               criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
312                               collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria);
313             }
314         }
315         else
316         {
317             // the following code is to determine if a new query is
318
// called for. If the criteria is the same as the last
319
// one, just return the collection.
320

321                         criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
322                                     if (!lastTurbineRolePermissionsCriteria.equals(criteria))
323             {
324                 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria);
325             }
326         }
327         lastTurbineRolePermissionsCriteria = criteria;
328
329         return collTurbineRolePermissions;
330                 }
331                   
332                     
333                               
334                                 
335                                                               
336                                         
337                     
338                     
339           
340     /**
341      * If this collection has already been initialized with
342      * an identical criteria, it returns the collection.
343      * Otherwise if this TurbinePermission is new, it will return
344      * an empty collection; or if this TurbinePermission has previously
345      * been saved, it will retrieve related TurbineRolePermissions from storage.
346      *
347      * This method is protected by default in order to keep the public
348      * api reasonable. You can provide public methods for those you
349      * actually need in TurbinePermission.
350      */

351     protected List JavaDoc getTurbineRolePermissionsJoinTurbinePermission(Criteria criteria)
352         throws TorqueException
353     {
354                     if (collTurbineRolePermissions == null)
355         {
356             if (isNew())
357             {
358                collTurbineRolePermissions = new ArrayList JavaDoc();
359             }
360             else
361             {
362                               criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
363                               collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria);
364             }
365         }
366         else
367         {
368             // the following code is to determine if a new query is
369
// called for. If the criteria is the same as the last
370
// one, just return the collection.
371

372                         criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
373                                     if (!lastTurbineRolePermissionsCriteria.equals(criteria))
374             {
375                 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria);
376             }
377         }
378         lastTurbineRolePermissionsCriteria = criteria;
379
380         return collTurbineRolePermissions;
381                 }
382                             
383
384
385           
386     private static List JavaDoc fieldNames = null;
387
388     /**
389      * Generate a list of field names.
390      *
391      * @return a list of field names
392      */

393     public static synchronized List JavaDoc getFieldNames()
394     {
395         if (fieldNames == null)
396         {
397             fieldNames = new ArrayList JavaDoc();
398               fieldNames.add("PermissionId");
399               fieldNames.add("Name");
400               fieldNames = Collections.unmodifiableList(fieldNames);
401         }
402         return fieldNames;
403     }
404
405     /**
406      * Retrieves a field from the object by name passed in as a String.
407      *
408      * @param name field name
409      * @return value
410      */

411     public Object JavaDoc getByName(String JavaDoc name)
412     {
413           if (name.equals("PermissionId"))
414         {
415                 return new Integer JavaDoc(getPermissionId());
416             }
417           if (name.equals("Name"))
418         {
419                 return getName();
420             }
421           return null;
422     }
423     
424     /**
425      * Retrieves a field from the object by name passed in
426      * as a String. The String must be one of the static
427      * Strings defined in this Class' Peer.
428      *
429      * @param name peer name
430      * @return value
431      */

432     public Object JavaDoc getByPeerName(String JavaDoc name)
433     {
434           if (name.equals(TurbinePermissionPeer.PERMISSION_ID))
435         {
436                 return new Integer JavaDoc(getPermissionId());
437             }
438           if (name.equals(TurbinePermissionPeer.PERMISSION_NAME))
439         {
440                 return getName();
441             }
442           return null;
443     }
444
445     /**
446      * Retrieves a field from the object by Position as specified
447      * in the xml schema. Zero-based.
448      *
449      * @param pos position in xml schema
450      * @return value
451      */

452     public Object JavaDoc getByPosition(int pos)
453     {
454             if (pos == 0)
455         {
456                 return new Integer JavaDoc(getPermissionId());
457             }
458               if (pos == 1)
459         {
460                 return getName();
461             }
462               return null;
463     }
464      
465     /**
466      * Stores the object in the database. If the object is new,
467      * it inserts it; otherwise an update is performed.
468      *
469      * @throws Exception
470      */

471     public void save() throws Exception JavaDoc
472     {
473           save(TurbinePermissionPeer.getMapBuilder()
474                 .getDatabaseMap().getName());
475       }
476
477     /**
478      * Stores the object in the database. If the object is new,
479      * it inserts it; otherwise an update is performed.
480        * Note: this code is here because the method body is
481      * auto-generated conditionally and therefore needs to be
482      * in this file instead of in the super class, BaseObject.
483        *
484      * @param dbName
485      * @throws TorqueException
486      */

487     public void save(String JavaDoc dbName) throws TorqueException
488     {
489         Connection JavaDoc con = null;
490           try
491         {
492             con = Transaction.begin(dbName);
493             save(con);
494             Transaction.commit(con);
495         }
496         catch(TorqueException e)
497         {
498             Transaction.safeRollback(con);
499             throw e;
500         }
501       }
502
503       /** flag to prevent endless save loop, if this object is referenced
504         by another object which falls in this transaction. */

505     private boolean alreadyInSave = false;
506       /**
507      * Stores the object in the database. If the object is new,
508      * it inserts it; otherwise an update is performed. This method
509      * is meant to be used as part of a transaction, otherwise use
510      * the save() method and the connection details will be handled
511      * internally
512      *
513      * @param con
514      * @throws TorqueException
515      */

516     public void save(Connection JavaDoc con) throws TorqueException
517     {
518           if (!alreadyInSave)
519         {
520             alreadyInSave = true;
521
522
523   
524             // If this object has been modified, then save it to the database.
525
if (isModified())
526             {
527                 if (isNew())
528                 {
529                     TurbinePermissionPeer.doInsert((TurbinePermission) this, con);
530                     setNew(false);
531                 }
532                 else
533                 {
534                     TurbinePermissionPeer.doUpdate((TurbinePermission) this, con);
535                 }
536             }
537
538                                       
539                 
540                     if (collTurbineRolePermissions != null)
541             {
542                 for (int i = 0; i < collTurbineRolePermissions.size(); i++)
543                 {
544                     ((TurbineRolePermission) collTurbineRolePermissions.get(i)).save(con);
545                 }
546             }
547                                   alreadyInSave = false;
548         }
549       }
550
551                         
552       /**
553      * Set the PrimaryKey using ObjectKey.
554      *
555      * @param key permissionId ObjectKey
556      */

557     public void setPrimaryKey(ObjectKey key)
558         throws TorqueException
559     {
560             setPermissionId(((NumberKey) key).intValue());
561         }
562
563     /**
564      * Set the PrimaryKey using a String.
565      *
566      * @param key
567      */

568     public void setPrimaryKey(String JavaDoc key) throws TorqueException
569     {
570             setPermissionId(Integer.parseInt(key));
571         }
572
573   
574     /**
575      * returns an id that differentiates this object from others
576      * of its class.
577      */

578     public ObjectKey getPrimaryKey()
579     {
580           return SimpleKey.keyFor(getPermissionId());
581       }
582  
583     /**
584      * get an id that differentiates this object from others
585      * of its class.
586      */

587     public String JavaDoc getQueryKey()
588     {
589         if (getPrimaryKey() == null)
590         {
591             return "";
592         }
593         else
594         {
595             return getPrimaryKey().toString();
596         }
597     }
598
599     /**
600      * set an id that differentiates this object from others
601      * of its class.
602      */

603     public void setQueryKey(String JavaDoc key)
604         throws TorqueException
605     {
606         setPrimaryKey(key);
607     }
608
609     /**
610      * Makes a copy of this object.
611      * It creates a new object filling in the simple attributes.
612        * It then fills all the association collections and sets the
613      * related objects to isNew=true.
614        */

615       public TurbinePermission copy() throws TorqueException
616     {
617         return copyInto(new TurbinePermission());
618     }
619   
620     protected TurbinePermission copyInto(TurbinePermission copyObj) throws TorqueException
621     {
622           copyObj.setPermissionId(permissionId);
623           copyObj.setName(name);
624   
625                             copyObj.setPermissionId( 0);
626                   
627                                       
628                             
629         List JavaDoc v = getTurbineRolePermissions();
630         for (int i = 0; i < v.size(); i++)
631         {
632             TurbineRolePermission obj = (TurbineRolePermission) v.get(i);
633             copyObj.addTurbineRolePermission(obj.copy());
634         }
635                             return copyObj;
636     }
637
638     /**
639      * returns a peer instance associated with this om. Since Peer classes
640      * are not to have any instance attributes, this method returns the
641      * same instance for all member of this class. The method could therefore
642      * be static, but this would prevent one from overriding the behavior.
643      */

644     public TurbinePermissionPeer getPeer()
645     {
646         return peer;
647     }
648
649     public String JavaDoc toString()
650     {
651         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
652         str.append("TurbinePermission:\n");
653         str.append("PermissionId = ")
654                .append(getPermissionId())
655              .append("\n");
656         str.append("Name = ")
657                .append(getName())
658              .append("\n");
659         return(str.toString());
660     }
661 }
662
Popular Tags