KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > BasePendingGroupUserRole


1 package org.tigris.scarab.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.fulcrum.intake.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  * You should not use this class directly. It should not even be
30  * extended all references should be to PendingGroupUserRole
31  */

32 public abstract class BasePendingGroupUserRole extends BaseObject
33     implements org.apache.fulcrum.intake.Retrievable
34 {
35     /** The Peer class */
36     private static final PendingGroupUserRolePeer peer =
37         new PendingGroupUserRolePeer();
38
39         
40     /** The value for the userId field */
41     private Integer JavaDoc userId;
42       
43     /** The value for the groupId field */
44     private Integer JavaDoc groupId;
45       
46     /** The value for the roleName field */
47     private String JavaDoc roleName;
48   
49     
50     /**
51      * Get the UserId
52      *
53      * @return Integer
54      */

55     public Integer JavaDoc getUserId()
56     {
57         return userId;
58     }
59
60                               
61     /**
62      * Set the value of UserId
63      *
64      * @param v new value
65      */

66     public void setUserId(Integer JavaDoc v) throws TorqueException
67     {
68     
69                   if (!ObjectUtils.equals(this.userId, v))
70               {
71             this.userId = v;
72             setModified(true);
73         }
74     
75                                           
76                 if (aScarabUser != null && !ObjectUtils.equals(aScarabUser.getUserId(), v))
77                 {
78             aScarabUser = null;
79         }
80       
81               }
82   
83     /**
84      * Get the GroupId
85      *
86      * @return Integer
87      */

88     public Integer JavaDoc getGroupId()
89     {
90         return groupId;
91     }
92
93                               
94     /**
95      * Set the value of GroupId
96      *
97      * @param v new value
98      */

99     public void setGroupId(Integer JavaDoc v) throws TorqueException
100     {
101     
102                   if (!ObjectUtils.equals(this.groupId, v))
103               {
104             this.groupId = v;
105             setModified(true);
106         }
107     
108                                           
109                 if (aModule != null && !ObjectUtils.equals(aModule.getModuleId(), v))
110                 {
111             aModule = null;
112         }
113       
114               }
115   
116     /**
117      * Get the RoleName
118      *
119      * @return String
120      */

121     public String JavaDoc getRoleName()
122     {
123         return roleName;
124     }
125
126                         
127     /**
128      * Set the value of RoleName
129      *
130      * @param v new value
131      */

132     public void setRoleName(String JavaDoc v)
133     {
134     
135                   if (!ObjectUtils.equals(this.roleName, v))
136               {
137             this.roleName = v;
138             setModified(true);
139         }
140     
141           
142               }
143   
144       
145             
146                   
147         private ScarabUser aScarabUser;
148
149     /**
150      * Declares an association between this object and a ScarabUser object
151      *
152      * @param v ScarabUser
153      * @throws TorqueException
154      */

155     public void setScarabUser(ScarabUser v) throws TorqueException
156     {
157             if (v == null)
158         {
159                   setUserId((Integer JavaDoc) null);
160               }
161         else
162         {
163             setUserId(v.getUserId());
164         }
165             aScarabUser = v;
166     }
167
168                         
169     /**
170      * Get the associated ScarabUser object
171      *
172      * @return the associated ScarabUser object
173      * @throws TorqueException
174      */

175     public ScarabUser getScarabUser() throws TorqueException
176     {
177         if ( !ObjectUtils.equals(getUserId(), null) )
178         {
179                 return ScarabUserManager.getInstance(SimpleKey.keyFor(getUserId()));
180             }
181         return aScarabUser;
182     }
183
184     /**
185      * Provides convenient way to set a relationship based on a
186      * ObjectKey, for example
187      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
188      *
189          */

190     public void setScarabUserKey(ObjectKey key) throws TorqueException
191     {
192     
193                     setUserId(new Integer JavaDoc(((NumberKey) key).intValue()));
194               }
195   
196             
197                   
198         private Module aModule;
199
200     /**
201      * Declares an association between this object and a Module object
202      *
203      * @param v Module
204      * @throws TorqueException
205      */

206     public void setModule(Module v) throws TorqueException
207     {
208             if (v == null)
209         {
210                   setGroupId((Integer JavaDoc) null);
211               }
212         else
213         {
214             setGroupId(v.getModuleId());
215         }
216             aModule = v;
217     }
218
219                         
220     /**
221      * Get the associated Module object
222      *
223      * @return the associated Module object
224      * @throws TorqueException
225      */

226     public Module getModule() throws TorqueException
227     {
228         if ( !ObjectUtils.equals(getGroupId(), null) )
229         {
230                 return ModuleManager.getInstance(SimpleKey.keyFor(getGroupId()));
231             }
232         return aModule;
233     }
234
235     /**
236      * Provides convenient way to set a relationship based on a
237      * ObjectKey, for example
238      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
239      *
240          */

241     public void setModuleKey(ObjectKey key) throws TorqueException
242     {
243     
244                     setGroupId(new Integer JavaDoc(((NumberKey) key).intValue()));
245               }
246      
247                 
248     private static List JavaDoc fieldNames = null;
249
250     /**
251      * Generate a list of field names.
252      *
253      * @return a list of field names
254      */

255     public static synchronized List JavaDoc getFieldNames()
256     {
257         if (fieldNames == null)
258         {
259             fieldNames = new ArrayList JavaDoc();
260               fieldNames.add("UserId");
261               fieldNames.add("GroupId");
262               fieldNames.add("RoleName");
263               fieldNames = Collections.unmodifiableList(fieldNames);
264         }
265         return fieldNames;
266     }
267
268     /**
269      * Retrieves a field from the object by name passed in as a String.
270      *
271      * @param name field name
272      * @return value
273      */

274     public Object JavaDoc getByName(String JavaDoc name)
275     {
276           if (name.equals("UserId"))
277         {
278                 return getUserId();
279             }
280           if (name.equals("GroupId"))
281         {
282                 return getGroupId();
283             }
284           if (name.equals("RoleName"))
285         {
286                 return getRoleName();
287             }
288           return null;
289     }
290     
291     /**
292      * Retrieves a field from the object by name passed in
293      * as a String. The String must be one of the static
294      * Strings defined in this Class' Peer.
295      *
296      * @param name peer name
297      * @return value
298      */

299     public Object JavaDoc getByPeerName(String JavaDoc name)
300     {
301           if (name.equals(PendingGroupUserRolePeer.USER_ID))
302         {
303                 return getUserId();
304             }
305           if (name.equals(PendingGroupUserRolePeer.GROUP_ID))
306         {
307                 return getGroupId();
308             }
309           if (name.equals(PendingGroupUserRolePeer.ROLE_NAME))
310         {
311                 return getRoleName();
312             }
313           return null;
314     }
315
316     /**
317      * Retrieves a field from the object by Position as specified
318      * in the xml schema. Zero-based.
319      *
320      * @param pos position in xml schema
321      * @return value
322      */

323     public Object JavaDoc getByPosition(int pos)
324     {
325             if (pos == 0)
326         {
327                 return getUserId();
328             }
329               if (pos == 1)
330         {
331                 return getGroupId();
332             }
333               if (pos == 2)
334         {
335                 return getRoleName();
336             }
337               return null;
338     }
339      
340     /**
341      * Stores the object in the database. If the object is new,
342      * it inserts it; otherwise an update is performed.
343      *
344      * @throws Exception
345      */

346     public void save() throws Exception JavaDoc
347     {
348           save(PendingGroupUserRolePeer.getMapBuilder()
349                 .getDatabaseMap().getName());
350       }
351
352     /**
353      * Stores the object in the database. If the object is new,
354      * it inserts it; otherwise an update is performed.
355        * Note: this code is here because the method body is
356      * auto-generated conditionally and therefore needs to be
357      * in this file instead of in the super class, BaseObject.
358        *
359      * @param dbName
360      * @throws TorqueException
361      */

362     public void save(String JavaDoc dbName) throws TorqueException
363     {
364         Connection JavaDoc con = null;
365           try
366         {
367             con = Transaction.begin(dbName);
368             save(con);
369             Transaction.commit(con);
370         }
371         catch(TorqueException e)
372         {
373             Transaction.safeRollback(con);
374             throw e;
375         }
376       }
377
378       /** flag to prevent endless save loop, if this object is referenced
379         by another object which falls in this transaction. */

380     private boolean alreadyInSave = false;
381       /**
382      * Stores the object in the database. If the object is new,
383      * it inserts it; otherwise an update is performed. This method
384      * is meant to be used as part of a transaction, otherwise use
385      * the save() method and the connection details will be handled
386      * internally
387      *
388      * @param con
389      * @throws TorqueException
390      */

391     public void save(Connection JavaDoc con) throws TorqueException
392     {
393           if (!alreadyInSave)
394         {
395             alreadyInSave = true;
396
397
398   
399             // If this object has been modified, then save it to the database.
400
if (isModified())
401             {
402                 if (isNew())
403                 {
404                     PendingGroupUserRolePeer.doInsert((PendingGroupUserRole)this, con);
405                     setNew(false);
406                 }
407                 else
408                 {
409                     PendingGroupUserRolePeer.doUpdate((PendingGroupUserRole)this, con);
410                 }
411
412                       if (isCacheOnSave())
413                 {
414                     PendingGroupUserRoleManager.putInstance(this);
415                 }
416               }
417
418                       alreadyInSave = false;
419         }
420       }
421
422     /**
423      * Specify whether to cache the object after saving to the db.
424      * This method returns false
425      */

426     protected boolean isCacheOnSave()
427     {
428         return true;
429     }
430
431                                                               
432   
433     private final SimpleKey[] pks = new SimpleKey[3];
434     private final ComboKey comboPK = new ComboKey(pks);
435
436     /**
437      * Set the PrimaryKey with an ObjectKey
438      *
439      * @param key
440      */

441     public void setPrimaryKey(ObjectKey key) throws TorqueException
442     {
443         SimpleKey[] keys = (SimpleKey[]) key.getValue();
444         SimpleKey tmpKey = null;
445                       setUserId(new Integer JavaDoc(((NumberKey)keys[0]).intValue()));
446                         setGroupId(new Integer JavaDoc(((NumberKey)keys[1]).intValue()));
447                         setRoleName(keys[2].toString());
448               }
449
450     /**
451      * Set the PrimaryKey using SimpleKeys.
452      *
453          * @param userId Integer
454          * @param groupId Integer
455          * @param roleName String
456          */

457     public void setPrimaryKey( Integer JavaDoc userId, Integer JavaDoc groupId, String JavaDoc roleName)
458         throws TorqueException
459     {
460             setUserId(userId);
461             setGroupId(groupId);
462             setRoleName(roleName);
463         }
464
465     /**
466      * Set the PrimaryKey using a String.
467      */

468     public void setPrimaryKey(String JavaDoc key) throws TorqueException
469     {
470         setPrimaryKey(new ComboKey(key));
471     }
472   
473     /**
474      * returns an id that differentiates this object from others
475      * of its class.
476      */

477     public ObjectKey getPrimaryKey()
478     {
479               pks[0] = SimpleKey.keyFor(getUserId());
480                   pks[1] = SimpleKey.keyFor(getGroupId());
481                   pks[2] = SimpleKey.keyFor(getRoleName());
482                   return comboPK;
483       }
484  
485     /**
486      * get an id that differentiates this object from others
487      * of its class.
488      */

489     public String JavaDoc getQueryKey()
490     {
491         if (getPrimaryKey() == null)
492         {
493             return "";
494         }
495         else
496         {
497             return getPrimaryKey().toString();
498         }
499     }
500
501     /**
502      * set an id that differentiates this object from others
503      * of its class.
504      */

505     public void setQueryKey(String JavaDoc key)
506         throws TorqueException
507     {
508         setPrimaryKey(key);
509     }
510
511     /**
512      * Makes a copy of this object.
513      * It creates a new object filling in the simple attributes.
514        * It then fills all the association collections and sets the
515      * related objects to isNew=true.
516        */

517       public PendingGroupUserRole copy() throws TorqueException
518     {
519         PendingGroupUserRole copyObj = new PendingGroupUserRole();
520             copyObj.setUserId(userId);
521           copyObj.setGroupId(groupId);
522           copyObj.setRoleName(roleName);
523   
524                       copyObj.setUserId((Integer JavaDoc)null);
525                                 copyObj.setGroupId((Integer JavaDoc)null);
526                                 copyObj.setRoleName((String JavaDoc)null);
527             
528                 return copyObj;
529     }
530
531     /**
532      * returns a peer instance associated with this om. Since Peer classes
533      * are not to have any instance attributes, this method returns the
534      * same instance for all member of this class. The method could therefore
535      * be static, but this would prevent one from overriding the behavior.
536      */

537     public PendingGroupUserRolePeer getPeer()
538     {
539         return peer;
540     }
541
542     public String JavaDoc toString()
543     {
544         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
545         str.append("PendingGroupUserRole:\n");
546         str.append("UserId = ")
547                .append(getUserId())
548              .append("\n");
549         str.append("GroupId = ")
550                .append(getGroupId())
551              .append("\n");
552         str.append("RoleName = ")
553                .append(getRoleName())
554              .append("\n");
555         return(str.toString());
556     }
557 }
558
Popular Tags