View Javadoc

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