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 TurbinePermission
22   */
23  public abstract class BaseTurbinePermission extends BaseObject
24      implements org.apache.turbine.om.Retrievable
25  {
26      /*** The Peer class */
27      private static final TurbinePermissionPeer peer =
28          new TurbinePermissionPeer();
29  
30          
31      /*** The value for the permissionId field */
32      private int permissionId;
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 PermissionId
43       *
44       * @return int
45       */
46      public int getPermissionId()
47      {
48          return permissionId;
49      }
50  
51                                                
52      /***
53       * Set the value of PermissionId
54       *
55       * @param v new value
56       */
57      public void setPermissionId(int v) throws TorqueException
58      {
59      
60                    if (this.permissionId != v)
61                {
62              this.permissionId = v;
63              setModified(true);
64          }
65      
66            
67                                    
68                    // update associated TurbineRolePermission
69          if (collTurbineRolePermissions != null)
70          {
71              for (int i = 0; i < collTurbineRolePermissions.size(); i++)
72              {
73                  ((TurbineRolePermission) collTurbineRolePermissions.get(i))
74                      .setPermissionId(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 collTurbineRolePermissions
140      */
141     protected List collTurbineRolePermissions;
142 
143     /***
144      * Temporary storage of collTurbineRolePermissions 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 initTurbineRolePermissions()
149     {
150         if (collTurbineRolePermissions == null)
151         {
152             collTurbineRolePermissions = new ArrayList();
153         }
154     }
155 
156     /***
157      * Method called to associate a TurbineRolePermission object to this object
158      * through the TurbineRolePermission foreign key attribute
159      *
160      * @param l TurbineRolePermission
161      * @throws TorqueException
162      */
163     public void addTurbineRolePermission(TurbineRolePermission l) throws TorqueException
164     {
165         getTurbineRolePermissions().add(l);
166         l.setTurbinePermission((TurbinePermission) this);
167     }
168 
169     /***
170      * The criteria used to select the current contents of collTurbineRolePermissions
171      */
172     private Criteria lastTurbineRolePermissionsCriteria = null;
173       
174     /***
175      * If this collection has already been initialized, returns
176      * the collection. Otherwise returns the results of
177      * getTurbineRolePermissions(new Criteria())
178      *
179      * @throws TorqueException
180      */
181     public List getTurbineRolePermissions() throws TorqueException
182     {
183               if (collTurbineRolePermissions == null)
184         {
185             collTurbineRolePermissions = getTurbineRolePermissions(new Criteria(10));
186         }
187         return collTurbineRolePermissions;
188           }
189 
190     /***
191      * If this collection has already been initialized with
192      * an identical criteria, it returns the collection.
193      * Otherwise if this TurbinePermission has previously
194      * been saved, it will retrieve related TurbineRolePermissions from storage.
195      * If this TurbinePermission 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 getTurbineRolePermissions(Criteria criteria) throws TorqueException
202     {
203               if (collTurbineRolePermissions == null)
204         {
205             if (isNew())
206             {
207                collTurbineRolePermissions = new ArrayList();
208             }
209             else
210             {
211                         criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() );
212                         collTurbineRolePermissions = TurbineRolePermissionPeer.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(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
224                             if (!lastTurbineRolePermissionsCriteria.equals(criteria))
225                 {
226                     collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria);
227                 }
228             }
229         }
230         lastTurbineRolePermissionsCriteria = criteria;
231 
232         return collTurbineRolePermissions;
233           }
234 
235     /***
236      * If this collection has already been initialized, returns
237      * the collection. Otherwise returns the results of
238      * getTurbineRolePermissions(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 getTurbineRolePermissions(Connection con) throws TorqueException
244     {
245               if (collTurbineRolePermissions == null)
246         {
247             collTurbineRolePermissions = getTurbineRolePermissions(new Criteria(10), con);
248         }
249         return collTurbineRolePermissions;
250           }
251 
252     /***
253      * If this collection has already been initialized with
254      * an identical criteria, it returns the collection.
255      * Otherwise if this TurbinePermission has previously
256      * been saved, it will retrieve related TurbineRolePermissions from storage.
257      * If this TurbinePermission 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 getTurbineRolePermissions(Criteria criteria, Connection con)
265             throws TorqueException
266     {
267               if (collTurbineRolePermissions == null)
268         {
269             if (isNew())
270             {
271                collTurbineRolePermissions = new ArrayList();
272             }
273             else
274             {
275                          criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
276                          collTurbineRolePermissions = TurbineRolePermissionPeer.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(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
288                              if (!lastTurbineRolePermissionsCriteria.equals(criteria))
289                  {
290                      collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria, con);
291                  }
292              }
293          }
294          lastTurbineRolePermissionsCriteria = criteria;
295 
296          return collTurbineRolePermissions;
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 TurbinePermission is new, it will return
313      * an empty collection; or if this TurbinePermission has previously
314      * been saved, it will retrieve related TurbineRolePermissions 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 TurbinePermission.
319      */
320     protected List getTurbineRolePermissionsJoinTurbineRole(Criteria criteria)
321         throws TorqueException
322     {
323                     if (collTurbineRolePermissions == null)
324         {
325             if (isNew())
326             {
327                collTurbineRolePermissions = new ArrayList();
328             }
329             else
330             {
331                               criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
332                               collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbineRole(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(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
342                                     if (!lastTurbineRolePermissionsCriteria.equals(criteria))
343             {
344                 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria);
345             }
346         }
347         lastTurbineRolePermissionsCriteria = criteria;
348 
349         return collTurbineRolePermissions;
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 TurbinePermission is new, it will return
364      * an empty collection; or if this TurbinePermission has previously
365      * been saved, it will retrieve related TurbineRolePermissions 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 TurbinePermission.
370      */
371     protected List getTurbineRolePermissionsJoinTurbinePermission(Criteria criteria)
372         throws TorqueException
373     {
374                     if (collTurbineRolePermissions == null)
375         {
376             if (isNew())
377             {
378                collTurbineRolePermissions = new ArrayList();
379             }
380             else
381             {
382                               criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
383                               collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbinePermission(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(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
393                                     if (!lastTurbineRolePermissionsCriteria.equals(criteria))
394             {
395                 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria);
396             }
397         }
398         lastTurbineRolePermissionsCriteria = criteria;
399 
400         return collTurbineRolePermissions;
401                 }
402                             
403 
404 
405           
406     private static List fieldNames = null;
407 
408     /***
409      * Generate a list of field names.
410      *
411      * @return a list of field names
412      */
413     public static synchronized List getFieldNames()
414     {
415         if (fieldNames == null)
416         {
417             fieldNames = new ArrayList();
418               fieldNames.add("PermissionId");
419               fieldNames.add("Name");
420               fieldNames.add("Objectdata");
421               fieldNames = Collections.unmodifiableList(fieldNames);
422         }
423         return fieldNames;
424     }
425 
426     /***
427      * Retrieves a field from the object by name passed in as a String.
428      *
429      * @param name field name
430      * @return value
431      */
432     public Object getByName(String name)
433     {
434           if (name.equals("PermissionId"))
435         {
436                 return new Integer(getPermissionId());
437             }
438           if (name.equals("Name"))
439         {
440                 return getName();
441             }
442           if (name.equals("Objectdata"))
443         {
444                 return getObjectdata();
445             }
446           return null;
447     }
448     
449     /***
450      * Retrieves a field from the object by name passed in
451      * as a String.  The String must be one of the static
452      * Strings defined in this Class' Peer.
453      *
454      * @param name peer name
455      * @return value
456      */
457     public Object getByPeerName(String name)
458     {
459           if (name.equals(TurbinePermissionPeer.PERMISSION_ID))
460         {
461                 return new Integer(getPermissionId());
462             }
463           if (name.equals(TurbinePermissionPeer.PERMISSION_NAME))
464         {
465                 return getName();
466             }
467           if (name.equals(TurbinePermissionPeer.OBJECTDATA))
468         {
469                 return getObjectdata();
470             }
471           return null;
472     }
473 
474     /***
475      * Retrieves a field from the object by Position as specified
476      * in the xml schema.  Zero-based.
477      *
478      * @param pos position in xml schema
479      * @return value
480      */
481     public Object getByPosition(int pos)
482     {
483             if (pos == 0)
484         {
485                 return new Integer(getPermissionId());
486             }
487               if (pos == 1)
488         {
489                 return getName();
490             }
491               if (pos == 2)
492         {
493                 return getObjectdata();
494             }
495               return null;
496     }
497      
498     /***
499      * Stores the object in the database.  If the object is new,
500      * it inserts it; otherwise an update is performed.
501      *
502      * @throws Exception
503      */
504     public void save() throws Exception
505     {
506           save(TurbinePermissionPeer.getMapBuilder()
507                 .getDatabaseMap().getName());
508       }
509 
510     /***
511      * Stores the object in the database.  If the object is new,
512      * it inserts it; otherwise an update is performed.
513        * Note: this code is here because the method body is
514      * auto-generated conditionally and therefore needs to be
515      * in this file instead of in the super class, BaseObject.
516        *
517      * @param dbName
518      * @throws TorqueException
519      */
520     public void save(String dbName) throws TorqueException
521     {
522         Connection con = null;
523           try
524         {
525             con = Transaction.begin(dbName);
526             save(con);
527             Transaction.commit(con);
528         }
529         catch(TorqueException e)
530         {
531             Transaction.safeRollback(con);
532             throw e;
533         }
534       }
535 
536       /*** flag to prevent endless save loop, if this object is referenced
537         by another object which falls in this transaction. */
538     private boolean alreadyInSave = false;
539       /***
540      * Stores the object in the database.  If the object is new,
541      * it inserts it; otherwise an update is performed.  This method
542      * is meant to be used as part of a transaction, otherwise use
543      * the save() method and the connection details will be handled
544      * internally
545      *
546      * @param con
547      * @throws TorqueException
548      */
549     public void save(Connection con) throws TorqueException
550     {
551           if (!alreadyInSave)
552         {
553             alreadyInSave = true;
554 
555 
556   
557             // If this object has been modified, then save it to the database.
558             if (isModified())
559             {
560                 if (isNew())
561                 {
562                     TurbinePermissionPeer.doInsert((TurbinePermission) this, con);
563                     setNew(false);
564                 }
565                 else
566                 {
567                     TurbinePermissionPeer.doUpdate((TurbinePermission) this, con);
568                 }
569             }
570 
571                                       
572                 
573                     if (collTurbineRolePermissions != null)
574             {
575                 for (int i = 0; i < collTurbineRolePermissions.size(); i++)
576                 {
577                     ((TurbineRolePermission) collTurbineRolePermissions.get(i)).save(con);
578                 }
579             }
580                                   alreadyInSave = false;
581         }
582       }
583 
584                         
585       /***
586      * Set the PrimaryKey using ObjectKey.
587      *
588      * @param  permissionId ObjectKey
589      */
590     public void setPrimaryKey(ObjectKey key)
591         throws TorqueException
592     {
593             setPermissionId(((NumberKey) key).intValue());
594         }
595 
596     /***
597      * Set the PrimaryKey using a String.
598      *
599      * @param key
600      */
601     public void setPrimaryKey(String key) throws TorqueException
602     {
603             setPermissionId(Integer.parseInt(key));
604         }
605 
606   
607     /***
608      * returns an id that differentiates this object from others
609      * of its class.
610      */
611     public ObjectKey getPrimaryKey()
612     {
613           return SimpleKey.keyFor(getPermissionId());
614       }
615  
616     /***
617      * get an id that differentiates this object from others
618      * of its class.
619      */
620     public String getQueryKey()
621     {
622         if (getPrimaryKey() == null)
623         {
624             return "";
625         }
626         else
627         {
628             return getPrimaryKey().toString();
629         }
630     }
631 
632     /***
633      * set an id that differentiates this object from others
634      * of its class.
635      */
636     public void setQueryKey(String key)
637         throws TorqueException
638     {
639         setPrimaryKey(key);
640     }
641 
642     /***
643      * Makes a copy of this object.
644      * It creates a new object filling in the simple attributes.
645        * It then fills all the association collections and sets the
646      * related objects to isNew=true.
647        */
648       public TurbinePermission copy() throws TorqueException
649     {
650         return copyInto(new TurbinePermission());
651     }
652   
653     protected TurbinePermission copyInto(TurbinePermission copyObj) throws TorqueException
654     {
655           copyObj.setPermissionId(permissionId);
656           copyObj.setName(name);
657           copyObj.setObjectdata(objectdata);
658   
659                             copyObj.setPermissionId( 0);
660                         
661                                       
662                             
663         List v = getTurbineRolePermissions();
664         for (int i = 0; i < v.size(); i++)
665         {
666             TurbineRolePermission obj = (TurbineRolePermission) v.get(i);
667             copyObj.addTurbineRolePermission(obj.copy());
668         }
669                             return copyObj;
670     }
671 
672     /***
673      * returns a peer instance associated with this om.  Since Peer classes
674      * are not to have any instance attributes, this method returns the
675      * same instance for all member of this class. The method could therefore
676      * be static, but this would prevent one from overriding the behavior.
677      */
678     public TurbinePermissionPeer getPeer()
679     {
680         return peer;
681     }
682 
683     public String toString()
684     {
685         StringBuffer str = new StringBuffer();
686         str.append("TurbinePermission:\n");
687         str.append("PermissionId = ")
688            .append(getPermissionId())
689            .append("\n");
690         str.append("Name = ")
691            .append(getName())
692            .append("\n");
693         str.append("Objectdata = ")
694            .append(getObjectdata())
695            .append("\n");
696         return(str.toString());
697     }
698 }