KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fulcrum > security > impl > db > entity > BaseTurbineUserGroupRole


1 package org.apache.fulcrum.security.impl.db.entity;
2
3
4 import java.math.BigDecimal JavaDoc;
5 import java.sql.Connection JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Date JavaDoc;
8 import java.util.Collections 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 /**
30  * You should not use this class directly. It should not even be
31  * extended all references should be to TurbineUserGroupRole
32  */

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

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

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

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

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

122     public Integer JavaDoc getRoleId()
123     {
124         return roleId;
125     }
126
127                               
128     /**
129      * Set the value of RoleId
130      *
131      * @param v new value
132      */

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

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

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

197         }
198         return aTurbineUser;
199     }
200
201     /**
202      * Provides convenient way to set a relationship based on a
203      * ObjectKey. e.g.
204      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
205      *
206            */

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

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

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

259         }
260         return aTurbineGroup;
261     }
262
263     /**
264      * Provides convenient way to set a relationship based on a
265      * ObjectKey. e.g.
266      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
267      *
268            */

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

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

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

321         }
322         return aTurbineRole;
323     }
324
325     /**
326      * Provides convenient way to set a relationship based on a
327      * ObjectKey. e.g.
328      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
329      *
330            */

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

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

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

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

413     public Object JavaDoc getByPosition(int pos)
414     {
415             if (pos == 0)
416         {
417                 return getUserId();
418             }
419               if (pos == 1)
420         {
421                 return getGroupId();
422             }
423               if (pos == 2)
424         {
425                 return getRoleId();
426             }
427               return null;
428     }
429      
430     /**
431      * Stores the object in the database. If the object is new,
432      * it inserts it; otherwise an update is performed.
433      *
434      * @throws Exception
435      */

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

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

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

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

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

534     public void setPrimaryKey( Integer JavaDoc userId, Integer JavaDoc groupId, Integer JavaDoc roleId)
535         throws TorqueException
536     {
537             setUserId(userId);
538             setGroupId(groupId);
539             setRoleId(roleId);
540         }
541
542     /**
543      * Set the PrimaryKey using a String.
544      */

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

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

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

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

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

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