View Javadoc

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