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 TurbineGroup
35   */
36  public abstract class BaseTurbineGroup extends BaseObject
37  {
38      /*** The Peer class */
39      private static final TurbineGroupPeer peer =
40          new TurbineGroupPeer();
41  
42          
43      /*** The value for the groupId field */
44      private int groupId;
45        
46      /*** The value for the name field */
47      private String name;
48    
49              
50      /***
51       * Get the GroupId
52       *
53       * @return int
54       */
55      public int getGroupId()
56      {
57          return groupId;
58      }
59  
60                                                
61      /***
62       * Set the value of GroupId
63       *
64       * @param v new value
65       */
66      public void setGroupId(int v) throws TorqueException
67      {
68      
69                    if (this.groupId != v)
70                {
71              this.groupId = v;
72              setModified(true);
73          }
74      
75            
76                                    
77                    // update associated TurbineUserGroupRole
78          if (collTurbineUserGroupRoles != null)
79          {
80              for (int i = 0; i < collTurbineUserGroupRoles.size(); i++)
81              {
82                  ((TurbineUserGroupRole) collTurbineUserGroupRoles.get(i))
83                      .setGroupId(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 collTurbineUserGroupRoles
121      */
122     protected List collTurbineUserGroupRoles;
123 
124     /***
125      * Temporary storage of collTurbineUserGroupRoles 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 initTurbineUserGroupRoles()
130     {
131         if (collTurbineUserGroupRoles == null)
132         {
133             collTurbineUserGroupRoles = new ArrayList();
134         }
135     }
136 
137         
138     /***
139      * Method called to associate a TurbineUserGroupRole object to this object
140      * through the TurbineUserGroupRole foreign key attribute
141      *
142      * @param l TurbineUserGroupRole
143      * @throws TorqueException
144      */
145     public void addTurbineUserGroupRole(TurbineUserGroupRole l) throws TorqueException
146     {
147         getTurbineUserGroupRoles().add(l);
148         l.setTurbineGroup((TurbineGroup) this);
149     }
150 
151     /***
152      * The criteria used to select the current contents of collTurbineUserGroupRoles
153      */
154     private Criteria lastTurbineUserGroupRolesCriteria = null;
155       
156     /***
157                    * If this collection has already been initialized, returns
158      * the collection. Otherwise returns the results of
159      * getTurbineUserGroupRoles(new Criteria())
160                    *
161      * @return the collection of associated objects
162            * @throws TorqueException
163            */
164     public List getTurbineUserGroupRoles()
165               throws TorqueException
166           {
167                       if (collTurbineUserGroupRoles == null)
168         {
169             collTurbineUserGroupRoles = getTurbineUserGroupRoles(new Criteria(10));
170         }
171                 return collTurbineUserGroupRoles;
172           }
173 
174     /***
175            * If this collection has already been initialized with
176      * an identical criteria, it returns the collection.
177      * Otherwise if this TurbineGroup has previously
178            * been saved, it will retrieve related TurbineUserGroupRoles from storage.
179      * If this TurbineGroup 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 getTurbineUserGroupRoles(Criteria criteria) throws TorqueException
186     {
187               if (collTurbineUserGroupRoles == null)
188         {
189             if (isNew())
190             {
191                collTurbineUserGroupRoles = new ArrayList();
192             }
193             else
194             {
195                         criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId() );
196                         collTurbineUserGroupRoles = TurbineUserGroupRolePeer.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(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
208                             if (!lastTurbineUserGroupRolesCriteria.equals(criteria))
209                 {
210                     collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelect(criteria);
211                 }
212             }
213         }
214         lastTurbineUserGroupRolesCriteria = criteria;
215 
216         return collTurbineUserGroupRoles;
217           }
218 
219     /***
220            * If this collection has already been initialized, returns
221      * the collection. Otherwise returns the results of
222      * getTurbineUserGroupRoles(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 getTurbineUserGroupRoles(Connection con) throws TorqueException
228     {
229               if (collTurbineUserGroupRoles == null)
230         {
231             collTurbineUserGroupRoles = getTurbineUserGroupRoles(new Criteria(10), con);
232         }
233         return collTurbineUserGroupRoles;
234           }
235 
236     /***
237            * If this collection has already been initialized with
238      * an identical criteria, it returns the collection.
239      * Otherwise if this TurbineGroup has previously
240            * been saved, it will retrieve related TurbineUserGroupRoles from storage.
241      * If this TurbineGroup 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 getTurbineUserGroupRoles(Criteria criteria, Connection con)
249             throws TorqueException
250     {
251               if (collTurbineUserGroupRoles == null)
252         {
253             if (isNew())
254             {
255                collTurbineUserGroupRoles = new ArrayList();
256             }
257             else
258             {
259                          criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
260                          collTurbineUserGroupRoles = TurbineUserGroupRolePeer.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(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
272                              if (!lastTurbineUserGroupRolesCriteria.equals(criteria))
273                  {
274                      collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelect(criteria, con);
275                  }
276              }
277          }
278          lastTurbineUserGroupRolesCriteria = criteria;
279 
280          return collTurbineUserGroupRoles;
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 TurbineGroup is new, it will return
297                  * an empty collection; or if this TurbineGroup has previously
298      * been saved, it will retrieve related TurbineUserGroupRoles 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 TurbineGroup.
303      */
304     protected List getTurbineUserGroupRolesJoinTurbineUser(Criteria criteria)
305         throws TorqueException
306     {
307                     if (collTurbineUserGroupRoles == null)
308         {
309             if (isNew())
310             {
311                collTurbineUserGroupRoles = new ArrayList();
312             }
313             else
314             {
315                               criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
316                               collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineUser(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(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
325                                     if (!lastTurbineUserGroupRolesCriteria.equals(criteria))
326             {
327                 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineUser(criteria);
328             }
329         }
330         lastTurbineUserGroupRolesCriteria = criteria;
331 
332         return collTurbineUserGroupRoles;
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 TurbineGroup is new, it will return
347                  * an empty collection; or if this TurbineGroup has previously
348      * been saved, it will retrieve related TurbineUserGroupRoles 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 TurbineGroup.
353      */
354     protected List getTurbineUserGroupRolesJoinTurbineGroup(Criteria criteria)
355         throws TorqueException
356     {
357                     if (collTurbineUserGroupRoles == null)
358         {
359             if (isNew())
360             {
361                collTurbineUserGroupRoles = new ArrayList();
362             }
363             else
364             {
365                               criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
366                               collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineGroup(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(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
375                                     if (!lastTurbineUserGroupRolesCriteria.equals(criteria))
376             {
377                 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineGroup(criteria);
378             }
379         }
380         lastTurbineUserGroupRolesCriteria = criteria;
381 
382         return collTurbineUserGroupRoles;
383                 }
384                   
385                     
386                     
387                                 
388                                                               
389                                         
390                     
391                     
392           
393     /***
394                  * If this collection has already been initialized with
395      * an identical criteria, it returns the collection.
396      * Otherwise if this TurbineGroup is new, it will return
397                  * an empty collection; or if this TurbineGroup has previously
398      * been saved, it will retrieve related TurbineUserGroupRoles from storage.
399      *
400      * This method is protected by default in order to keep the public
401      * api reasonable.  You can provide public methods for those you
402      * actually need in TurbineGroup.
403      */
404     protected List getTurbineUserGroupRolesJoinTurbineRole(Criteria criteria)
405         throws TorqueException
406     {
407                     if (collTurbineUserGroupRoles == null)
408         {
409             if (isNew())
410             {
411                collTurbineUserGroupRoles = new ArrayList();
412             }
413             else
414             {
415                               criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
416                               collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineRole(criteria);
417             }
418         }
419         else
420         {
421             // the following code is to determine if a new query is
422             // called for.  If the criteria is the same as the last
423             // one, just return the collection.
424                                     criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId());
425                                     if (!lastTurbineUserGroupRolesCriteria.equals(criteria))
426             {
427                 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineRole(criteria);
428             }
429         }
430         lastTurbineUserGroupRolesCriteria = criteria;
431 
432         return collTurbineUserGroupRoles;
433                 }
434                             
435 
436 
437           
438     private static List fieldNames = null;
439 
440     /***
441      * Generate a list of field names.
442      *
443      * @return a list of field names
444      */
445     public static synchronized List getFieldNames()
446     {
447         if (fieldNames == null)
448         {
449             fieldNames = new ArrayList();
450               fieldNames.add("GroupId");
451               fieldNames.add("Name");
452               fieldNames = Collections.unmodifiableList(fieldNames);
453         }
454         return fieldNames;
455     }
456 
457     /***
458      * Retrieves a field from the object by name passed in as a String.
459      *
460      * @param name field name
461      * @return value
462      */
463     public Object getByName(String name)
464     {
465           if (name.equals("GroupId"))
466         {
467                 return new Integer(getGroupId());
468             }
469           if (name.equals("Name"))
470         {
471                 return getName();
472             }
473           return null;
474     }
475 
476     /***
477      * Retrieves a field from the object by name passed in
478      * as a String.  The String must be one of the static
479      * Strings defined in this Class' Peer.
480      *
481      * @param name peer name
482      * @return value
483      */
484     public Object getByPeerName(String name)
485     {
486           if (name.equals(TurbineGroupPeer.GROUP_ID))
487         {
488                 return new Integer(getGroupId());
489             }
490           if (name.equals(TurbineGroupPeer.GROUP_NAME))
491         {
492                 return getName();
493             }
494           return null;
495     }
496 
497     /***
498      * Retrieves a field from the object by Position as specified
499      * in the xml schema.  Zero-based.
500      *
501      * @param pos position in xml schema
502      * @return value
503      */
504     public Object getByPosition(int pos)
505     {
506             if (pos == 0)
507         {
508                 return new Integer(getGroupId());
509             }
510               if (pos == 1)
511         {
512                 return getName();
513             }
514               return null;
515     }
516      
517     /***
518      * Stores the object in the database.  If the object is new,
519      * it inserts it; otherwise an update is performed.
520      *
521      * @throws Exception
522      */
523     public void save() throws Exception
524     {
525           save(TurbineGroupPeer.getMapBuilder()
526                 .getDatabaseMap().getName());
527       }
528 
529     /***
530      * Stores the object in the database.  If the object is new,
531      * it inserts it; otherwise an update is performed.
532        * Note: this code is here because the method body is
533      * auto-generated conditionally and therefore needs to be
534      * in this file instead of in the super class, BaseObject.
535        *
536      * @param dbName
537      * @throws TorqueException
538      */
539     public void save(String dbName) throws TorqueException
540     {
541         Connection con = null;
542           try
543         {
544             con = Transaction.begin(dbName);
545             save(con);
546             Transaction.commit(con);
547         }
548         catch(TorqueException e)
549         {
550             Transaction.safeRollback(con);
551             throw e;
552         }
553       }
554 
555       /*** flag to prevent endless save loop, if this object is referenced
556         by another object which falls in this transaction. */
557     private boolean alreadyInSave = false;
558       /***
559      * Stores the object in the database.  If the object is new,
560      * it inserts it; otherwise an update is performed.  This method
561      * is meant to be used as part of a transaction, otherwise use
562      * the save() method and the connection details will be handled
563      * internally
564      *
565      * @param con
566      * @throws TorqueException
567      */
568     public void save(Connection con) throws TorqueException
569     {
570           if (!alreadyInSave)
571         {
572             alreadyInSave = true;
573 
574 
575   
576             // If this object has been modified, then save it to the database.
577             if (isModified())
578             {
579                 if (isNew())
580                 {
581                     TurbineGroupPeer.doInsert((TurbineGroup) this, con);
582                     setNew(false);
583                 }
584                 else
585                 {
586                     TurbineGroupPeer.doUpdate((TurbineGroup) this, con);
587                 }
588                 }
589 
590                                       
591                                     if (collTurbineUserGroupRoles != null)
592             {
593                 for (int i = 0; i < collTurbineUserGroupRoles.size(); i++)
594                 {
595                     ((TurbineUserGroupRole) collTurbineUserGroupRoles.get(i)).save(con);
596                 }
597             }
598                                   alreadyInSave = false;
599         }
600       }
601 
602                         
603       /***
604      * Set the PrimaryKey using ObjectKey.
605      *
606      * @param key groupId ObjectKey
607      */
608     public void setPrimaryKey(ObjectKey key)
609         throws TorqueException
610     {
611             setGroupId(((NumberKey) key).intValue());
612         }
613 
614     /***
615      * Set the PrimaryKey using a String.
616      *
617      * @param key
618      */
619     public void setPrimaryKey(String key) throws TorqueException
620     {
621             setGroupId(Integer.parseInt(key));
622         }
623 
624   
625     /***
626      * returns an id that differentiates this object from others
627      * of its class.
628      */
629     public ObjectKey getPrimaryKey()
630     {
631           return SimpleKey.keyFor(getGroupId());
632       }
633  
634 
635     /***
636      * Makes a copy of this object.
637      * It creates a new object filling in the simple attributes.
638        * It then fills all the association collections and sets the
639      * related objects to isNew=true.
640        */
641       public TurbineGroup copy() throws TorqueException
642     {
643         return copyInto(new TurbineGroup());
644     }
645   
646     protected TurbineGroup copyInto(TurbineGroup copyObj) throws TorqueException
647     {
648           copyObj.setGroupId(groupId);
649           copyObj.setName(name);
650   
651                             copyObj.setGroupId( 0);
652                   
653                                       
654                             
655         List v = getTurbineUserGroupRoles();
656                             if (v != null)
657         {
658             for (int i = 0; i < v.size(); i++)
659             {
660                 TurbineUserGroupRole obj = (TurbineUserGroupRole) v.get(i);
661                 copyObj.addTurbineUserGroupRole(obj.copy());
662             }
663         }
664         else
665         {
666             copyObj.collTurbineUserGroupRoles = null;
667         }
668                             return copyObj;
669     }
670 
671     /***
672      * returns a peer instance associated with this om.  Since Peer classes
673      * are not to have any instance attributes, this method returns the
674      * same instance for all member of this class. The method could therefore
675      * be static, but this would prevent one from overriding the behavior.
676      */
677     public TurbineGroupPeer getPeer()
678     {
679         return peer;
680     }
681 
682 
683     public String toString()
684     {
685         StringBuffer str = new StringBuffer();
686         str.append("TurbineGroup:\n");
687         str.append("GroupId = ")
688                .append(getGroupId())
689              .append("\n");
690         str.append("Name = ")
691                .append(getName())
692              .append("\n");
693         return(str.toString());
694     }
695 }