KickJava   Java API By Example, From Geeks To Geeks.

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


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  * You should not use this class directly. It should not even be
30  * extended all references should be to TurbineRolePermission
31  */

32 public abstract class BaseTurbineRolePermission extends BaseObject
33     implements org.apache.fulcrum.intake.Retrievable
34 {
35     /** The Peer class */
36     private static final TurbineRolePermissionPeer peer =
37         new TurbineRolePermissionPeer();
38
39         
40     /** The value for the roleId field */
41     private Integer JavaDoc roleId;
42       
43     /** The value for the permissionId field */
44     private Integer JavaDoc permissionId;
45   
46     
47     /**
48      * Get the RoleId
49      *
50      * @return Integer
51      */

52     public Integer JavaDoc getRoleId()
53     {
54         return roleId;
55     }
56
57                               
58     /**
59      * Set the value of RoleId
60      *
61      * @param v new value
62      */

63     public void setRoleId(Integer JavaDoc v) throws TorqueException
64     {
65     
66                   if (!ObjectUtils.equals(this.roleId, v))
67               {
68             this.roleId = v;
69             setModified(true);
70         }
71     
72                           
73                 if (aTurbineRole != null && !ObjectUtils.equals(aTurbineRole.getRoleId(), v))
74                 {
75             aTurbineRole = null;
76         }
77       
78               }
79   
80     /**
81      * Get the PermissionId
82      *
83      * @return Integer
84      */

85     public Integer JavaDoc getPermissionId()
86     {
87         return permissionId;
88     }
89
90                               
91     /**
92      * Set the value of PermissionId
93      *
94      * @param v new value
95      */

96     public void setPermissionId(Integer JavaDoc v) throws TorqueException
97     {
98     
99                   if (!ObjectUtils.equals(this.permissionId, v))
100               {
101             this.permissionId = v;
102             setModified(true);
103         }
104     
105                           
106                 if (aTurbinePermission != null && !ObjectUtils.equals(aTurbinePermission.getPermissionId(), v))
107                 {
108             aTurbinePermission = null;
109         }
110       
111               }
112   
113       
114     
115                   
116     
117         private TurbineRole aTurbineRole;
118
119     /**
120      * Declares an association between this object and a TurbineRole object
121      *
122      * @param v TurbineRole
123      * @throws TorqueException
124      */

125     public void setTurbineRole(TurbineRole v) throws TorqueException
126     {
127             if (v == null)
128         {
129                     setRoleId((Integer JavaDoc) null);
130                   }
131         else
132         {
133             setRoleId(v.getRoleId());
134         }
135                 aTurbineRole = v;
136     }
137
138                                             
139     /**
140      * Get the associated TurbineRole object
141      *
142      * @return the associated TurbineRole object
143      * @throws TorqueException
144      */

145     public TurbineRole getTurbineRole() throws TorqueException
146     {
147         if (aTurbineRole == null && (!ObjectUtils.equals(this.roleId, null)))
148         {
149                           aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId));
150               
151             /* The following can be used instead of the line above to
152                guarantee the related object contains a reference
153                to this object, but this level of coupling
154                may be undesirable in many circumstances.
155                As it can lead to a db query with many results that may
156                never be used.
157                TurbineRole obj = TurbineRolePeer.retrieveByPK(this.roleId);
158                obj.addTurbineRolePermissions(this);
159             */

160         }
161         return aTurbineRole;
162     }
163
164     /**
165      * Provides convenient way to set a relationship based on a
166      * ObjectKey. e.g.
167      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
168      *
169            */

170     public void setTurbineRoleKey(ObjectKey key) throws TorqueException
171     {
172       
173                         setRoleId(new Integer JavaDoc(((NumberKey) key).intValue()));
174                   }
175     
176     
177                   
178     
179         private TurbinePermission aTurbinePermission;
180
181     /**
182      * Declares an association between this object and a TurbinePermission object
183      *
184      * @param v TurbinePermission
185      * @throws TorqueException
186      */

187     public void setTurbinePermission(TurbinePermission v) throws TorqueException
188     {
189             if (v == null)
190         {
191                     setPermissionId((Integer JavaDoc) null);
192                   }
193         else
194         {
195             setPermissionId(v.getPermissionId());
196         }
197                 aTurbinePermission = v;
198     }
199
200                                             
201     /**
202      * Get the associated TurbinePermission object
203      *
204      * @return the associated TurbinePermission object
205      * @throws TorqueException
206      */

207     public TurbinePermission getTurbinePermission() throws TorqueException
208     {
209         if (aTurbinePermission == null && (!ObjectUtils.equals(this.permissionId, null)))
210         {
211                           aTurbinePermission = TurbinePermissionPeer.retrieveByPK(SimpleKey.keyFor(this.permissionId));
212               
213             /* The following can be used instead of the line above to
214                guarantee the related object contains a reference
215                to this object, but this level of coupling
216                may be undesirable in many circumstances.
217                As it can lead to a db query with many results that may
218                never be used.
219                TurbinePermission obj = TurbinePermissionPeer.retrieveByPK(this.permissionId);
220                obj.addTurbineRolePermissions(this);
221             */

222         }
223         return aTurbinePermission;
224     }
225
226     /**
227      * Provides convenient way to set a relationship based on a
228      * ObjectKey. e.g.
229      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
230      *
231            */

232     public void setTurbinePermissionKey(ObjectKey key) throws TorqueException
233     {
234       
235                         setPermissionId(new Integer JavaDoc(((NumberKey) key).intValue()));
236                   }
237        
238                 
239     private static List JavaDoc fieldNames = null;
240
241     /**
242      * Generate a list of field names.
243      *
244      * @return a list of field names
245      */

246     public static synchronized List JavaDoc getFieldNames()
247     {
248         if (fieldNames == null)
249         {
250             fieldNames = new ArrayList JavaDoc();
251               fieldNames.add("RoleId");
252               fieldNames.add("PermissionId");
253               fieldNames = Collections.unmodifiableList(fieldNames);
254         }
255         return fieldNames;
256     }
257
258     /**
259      * Retrieves a field from the object by name passed in as a String.
260      *
261      * @param name field name
262      * @return value
263      */

264     public Object JavaDoc getByName(String JavaDoc name)
265     {
266           if (name.equals("RoleId"))
267         {
268                 return getRoleId();
269             }
270           if (name.equals("PermissionId"))
271         {
272                 return getPermissionId();
273             }
274           return null;
275     }
276     
277     /**
278      * Retrieves a field from the object by name passed in
279      * as a String. The String must be one of the static
280      * Strings defined in this Class' Peer.
281      *
282      * @param name peer name
283      * @return value
284      */

285     public Object JavaDoc getByPeerName(String JavaDoc name)
286     {
287           if (name.equals(TurbineRolePermissionPeer.ROLE_ID))
288         {
289                 return getRoleId();
290             }
291           if (name.equals(TurbineRolePermissionPeer.PERMISSION_ID))
292         {
293                 return getPermissionId();
294             }
295           return null;
296     }
297
298     /**
299      * Retrieves a field from the object by Position as specified
300      * in the xml schema. Zero-based.
301      *
302      * @param pos position in xml schema
303      * @return value
304      */

305     public Object JavaDoc getByPosition(int pos)
306     {
307             if (pos == 0)
308         {
309                 return getRoleId();
310             }
311               if (pos == 1)
312         {
313                 return getPermissionId();
314             }
315               return null;
316     }
317      
318     /**
319      * Stores the object in the database. If the object is new,
320      * it inserts it; otherwise an update is performed.
321      *
322      * @throws Exception
323      */

324     public void save() throws Exception JavaDoc
325     {
326           save(TurbineRolePermissionPeer.getMapBuilder()
327                 .getDatabaseMap().getName());
328       }
329
330     /**
331      * Stores the object in the database. If the object is new,
332      * it inserts it; otherwise an update is performed.
333        * Note: this code is here because the method body is
334      * auto-generated conditionally and therefore needs to be
335      * in this file instead of in the super class, BaseObject.
336        *
337      * @param dbName
338      * @throws TorqueException
339      */

340     public void save(String JavaDoc dbName) throws TorqueException
341     {
342         Connection JavaDoc con = null;
343           try
344         {
345             con = Transaction.begin(dbName);
346             save(con);
347             Transaction.commit(con);
348         }
349         catch(TorqueException e)
350         {
351             Transaction.safeRollback(con);
352             throw e;
353         }
354       }
355
356       /** flag to prevent endless save loop, if this object is referenced
357         by another object which falls in this transaction. */

358     private boolean alreadyInSave = false;
359       /**
360      * Stores the object in the database. If the object is new,
361      * it inserts it; otherwise an update is performed. This method
362      * is meant to be used as part of a transaction, otherwise use
363      * the save() method and the connection details will be handled
364      * internally
365      *
366      * @param con
367      * @throws TorqueException
368      */

369     public void save(Connection JavaDoc con) throws TorqueException
370     {
371           if (!alreadyInSave)
372         {
373             alreadyInSave = true;
374
375
376   
377             // If this object has been modified, then save it to the database.
378
if (isModified())
379             {
380                 if (isNew())
381                 {
382                     TurbineRolePermissionPeer.doInsert((TurbineRolePermission) this, con);
383                     setNew(false);
384                 }
385                 else
386                 {
387                     TurbineRolePermissionPeer.doUpdate((TurbineRolePermission) this, con);
388                 }
389             }
390
391                       alreadyInSave = false;
392         }
393       }
394
395
396                                                 
397   
398     private final SimpleKey[] pks = new SimpleKey[2];
399     private final ComboKey comboPK = new ComboKey(pks);
400     
401     /**
402      * Set the PrimaryKey with an ObjectKey
403      *
404      * @param key
405      */

406     public void setPrimaryKey(ObjectKey key) throws TorqueException
407     {
408         SimpleKey[] keys = (SimpleKey[]) key.getValue();
409         SimpleKey tmpKey = null;
410                       setRoleId(new Integer JavaDoc(((NumberKey)keys[0]).intValue()));
411                         setPermissionId(new Integer JavaDoc(((NumberKey)keys[1]).intValue()));
412               }
413
414     /**
415      * Set the PrimaryKey using SimpleKeys.
416      *
417          * @param Integer roleId
418          * @param Integer permissionId
419          */

420     public void setPrimaryKey( Integer JavaDoc roleId, Integer JavaDoc permissionId)
421         throws TorqueException
422     {
423             setRoleId(roleId);
424             setPermissionId(permissionId);
425         }
426
427     /**
428      * Set the PrimaryKey using a String.
429      */

430     public void setPrimaryKey(String JavaDoc key) throws TorqueException
431     {
432         setPrimaryKey(new ComboKey(key));
433     }
434   
435     /**
436      * returns an id that differentiates this object from others
437      * of its class.
438      */

439     public ObjectKey getPrimaryKey()
440     {
441               pks[0] = SimpleKey.keyFor(getRoleId());
442                   pks[1] = SimpleKey.keyFor(getPermissionId());
443                   return comboPK;
444       }
445
446  
447     /**
448      * get an id that differentiates this object from others
449      * of its class.
450      */

451     public String JavaDoc getQueryKey()
452     {
453         if (getPrimaryKey() == null)
454         {
455             return "";
456         }
457         else
458         {
459             return getPrimaryKey().toString();
460         }
461     }
462
463     /**
464      * set an id that differentiates this object from others
465      * of its class.
466      */

467     public void setQueryKey(String JavaDoc key)
468         throws TorqueException
469     {
470         setPrimaryKey(key);
471     }
472
473     /**
474      * Makes a copy of this object.
475      * It creates a new object filling in the simple attributes.
476        * It then fills all the association collections and sets the
477      * related objects to isNew=true.
478        */

479       public TurbineRolePermission copy() throws TorqueException
480     {
481         return copyInto(new TurbineRolePermission());
482     }
483   
484     protected TurbineRolePermission copyInto(TurbineRolePermission copyObj) throws TorqueException
485     {
486           copyObj.setRoleId(roleId);
487           copyObj.setPermissionId(permissionId);
488   
489                     copyObj.setRoleId((Integer JavaDoc)null);
490                               copyObj.setPermissionId((Integer JavaDoc)null);
491             
492         
493         return copyObj;
494     }
495
496     /**
497      * returns a peer instance associated with this om. Since Peer classes
498      * are not to have any instance attributes, this method returns the
499      * same instance for all member of this class. The method could therefore
500      * be static, but this would prevent one from overriding the behavior.
501      */

502     public TurbineRolePermissionPeer getPeer()
503     {
504         return peer;
505     }
506
507     public String JavaDoc toString()
508     {
509         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
510         str.append("TurbineRolePermission:\n");
511         str.append("RoleId = ")
512            .append(getRoleId())
513            .append("\n");
514         str.append("PermissionId = ")
515            .append(getPermissionId())
516            .append("\n");
517         return(str.toString());
518     }
519 }
520
Popular Tags