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 TurbineRolePermission
35   */
36  public abstract class BaseTurbineRolePermission extends BaseObject
37  {
38      /*** The Peer class */
39      private static final TurbineRolePermissionPeer peer =
40          new TurbineRolePermissionPeer();
41  
42          
43      /*** The value for the roleId field */
44      private int roleId;
45        
46      /*** The value for the permissionId field */
47      private int permissionId;
48    
49              
50      /***
51       * Get the RoleId
52       *
53       * @return int
54       */
55      public int getRoleId()
56      {
57          return roleId;
58      }
59  
60                                
61      /***
62       * Set the value of RoleId
63       *
64       * @param v new value
65       */
66      public void setRoleId(int v) throws TorqueException
67      {
68      
69                    if (this.roleId != v)
70                {
71              this.roleId = v;
72              setModified(true);
73          }
74      
75                                    
76                  if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v))
77                  {
78              aTurbineRole = null;
79          }
80        
81                }
82            
83      /***
84       * Get the PermissionId
85       *
86       * @return int
87       */
88      public int getPermissionId()
89      {
90          return permissionId;
91      }
92  
93                                
94      /***
95       * Set the value of PermissionId
96       *
97       * @param v new value
98       */
99      public void setPermissionId(int v) throws TorqueException
100     {
101     
102                   if (this.permissionId != v)
103               {
104             this.permissionId = v;
105             setModified(true);
106         }
107     
108                                   
109                 if (aTurbinePermission != null && !(aTurbinePermission.getPermissionId() == v))
110                 {
111             aTurbinePermission = null;
112         }
113       
114               }
115   
116       
117         
118                   
119     
120         private TurbineRole aTurbineRole;
121 
122     /***
123      * Declares an association between this object and a TurbineRole object
124      *
125      * @param v TurbineRole
126      * @throws TorqueException
127      */
128     public void setTurbineRole(TurbineRole v) throws TorqueException
129     {
130             if (v == null)
131         {
132                           setRoleId( 0);
133               }
134         else
135         {
136             setRoleId(v.getRoleId());
137         }
138             aTurbineRole = v;
139     }
140 
141                         
142     /***
143      * Returns the associated TurbineRole object.
144            * If it was not retrieved before, the object is retrieved from
145      * the database
146            *
147      * @return the associated TurbineRole object
148            * @throws TorqueException
149            */
150     public TurbineRole getTurbineRole()
151               throws TorqueException
152           {
153               if (aTurbineRole == null && (this.roleId != 0))
154         {
155                               aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId));
156                   
157             /* The following can be used instead of the line above to
158                guarantee the related object contains a reference
159                to this object, but this level of coupling
160                may be undesirable in many circumstances.
161                As it can lead to a db query with many results that may
162                never be used.
163                TurbineRole obj = TurbineRolePeer.retrieveByPK(this.roleId);
164                obj.add${pCollName}(this);
165             */
166         }
167               return aTurbineRole;
168     }
169 
170     /***
171      * Return the associated TurbineRole object
172      * If it was not retrieved before, the object is retrieved from
173      * the database using the passed connection
174      *
175      * @param connection the connection used to retrieve the associated object
176      *        from the database, if it was not retrieved before
177      * @return the associated TurbineRole object
178      * @throws TorqueException
179      */
180     public TurbineRole getTurbineRole(Connection connection)
181         throws TorqueException
182     {
183         if (aTurbineRole == null && (this.roleId != 0))
184         {
185                           aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId), connection);
186               
187             /* The following can be used instead of the line above to
188                guarantee the related object contains a reference
189                to this object, but this level of coupling
190                may be undesirable in many circumstances.
191                As it can lead to a db query with many results that may
192                never be used.
193                TurbineRole obj = TurbineRolePeer.retrieveByPK(this.roleId, connection);
194                obj.add${pCollName}(this);
195             */
196         }
197         return aTurbineRole;
198     }
199 
200     /***
201      * Provides convenient way to set a relationship based on a
202      * ObjectKey, for example
203      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
204      *
205          */
206     public void setTurbineRoleKey(ObjectKey key) throws TorqueException
207     {
208       
209                         setRoleId(((NumberKey) key).intValue());
210                   }
211     
212         
213                   
214     
215         private TurbinePermission aTurbinePermission;
216 
217     /***
218      * Declares an association between this object and a TurbinePermission object
219      *
220      * @param v TurbinePermission
221      * @throws TorqueException
222      */
223     public void setTurbinePermission(TurbinePermission v) throws TorqueException
224     {
225             if (v == null)
226         {
227                           setPermissionId( 0);
228               }
229         else
230         {
231             setPermissionId(v.getPermissionId());
232         }
233             aTurbinePermission = v;
234     }
235 
236                         
237     /***
238      * Returns the associated TurbinePermission object.
239            * If it was not retrieved before, the object is retrieved from
240      * the database
241            *
242      * @return the associated TurbinePermission object
243            * @throws TorqueException
244            */
245     public TurbinePermission getTurbinePermission()
246               throws TorqueException
247           {
248               if (aTurbinePermission == null && (this.permissionId != 0))
249         {
250                               aTurbinePermission = TurbinePermissionPeer.retrieveByPK(SimpleKey.keyFor(this.permissionId));
251                   
252             /* The following can be used instead of the line above to
253                guarantee the related object contains a reference
254                to this object, but this level of coupling
255                may be undesirable in many circumstances.
256                As it can lead to a db query with many results that may
257                never be used.
258                TurbinePermission obj = TurbinePermissionPeer.retrieveByPK(this.permissionId);
259                obj.add${pCollName}(this);
260             */
261         }
262               return aTurbinePermission;
263     }
264 
265     /***
266      * Return the associated TurbinePermission object
267      * If it was not retrieved before, the object is retrieved from
268      * the database using the passed connection
269      *
270      * @param connection the connection used to retrieve the associated object
271      *        from the database, if it was not retrieved before
272      * @return the associated TurbinePermission object
273      * @throws TorqueException
274      */
275     public TurbinePermission getTurbinePermission(Connection connection)
276         throws TorqueException
277     {
278         if (aTurbinePermission == null && (this.permissionId != 0))
279         {
280                           aTurbinePermission = TurbinePermissionPeer.retrieveByPK(SimpleKey.keyFor(this.permissionId), connection);
281               
282             /* The following can be used instead of the line above to
283                guarantee the related object contains a reference
284                to this object, but this level of coupling
285                may be undesirable in many circumstances.
286                As it can lead to a db query with many results that may
287                never be used.
288                TurbinePermission obj = TurbinePermissionPeer.retrieveByPK(this.permissionId, connection);
289                obj.add${pCollName}(this);
290             */
291         }
292         return aTurbinePermission;
293     }
294 
295     /***
296      * Provides convenient way to set a relationship based on a
297      * ObjectKey, for example
298      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
299      *
300          */
301     public void setTurbinePermissionKey(ObjectKey key) throws TorqueException
302     {
303       
304                         setPermissionId(((NumberKey) key).intValue());
305                   }
306        
307                 
308     private static List fieldNames = null;
309 
310     /***
311      * Generate a list of field names.
312      *
313      * @return a list of field names
314      */
315     public static synchronized List getFieldNames()
316     {
317         if (fieldNames == null)
318         {
319             fieldNames = new ArrayList();
320               fieldNames.add("RoleId");
321               fieldNames.add("PermissionId");
322               fieldNames = Collections.unmodifiableList(fieldNames);
323         }
324         return fieldNames;
325     }
326 
327     /***
328      * Retrieves a field from the object by name passed in as a String.
329      *
330      * @param name field name
331      * @return value
332      */
333     public Object getByName(String name)
334     {
335           if (name.equals("RoleId"))
336         {
337                 return new Integer(getRoleId());
338             }
339           if (name.equals("PermissionId"))
340         {
341                 return new Integer(getPermissionId());
342             }
343           return null;
344     }
345 
346     /***
347      * Retrieves a field from the object by name passed in
348      * as a String.  The String must be one of the static
349      * Strings defined in this Class' Peer.
350      *
351      * @param name peer name
352      * @return value
353      */
354     public Object getByPeerName(String name)
355     {
356           if (name.equals(TurbineRolePermissionPeer.ROLE_ID))
357         {
358                 return new Integer(getRoleId());
359             }
360           if (name.equals(TurbineRolePermissionPeer.PERMISSION_ID))
361         {
362                 return new Integer(getPermissionId());
363             }
364           return null;
365     }
366 
367     /***
368      * Retrieves a field from the object by Position as specified
369      * in the xml schema.  Zero-based.
370      *
371      * @param pos position in xml schema
372      * @return value
373      */
374     public Object getByPosition(int pos)
375     {
376             if (pos == 0)
377         {
378                 return new Integer(getRoleId());
379             }
380               if (pos == 1)
381         {
382                 return new Integer(getPermissionId());
383             }
384               return null;
385     }
386      
387     /***
388      * Stores the object in the database.  If the object is new,
389      * it inserts it; otherwise an update is performed.
390      *
391      * @throws Exception
392      */
393     public void save() throws Exception
394     {
395           save(TurbineRolePermissionPeer.getMapBuilder()
396                 .getDatabaseMap().getName());
397       }
398 
399     /***
400      * Stores the object in the database.  If the object is new,
401      * it inserts it; otherwise an update is performed.
402        * Note: this code is here because the method body is
403      * auto-generated conditionally and therefore needs to be
404      * in this file instead of in the super class, BaseObject.
405        *
406      * @param dbName
407      * @throws TorqueException
408      */
409     public void save(String dbName) throws TorqueException
410     {
411         Connection con = null;
412           try
413         {
414             con = Transaction.begin(dbName);
415             save(con);
416             Transaction.commit(con);
417         }
418         catch(TorqueException e)
419         {
420             Transaction.safeRollback(con);
421             throw e;
422         }
423       }
424 
425       /*** flag to prevent endless save loop, if this object is referenced
426         by another object which falls in this transaction. */
427     private boolean alreadyInSave = false;
428       /***
429      * Stores the object in the database.  If the object is new,
430      * it inserts it; otherwise an update is performed.  This method
431      * is meant to be used as part of a transaction, otherwise use
432      * the save() method and the connection details will be handled
433      * internally
434      *
435      * @param con
436      * @throws TorqueException
437      */
438     public void save(Connection con) throws TorqueException
439     {
440           if (!alreadyInSave)
441         {
442             alreadyInSave = true;
443 
444 
445   
446             // If this object has been modified, then save it to the database.
447             if (isModified())
448             {
449                 if (isNew())
450                 {
451                     TurbineRolePermissionPeer.doInsert((TurbineRolePermission) this, con);
452                     setNew(false);
453                 }
454                 else
455                 {
456                     TurbineRolePermissionPeer.doUpdate((TurbineRolePermission) this, con);
457                 }
458                 }
459 
460                       alreadyInSave = false;
461         }
462       }
463 
464                                               
465   
466     private final SimpleKey[] pks = new SimpleKey[2];
467     private final ComboKey comboPK = new ComboKey(pks);
468 
469     /***
470      * Set the PrimaryKey with an ObjectKey
471      *
472      * @param key
473      */
474     public void setPrimaryKey(ObjectKey key) throws TorqueException
475     {
476         SimpleKey[] keys = (SimpleKey[]) key.getValue();
477         SimpleKey tmpKey = null;
478                       setRoleId(((NumberKey)keys[0]).intValue());
479                         setPermissionId(((NumberKey)keys[1]).intValue());
480               }
481 
482     /***
483      * Set the PrimaryKey using SimpleKeys.
484      *
485          * @param roleId int
486          * @param permissionId int
487          */
488     public void setPrimaryKey( int roleId, int permissionId)
489         throws TorqueException
490     {
491             setRoleId(roleId);
492             setPermissionId(permissionId);
493         }
494 
495     /***
496      * Set the PrimaryKey using a String.
497      */
498     public void setPrimaryKey(String key) throws TorqueException
499     {
500         setPrimaryKey(new ComboKey(key));
501     }
502   
503     /***
504      * returns an id that differentiates this object from others
505      * of its class.
506      */
507     public ObjectKey getPrimaryKey()
508     {
509               pks[0] = SimpleKey.keyFor(getRoleId());
510                   pks[1] = SimpleKey.keyFor(getPermissionId());
511                   return comboPK;
512       }
513  
514 
515     /***
516      * Makes a copy of this object.
517      * It creates a new object filling in the simple attributes.
518        * It then fills all the association collections and sets the
519      * related objects to isNew=true.
520        */
521       public TurbineRolePermission copy() throws TorqueException
522     {
523         return copyInto(new TurbineRolePermission());
524     }
525   
526     protected TurbineRolePermission copyInto(TurbineRolePermission copyObj) throws TorqueException
527     {
528           copyObj.setRoleId(roleId);
529           copyObj.setPermissionId(permissionId);
530   
531                             copyObj.setRoleId( 0);
532                                       copyObj.setPermissionId( 0);
533             
534                 return copyObj;
535     }
536 
537     /***
538      * returns a peer instance associated with this om.  Since Peer classes
539      * are not to have any instance attributes, this method returns the
540      * same instance for all member of this class. The method could therefore
541      * be static, but this would prevent one from overriding the behavior.
542      */
543     public TurbineRolePermissionPeer getPeer()
544     {
545         return peer;
546     }
547 
548 
549     public String toString()
550     {
551         StringBuffer str = new StringBuffer();
552         str.append("TurbineRolePermission:\n");
553         str.append("RoleId = ")
554                .append(getRoleId())
555              .append("\n");
556         str.append("PermissionId = ")
557                .append(getPermissionId())
558              .append("\n");
559         return(str.toString());
560     }
561 }