KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > campware > cream > om > BaseTurbineUserGroupRole


1 package org.campware.cream.om;
2
3
4 import java.math.BigDecimal JavaDoc;
5 import java.sql.Connection JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Collections JavaDoc;
8 import java.util.Date JavaDoc;
9 import java.util.List JavaDoc;
10
11 import org.apache.commons.lang.ObjectUtils;
12 import org.apache.turbine.om.Retrievable;
13 import org.apache.torque.TorqueException;
14 import org.apache.torque.om.BaseObject;
15 import org.apache.torque.om.ComboKey;
16 import org.apache.torque.om.DateKey;
17 import org.apache.torque.om.NumberKey;
18 import org.apache.torque.om.ObjectKey;
19 import org.apache.torque.om.SimpleKey;
20 import org.apache.torque.om.StringKey;
21 import org.apache.torque.om.Persistent;
22 import org.apache.torque.util.Criteria;
23 import org.apache.torque.util.Transaction;
24
25   
26     
27     
28   
29 /**
30  * This class was autogenerated by Torque on:
31  *
32  * [Wed May 04 09:10:56 CEST 2005]
33  *
34  * You should not use this class directly. It should not even be
35  * extended all references should be to TurbineUserGroupRole
36  */

37 public abstract class BaseTurbineUserGroupRole extends BaseObject
38     implements org.apache.turbine.om.Retrievable
39 {
40     /** The Peer class */
41     private static final TurbineUserGroupRolePeer peer =
42         new TurbineUserGroupRolePeer();
43
44         
45     /** The value for the userId field */
46     private int userId;
47       
48     /** The value for the groupId field */
49     private int groupId;
50       
51     /** The value for the roleId field */
52     private int roleId;
53   
54     
55     /**
56      * Get the UserId
57      *
58      * @return int
59      */

60     public int getUserId()
61     {
62         return userId;
63     }
64
65                               
66     /**
67      * Set the value of UserId
68      *
69      * @param v new value
70      */

71     public void setUserId(int v) throws TorqueException
72     {
73     
74                   if (this.userId != v)
75               {
76             this.userId = v;
77             setModified(true);
78         }
79     
80                           
81                 if (aTurbineUser != null && !(aTurbineUser.getUserId() == v))
82                 {
83             aTurbineUser = null;
84         }
85       
86               }
87   
88     /**
89      * Get the GroupId
90      *
91      * @return int
92      */

93     public int getGroupId()
94     {
95         return groupId;
96     }
97
98                               
99     /**
100      * Set the value of GroupId
101      *
102      * @param v new value
103      */

104     public void setGroupId(int v) throws TorqueException
105     {
106     
107                   if (this.groupId != v)
108               {
109             this.groupId = v;
110             setModified(true);
111         }
112     
113                           
114                 if (aTurbineGroup != null && !(aTurbineGroup.getGroupId() == v))
115                 {
116             aTurbineGroup = null;
117         }
118       
119               }
120   
121     /**
122      * Get the RoleId
123      *
124      * @return int
125      */

126     public int getRoleId()
127     {
128         return roleId;
129     }
130
131                               
132     /**
133      * Set the value of RoleId
134      *
135      * @param v new value
136      */

137     public void setRoleId(int v) throws TorqueException
138     {
139     
140                   if (this.roleId != v)
141               {
142             this.roleId = v;
143             setModified(true);
144         }
145     
146                           
147                 if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v))
148                 {
149             aTurbineRole = null;
150         }
151       
152               }
153   
154       
155     
156                   
157     
158         private TurbineUser aTurbineUser;
159
160     /**
161      * Declares an association between this object and a TurbineUser object
162      *
163      * @param v TurbineUser
164      * @throws TorqueException
165      */

166     public void setTurbineUser(TurbineUser v) throws TorqueException
167     {
168             if (v == null)
169         {
170                           setUserId( 0);
171               }
172         else
173         {
174             setUserId(v.getUserId());
175         }
176             aTurbineUser = v;
177     }
178
179                                             
180     /**
181      * Get the associated TurbineUser object
182      *
183      * @return the associated TurbineUser object
184      * @throws TorqueException
185      */

186     public TurbineUser getTurbineUser() throws TorqueException
187     {
188         if (aTurbineUser == null && (this.userId != 0))
189         {
190                           aTurbineUser = TurbineUserPeer.retrieveByPK(SimpleKey.keyFor(this.userId));
191               
192             /* The following can be used instead of the line above to
193                guarantee the related object contains a reference
194                to this object, but this level of coupling
195                may be undesirable in many circumstances.
196                As it can lead to a db query with many results that may
197                never be used.
198                TurbineUser obj = TurbineUserPeer.retrieveByPK(this.userId);
199                obj.addTurbineUserGroupRoles(this);
200             */

201         }
202         return aTurbineUser;
203     }
204
205     /**
206      * Provides convenient way to set a relationship based on a
207      * ObjectKey, for example
208      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
209      *
210          */

211     public void setTurbineUserKey(ObjectKey key) throws TorqueException
212     {
213       
214                         setUserId(((NumberKey) key).intValue());
215                   }
216     
217     
218                   
219     
220         private TurbineGroup aTurbineGroup;
221
222     /**
223      * Declares an association between this object and a TurbineGroup object
224      *
225      * @param v TurbineGroup
226      * @throws TorqueException
227      */

228     public void setTurbineGroup(TurbineGroup v) throws TorqueException
229     {
230             if (v == null)
231         {
232                           setGroupId( 0);
233               }
234         else
235         {
236             setGroupId(v.getGroupId());
237         }
238             aTurbineGroup = v;
239     }
240
241                                             
242     /**
243      * Get the associated TurbineGroup object
244      *
245      * @return the associated TurbineGroup object
246      * @throws TorqueException
247      */

248     public TurbineGroup getTurbineGroup() throws TorqueException
249     {
250         if (aTurbineGroup == null && (this.groupId != 0))
251         {
252                           aTurbineGroup = TurbineGroupPeer.retrieveByPK(SimpleKey.keyFor(this.groupId));
253               
254             /* The following can be used instead of the line above to
255                guarantee the related object contains a reference
256                to this object, but this level of coupling
257                may be undesirable in many circumstances.
258                As it can lead to a db query with many results that may
259                never be used.
260                TurbineGroup obj = TurbineGroupPeer.retrieveByPK(this.groupId);
261                obj.addTurbineUserGroupRoles(this);
262             */

263         }
264         return aTurbineGroup;
265     }
266
267     /**
268      * Provides convenient way to set a relationship based on a
269      * ObjectKey, for example
270      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
271      *
272          */

273     public void setTurbineGroupKey(ObjectKey key) throws TorqueException
274     {
275       
276                         setGroupId(((NumberKey) key).intValue());
277                   }
278     
279     
280                   
281     
282         private TurbineRole aTurbineRole;
283
284     /**
285      * Declares an association between this object and a TurbineRole object
286      *
287      * @param v TurbineRole
288      * @throws TorqueException
289      */

290     public void setTurbineRole(TurbineRole v) throws TorqueException
291     {
292             if (v == null)
293         {
294                           setRoleId( 0);
295               }
296         else
297         {
298             setRoleId(v.getRoleId());
299         }
300             aTurbineRole = v;
301     }
302
303                                             
304     /**
305      * Get the associated TurbineRole object
306      *
307      * @return the associated TurbineRole object
308      * @throws TorqueException
309      */

310     public TurbineRole getTurbineRole() throws TorqueException
311     {
312         if (aTurbineRole == null && (this.roleId != 0))
313         {
314                           aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId));
315               
316             /* The following can be used instead of the line above to
317                guarantee the related object contains a reference
318                to this object, but this level of coupling
319                may be undesirable in many circumstances.
320                As it can lead to a db query with many results that may
321                never be used.
322                TurbineRole obj = TurbineRolePeer.retrieveByPK(this.roleId);
323                obj.addTurbineUserGroupRoles(this);
324             */

325         }
326         return aTurbineRole;
327     }
328
329     /**
330      * Provides convenient way to set a relationship based on a
331      * ObjectKey, for example
332      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
333      *
334          */

335     public void setTurbineRoleKey(ObjectKey key) throws TorqueException
336     {
337       
338                         setRoleId(((NumberKey) key).intValue());
339                   }
340        
341                 
342     private static List JavaDoc fieldNames = null;
343
344     /**
345      * Generate a list of field names.
346      *
347      * @return a list of field names
348      */

349     public static synchronized List JavaDoc getFieldNames()
350     {
351         if (fieldNames == null)
352         {
353             fieldNames = new ArrayList JavaDoc();
354               fieldNames.add("UserId");
355               fieldNames.add("GroupId");
356               fieldNames.add("RoleId");
357               fieldNames = Collections.unmodifiableList(fieldNames);
358         }
359         return fieldNames;
360     }
361
362     /**
363      * Retrieves a field from the object by name passed in as a String.
364      *
365      * @param name field name
366      * @return value
367      */

368     public Object JavaDoc getByName(String JavaDoc name)
369     {
370           if (name.equals("UserId"))
371         {
372                 return new Integer JavaDoc(getUserId());
373             }
374           if (name.equals("GroupId"))
375         {
376                 return new Integer JavaDoc(getGroupId());
377             }
378           if (name.equals("RoleId"))
379         {
380                 return new Integer JavaDoc(getRoleId());
381             }
382           return null;
383     }
384     
385     /**
386      * Retrieves a field from the object by name passed in
387      * as a String. The String must be one of the static
388      * Strings defined in this Class' Peer.
389      *
390      * @param name peer name
391      * @return value
392      */

393     public Object JavaDoc getByPeerName(String JavaDoc name)
394     {
395           if (name.equals(TurbineUserGroupRolePeer.USER_ID))
396         {
397                 return new Integer JavaDoc(getUserId());
398             }
399           if (name.equals(TurbineUserGroupRolePeer.GROUP_ID))
400         {
401                 return new Integer JavaDoc(getGroupId());
402             }
403           if (name.equals(TurbineUserGroupRolePeer.ROLE_ID))
404         {
405                 return new Integer JavaDoc(getRoleId());
406             }
407           return null;
408     }
409
410     /**
411      * Retrieves a field from the object by Position as specified
412      * in the xml schema. Zero-based.
413      *
414      * @param pos position in xml schema
415      * @return value
416      */

417     public Object JavaDoc getByPosition(int pos)
418     {
419             if (pos == 0)
420         {
421                 return new Integer JavaDoc(getUserId());
422             }
423               if (pos == 1)
424         {
425                 return new Integer JavaDoc(getGroupId());
426             }
427               if (pos == 2)
428         {
429                 return new Integer JavaDoc(getRoleId());
430             }
431               return null;
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      *
438      * @throws Exception
439      */

440     public void save() throws Exception JavaDoc
441     {
442           save(TurbineUserGroupRolePeer.getMapBuilder()
443                 .getDatabaseMap().getName());
444       }
445
446     /**
447      * Stores the object in the database. If the object is new,
448      * it inserts it; otherwise an update is performed.
449        * Note: this code is here because the method body is
450      * auto-generated conditionally and therefore needs to be
451      * in this file instead of in the super class, BaseObject.
452        *
453      * @param dbName
454      * @throws TorqueException
455      */

456     public void save(String JavaDoc dbName) throws TorqueException
457     {
458         Connection JavaDoc con = null;
459           try
460         {
461             con = Transaction.begin(dbName);
462             save(con);
463             Transaction.commit(con);
464         }
465         catch(TorqueException e)
466         {
467             Transaction.safeRollback(con);
468             throw e;
469         }
470       }
471
472       /** flag to prevent endless save loop, if this object is referenced
473         by another object which falls in this transaction. */

474     private boolean alreadyInSave = false;
475       /**
476      * Stores the object in the database. If the object is new,
477      * it inserts it; otherwise an update is performed. This method
478      * is meant to be used as part of a transaction, otherwise use
479      * the save() method and the connection details will be handled
480      * internally
481      *
482      * @param con
483      * @throws TorqueException
484      */

485     public void save(Connection JavaDoc con) throws TorqueException
486     {
487           if (!alreadyInSave)
488         {
489             alreadyInSave = true;
490
491
492   
493             // If this object has been modified, then save it to the database.
494
if (isModified())
495             {
496                 if (isNew())
497                 {
498                     TurbineUserGroupRolePeer.doInsert((TurbineUserGroupRole) this, con);
499                     setNew(false);
500                 }
501                 else
502                 {
503                     TurbineUserGroupRolePeer.doUpdate((TurbineUserGroupRole) this, con);
504                 }
505             }
506
507                       alreadyInSave = false;
508         }
509       }
510
511                                                                     
512   
513     private final SimpleKey[] pks = new SimpleKey[3];
514     private final ComboKey comboPK = new ComboKey(pks);
515     
516     /**
517      * Set the PrimaryKey with an ObjectKey
518      *
519      * @param key
520      */

521     public void setPrimaryKey(ObjectKey key) throws TorqueException
522     {
523         SimpleKey[] keys = (SimpleKey[]) key.getValue();
524         SimpleKey tmpKey = null;
525                       setUserId(((NumberKey)keys[0]).intValue());
526                         setGroupId(((NumberKey)keys[1]).intValue());
527                         setRoleId(((NumberKey)keys[2]).intValue());
528               }
529
530     /**
531      * Set the PrimaryKey using SimpleKeys.
532      *
533          * @param userId int
534          * @param groupId int
535          * @param roleId int
536          */

537     public void setPrimaryKey( int userId, int groupId, int roleId)
538         throws TorqueException
539     {
540             setUserId(userId);
541             setGroupId(groupId);
542             setRoleId(roleId);
543         }
544
545     /**
546      * Set the PrimaryKey using a String.
547      */

548     public void setPrimaryKey(String JavaDoc key) throws TorqueException
549     {
550         setPrimaryKey(new ComboKey(key));
551     }
552   
553     /**
554      * returns an id that differentiates this object from others
555      * of its class.
556      */

557     public ObjectKey getPrimaryKey()
558     {
559               pks[0] = SimpleKey.keyFor(getUserId());
560                   pks[1] = SimpleKey.keyFor(getGroupId());
561                   pks[2] = SimpleKey.keyFor(getRoleId());
562                   return comboPK;
563       }
564  
565     /**
566      * get an id that differentiates this object from others
567      * of its class.
568      */

569     public String JavaDoc getQueryKey()
570     {
571         if (getPrimaryKey() == null)
572         {
573             return "";
574         }
575         else
576         {
577             return getPrimaryKey().toString();
578         }
579     }
580
581     /**
582      * set an id that differentiates this object from others
583      * of its class.
584      */

585     public void setQueryKey(String JavaDoc key)
586         throws TorqueException
587     {
588         setPrimaryKey(key);
589     }
590
591     /**
592      * Makes a copy of this object.
593      * It creates a new object filling in the simple attributes.
594        * It then fills all the association collections and sets the
595      * related objects to isNew=true.
596        */

597       public TurbineUserGroupRole copy() throws TorqueException
598     {
599         return copyInto(new TurbineUserGroupRole());
600     }
601   
602     protected TurbineUserGroupRole copyInto(TurbineUserGroupRole copyObj) throws TorqueException
603     {
604           copyObj.setUserId(userId);
605           copyObj.setGroupId(groupId);
606           copyObj.setRoleId(roleId);
607   
608                             copyObj.setUserId( 0);
609                                       copyObj.setGroupId( 0);
610                                       copyObj.setRoleId( 0);
611             
612                 return copyObj;
613     }
614
615     /**
616      * returns a peer instance associated with this om. Since Peer classes
617      * are not to have any instance attributes, this method returns the
618      * same instance for all member of this class. The method could therefore
619      * be static, but this would prevent one from overriding the behavior.
620      */

621     public TurbineUserGroupRolePeer getPeer()
622     {
623         return peer;
624     }
625
626     public String JavaDoc toString()
627     {
628         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
629         str.append("TurbineUserGroupRole:\n");
630         str.append("UserId = ")
631                .append(getUserId())
632              .append("\n");
633         str.append("GroupId = ")
634                .append(getGroupId())
635              .append("\n");
636         str.append("RoleId = ")
637                .append(getRoleId())
638              .append("\n");
639         return(str.toString());
640     }
641 }
642
Popular Tags