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