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