View Javadoc

1   package org.apache.turbine.services.security.torque.om;
2   
3   
4   import java.math.BigDecimal;
5   import java.sql.Connection;
6   import java.util.ArrayList;
7   import java.util.Collections;
8   import java.util.Date;
9   import java.util.List;
10  
11  import org.apache.commons.lang.ObjectUtils;
12  import org.apache.torque.TorqueException;
13  import org.apache.torque.om.BaseObject;
14  import org.apache.torque.om.ComboKey;
15  import org.apache.torque.om.DateKey;
16  import org.apache.torque.om.NumberKey;
17  import org.apache.torque.om.ObjectKey;
18  import org.apache.torque.om.SimpleKey;
19  import org.apache.torque.om.StringKey;
20  import org.apache.torque.om.Persistent;
21  import org.apache.torque.util.Criteria;
22  import org.apache.torque.util.Transaction;
23  
24    
25      
26    
27  /***
28   * This class was autogenerated by Torque on:
29   *
30   * [Mon Oct 03 14:24:58 CEST 2005]
31   *
32   * You should not use this class directly.  It should not even be
33   * extended all references should be to TurbineRolePermission
34   */
35  public abstract class BaseTurbineRolePermission extends BaseObject
36  {
37      /*** The Peer class */
38      private static final TurbineRolePermissionPeer peer =
39          new TurbineRolePermissionPeer();
40  
41          
42      /*** The value for the roleId field */
43      private int roleId;
44        
45      /*** The value for the permissionId field */
46      private int permissionId;
47    
48      
49      /***
50       * Get the RoleId
51       *
52       * @return int
53       */
54      public int getRoleId()
55      {
56          return roleId;
57      }
58  
59                                
60      /***
61       * Set the value of RoleId
62       *
63       * @param v new value
64       */
65      public void setRoleId(int v) throws TorqueException
66      {
67      
68                    if (this.roleId != v)
69                {
70              this.roleId = v;
71              setModified(true);
72          }
73      
74                            
75                  if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v))
76                  {
77              aTurbineRole = null;
78          }
79        
80                }
81    
82      /***
83       * Get the PermissionId
84       *
85       * @return int
86       */
87      public int getPermissionId()
88      {
89          return permissionId;
90      }
91  
92                                
93      /***
94       * Set the value of PermissionId
95       *
96       * @param v new value
97       */
98      public void setPermissionId(int v) throws TorqueException
99      {
100     
101                   if (this.permissionId != v)
102               {
103             this.permissionId = v;
104             setModified(true);
105         }
106     
107                           
108                 if (aTurbinePermission != null && !(aTurbinePermission.getPermissionId() == v))
109                 {
110             aTurbinePermission = null;
111         }
112       
113               }
114   
115       
116     
117                   
118     
119         private TurbineRole aTurbineRole;
120 
121     /***
122      * Declares an association between this object and a TurbineRole object
123      *
124      * @param v TurbineRole
125      * @throws TorqueException
126      */
127     public void setTurbineRole(TurbineRole v) throws TorqueException
128     {
129             if (v == null)
130         {
131                           setRoleId( 0);
132               }
133         else
134         {
135             setRoleId(v.getRoleId());
136         }
137             aTurbineRole = v;
138     }
139 
140                                             
141     /***
142      * Get the associated TurbineRole object
143      *
144      * @return the associated TurbineRole object
145      * @throws TorqueException
146      */
147     public TurbineRole getTurbineRole() throws TorqueException
148     {
149         if (aTurbineRole == null && (this.roleId != 0))
150         {
151                           aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId));
152               
153             /* The following can be used instead of the line above to
154                guarantee the related object contains a reference
155                to this object, but this level of coupling
156                may be undesirable in many circumstances.
157                As it can lead to a db query with many results that may
158                never be used.
159                TurbineRole obj = TurbineRolePeer.retrieveByPK(this.roleId);
160                obj.addTurbineRolePermissions(this);
161             */
162         }
163         return aTurbineRole;
164     }
165 
166     /***
167      * Provides convenient way to set a relationship based on a
168      * ObjectKey, for example
169      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
170      *
171          */
172     public void setTurbineRoleKey(ObjectKey key) throws TorqueException
173     {
174       
175                         setRoleId(((NumberKey) key).intValue());
176                   }
177     
178     
179                   
180     
181         private TurbinePermission aTurbinePermission;
182 
183     /***
184      * Declares an association between this object and a TurbinePermission object
185      *
186      * @param v TurbinePermission
187      * @throws TorqueException
188      */
189     public void setTurbinePermission(TurbinePermission v) throws TorqueException
190     {
191             if (v == null)
192         {
193                           setPermissionId( 0);
194               }
195         else
196         {
197             setPermissionId(v.getPermissionId());
198         }
199             aTurbinePermission = v;
200     }
201 
202                                             
203     /***
204      * Get the associated TurbinePermission object
205      *
206      * @return the associated TurbinePermission object
207      * @throws TorqueException
208      */
209     public TurbinePermission getTurbinePermission() throws TorqueException
210     {
211         if (aTurbinePermission == null && (this.permissionId != 0))
212         {
213                           aTurbinePermission = TurbinePermissionPeer.retrieveByPK(SimpleKey.keyFor(this.permissionId));
214               
215             /* The following can be used instead of the line above to
216                guarantee the related object contains a reference
217                to this object, but this level of coupling
218                may be undesirable in many circumstances.
219                As it can lead to a db query with many results that may
220                never be used.
221                TurbinePermission obj = TurbinePermissionPeer.retrieveByPK(this.permissionId);
222                obj.addTurbineRolePermissions(this);
223             */
224         }
225         return aTurbinePermission;
226     }
227 
228     /***
229      * Provides convenient way to set a relationship based on a
230      * ObjectKey, for example
231      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
232      *
233          */
234     public void setTurbinePermissionKey(ObjectKey key) throws TorqueException
235     {
236       
237                         setPermissionId(((NumberKey) key).intValue());
238                   }
239        
240                 
241     private static List fieldNames = null;
242 
243     /***
244      * Generate a list of field names.
245      *
246      * @return a list of field names
247      */
248     public static synchronized List getFieldNames()
249     {
250         if (fieldNames == null)
251         {
252             fieldNames = new ArrayList();
253               fieldNames.add("RoleId");
254               fieldNames.add("PermissionId");
255               fieldNames = Collections.unmodifiableList(fieldNames);
256         }
257         return fieldNames;
258     }
259 
260     /***
261      * Retrieves a field from the object by name passed in as a String.
262      *
263      * @param name field name
264      * @return value
265      */
266     public Object getByName(String name)
267     {
268           if (name.equals("RoleId"))
269         {
270                 return new Integer(getRoleId());
271             }
272           if (name.equals("PermissionId"))
273         {
274                 return new Integer(getPermissionId());
275             }
276           return null;
277     }
278     
279     /***
280      * Retrieves a field from the object by name passed in
281      * as a String.  The String must be one of the static
282      * Strings defined in this Class' Peer.
283      *
284      * @param name peer name
285      * @return value
286      */
287     public Object getByPeerName(String name)
288     {
289           if (name.equals(TurbineRolePermissionPeer.ROLE_ID))
290         {
291                 return new Integer(getRoleId());
292             }
293           if (name.equals(TurbineRolePermissionPeer.PERMISSION_ID))
294         {
295                 return new Integer(getPermissionId());
296             }
297           return null;
298     }
299 
300     /***
301      * Retrieves a field from the object by Position as specified
302      * in the xml schema.  Zero-based.
303      *
304      * @param pos position in xml schema
305      * @return value
306      */
307     public Object getByPosition(int pos)
308     {
309             if (pos == 0)
310         {
311                 return new Integer(getRoleId());
312             }
313               if (pos == 1)
314         {
315                 return new Integer(getPermissionId());
316             }
317               return null;
318     }
319      
320     /***
321      * Stores the object in the database.  If the object is new,
322      * it inserts it; otherwise an update is performed.
323      *
324      * @throws Exception
325      */
326     public void save() throws Exception
327     {
328           save(TurbineRolePermissionPeer.getMapBuilder()
329                 .getDatabaseMap().getName());
330       }
331 
332     /***
333      * Stores the object in the database.  If the object is new,
334      * it inserts it; otherwise an update is performed.
335        * Note: this code is here because the method body is
336      * auto-generated conditionally and therefore needs to be
337      * in this file instead of in the super class, BaseObject.
338        *
339      * @param dbName
340      * @throws TorqueException
341      */
342     public void save(String dbName) throws TorqueException
343     {
344         Connection con = null;
345           try
346         {
347             con = Transaction.begin(dbName);
348             save(con);
349             Transaction.commit(con);
350         }
351         catch(TorqueException e)
352         {
353             Transaction.safeRollback(con);
354             throw e;
355         }
356       }
357 
358       /*** flag to prevent endless save loop, if this object is referenced
359         by another object which falls in this transaction. */
360     private boolean alreadyInSave = false;
361       /***
362      * Stores the object in the database.  If the object is new,
363      * it inserts it; otherwise an update is performed.  This method
364      * is meant to be used as part of a transaction, otherwise use
365      * the save() method and the connection details will be handled
366      * internally
367      *
368      * @param con
369      * @throws TorqueException
370      */
371     public void save(Connection con) throws TorqueException
372     {
373           if (!alreadyInSave)
374         {
375             alreadyInSave = true;
376 
377 
378   
379             // If this object has been modified, then save it to the database.
380             if (isModified())
381             {
382                 if (isNew())
383                 {
384                     TurbineRolePermissionPeer.doInsert((TurbineRolePermission) this, con);
385                     setNew(false);
386                 }
387                 else
388                 {
389                     TurbineRolePermissionPeer.doUpdate((TurbineRolePermission) this, con);
390                 }
391             }
392 
393                       alreadyInSave = false;
394         }
395       }
396 
397                                               
398   
399     private final SimpleKey[] pks = new SimpleKey[2];
400     private final ComboKey comboPK = new ComboKey(pks);
401     
402     /***
403      * Set the PrimaryKey with an ObjectKey
404      *
405      * @param key
406      */
407     public void setPrimaryKey(ObjectKey key) throws TorqueException
408     {
409         SimpleKey[] keys = (SimpleKey[]) key.getValue();
410         SimpleKey tmpKey = null;
411                       setRoleId(((NumberKey)keys[0]).intValue());
412                         setPermissionId(((NumberKey)keys[1]).intValue());
413               }
414 
415     /***
416      * Set the PrimaryKey using SimpleKeys.
417      *
418          * @param roleId int
419          * @param permissionId int
420          */
421     public void setPrimaryKey( int roleId, int permissionId)
422         throws TorqueException
423     {
424             setRoleId(roleId);
425             setPermissionId(permissionId);
426         }
427 
428     /***
429      * Set the PrimaryKey using a String.
430      */
431     public void setPrimaryKey(String key) throws TorqueException
432     {
433         setPrimaryKey(new ComboKey(key));
434     }
435   
436     /***
437      * returns an id that differentiates this object from others
438      * of its class.
439      */
440     public ObjectKey getPrimaryKey()
441     {
442               pks[0] = SimpleKey.keyFor(getRoleId());
443                   pks[1] = SimpleKey.keyFor(getPermissionId());
444                   return comboPK;
445       }
446  
447 
448     /***
449      * Makes a copy of this object.
450      * It creates a new object filling in the simple attributes.
451        * It then fills all the association collections and sets the
452      * related objects to isNew=true.
453        */
454       public TurbineRolePermission copy() throws TorqueException
455     {
456         return copyInto(new TurbineRolePermission());
457     }
458   
459     protected TurbineRolePermission copyInto(TurbineRolePermission copyObj) throws TorqueException
460     {
461           copyObj.setRoleId(roleId);
462           copyObj.setPermissionId(permissionId);
463   
464                             copyObj.setRoleId( 0);
465                                       copyObj.setPermissionId( 0);
466             
467                 return copyObj;
468     }
469 
470     /***
471      * returns a peer instance associated with this om.  Since Peer classes
472      * are not to have any instance attributes, this method returns the
473      * same instance for all member of this class. The method could therefore
474      * be static, but this would prevent one from overriding the behavior.
475      */
476     public TurbineRolePermissionPeer getPeer()
477     {
478         return peer;
479     }
480 
481     public String toString()
482     {
483         StringBuffer str = new StringBuffer();
484         str.append("TurbineRolePermission:\n");
485         str.append("RoleId = ")
486                .append(getRoleId())
487              .append("\n");
488         str.append("PermissionId = ")
489                .append(getPermissionId())
490              .append("\n");
491         return(str.toString());
492     }
493 }