View Javadoc

1   package org.apache.jetspeed.om.security.turbine;
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   * [Thu Apr 22 23:12:36 EDT 2004]
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       * @return int
52       */
53      public int getRoleId()
54      {
55          return roleId;
56      }
57  
58                                
59      /***
60       * Set the value of RoleId
61       */
62      public void setRoleId(int v ) throws TorqueException
63      {
64      
65                    if (this.roleId != v)
66                {
67              this.roleId = v;
68              setModified(true);
69          }
70      
71                                    
72                  if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v))
73                  {
74              aTurbineRole = null;
75          }
76        
77                }
78  
79    
80      /***
81       * Get the PermissionId
82       * @return int
83       */
84      public int getPermissionId()
85      {
86          return permissionId;
87      }
88  
89                                
90      /***
91       * Set the value of PermissionId
92       */
93      public void setPermissionId(int v ) throws TorqueException
94      {
95      
96                    if (this.permissionId != v)
97                {
98              this.permissionId = v;
99              setModified(true);
100         }
101     
102                                   
103                 if (aTurbinePermission != null && !(aTurbinePermission.getPermissionId() == v))
104                 {
105             aTurbinePermission = null;
106         }
107       
108               }
109 
110   
111       
112         
113                   
114         private TurbineRole aTurbineRole;
115 
116     /***
117      * Declares an association between this object and a TurbineRole object
118      *
119      * @param TurbineRole v
120      */
121     public void setTurbineRole(TurbineRole v) throws TorqueException
122     {
123             if (v == null)
124         {
125                   setRoleId(0);
126               }
127         else
128         {
129             setRoleId(v.getRoleId());
130         }
131             aTurbineRole = v;
132     }
133 
134                         
135     public TurbineRole getTurbineRole() throws TorqueException
136     {
137         if ( getRoleId()>0 )
138         {
139                 return TurbineRoleManager.getInstance(SimpleKey.keyFor(getRoleId()));
140             }
141         return aTurbineRole;
142     }
143 
144     /***
145      * Provides convenient way to set a relationship based on a
146      * ObjectKey.  e.g.
147      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
148      *
149          */
150     public void setTurbineRoleKey(ObjectKey key) throws TorqueException
151     {
152     
153                     setRoleId(((NumberKey) key).intValue());
154               }
155 
156   
157         
158                   
159         private TurbinePermission aTurbinePermission;
160 
161     /***
162      * Declares an association between this object and a TurbinePermission object
163      *
164      * @param TurbinePermission v
165      */
166     public void setTurbinePermission(TurbinePermission v) throws TorqueException
167     {
168             if (v == null)
169         {
170                   setPermissionId(0);
171               }
172         else
173         {
174             setPermissionId(v.getPermissionId());
175         }
176             aTurbinePermission = v;
177     }
178 
179                         
180     public TurbinePermission getTurbinePermission() throws TorqueException
181     {
182         if ( getPermissionId()>0 )
183         {
184                 return TurbinePermissionManager.getInstance(SimpleKey.keyFor(getPermissionId()));
185             }
186         return aTurbinePermission;
187     }
188 
189     /***
190      * Provides convenient way to set a relationship based on a
191      * ObjectKey.  e.g.
192      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
193      *
194          */
195     public void setTurbinePermissionKey(ObjectKey key) throws TorqueException
196     {
197     
198                     setPermissionId(((NumberKey) key).intValue());
199               }
200 
201      
202                 
203     private static List fieldNames = null;
204 
205     /***
206      * Generate a list of field names.
207      */
208     public static synchronized List getFieldNames()
209     {
210         if (fieldNames == null)
211         {
212             fieldNames = new ArrayList();
213               fieldNames.add("RoleId");
214               fieldNames.add("PermissionId");
215               fieldNames = Collections.unmodifiableList(fieldNames);
216         }
217         return fieldNames;
218     }
219 
220     /***
221      * Retrieves a field from the object by name passed in
222      * as a String.
223      */
224     public Object getByName(String name)
225     {
226           if (name.equals("RoleId"))
227         {
228                 return new Integer(getRoleId());
229             }
230           if (name.equals("PermissionId"))
231         {
232                 return new Integer(getPermissionId());
233             }
234           return null;
235     }
236     
237     /***
238      * Retrieves a field from the object by name passed in
239      * as a String.  The String must be one of the static
240      * Strings defined in this Class' Peer.
241      */
242     public Object getByPeerName(String name)
243     {
244           if (name.equals(TurbineRolePermissionPeer.ROLE_ID ))
245         {
246                 return new Integer(getRoleId());
247             }
248           if (name.equals(TurbineRolePermissionPeer.PERMISSION_ID ))
249         {
250                 return new Integer(getPermissionId());
251             }
252           return null;
253     }
254 
255     /***
256      * Retrieves a field from the object by Position as specified
257      * in the xml schema.  Zero-based.
258      */
259     public Object getByPosition(int pos)
260     {
261             if ( pos == 0 )
262         {
263                 return new Integer(getRoleId());
264             }
265               if ( pos == 1 )
266         {
267                 return new Integer(getPermissionId());
268             }
269               return null;
270     }
271      
272     /***
273      * Stores the object in the database.  If the object is new,
274      * it inserts it; otherwise an update is performed.
275      */
276     public void save() throws Exception
277     {
278           save(TurbineRolePermissionPeer.getMapBuilder()
279                 .getDatabaseMap().getName());
280       }
281 
282     /***
283      * Stores the object in the database.  If the object is new,
284      * it inserts it; otherwise an update is performed.
285        * Note: this code is here because the method body is
286      * auto-generated conditionally and therefore needs to be
287      * in this file instead of in the super class, BaseObject.
288        */
289     public void save(String dbName) throws TorqueException
290     {
291         Connection con = null;
292           try
293         {
294             con = Transaction.begin(dbName);
295             save(con);
296             Transaction.commit(con);
297         }
298         catch(TorqueException e)
299         {
300             Transaction.safeRollback(con);
301             throw e;
302         }
303       }
304 
305       /*** flag to prevent endless save loop, if this object is referenced
306         by another object which falls in this transaction. */
307     private boolean alreadyInSave = false;
308       /***
309      * Stores the object in the database.  If the object is new,
310      * it inserts it; otherwise an update is performed.  This method
311      * is meant to be used as part of a transaction, otherwise use
312      * the save() method and the connection details will be handled
313      * internally
314      */
315     public void save(Connection con) throws TorqueException
316     {
317           if (!alreadyInSave)
318         {
319             alreadyInSave = true;
320 
321 
322   
323             // If this object has been modified, then save it to the database.
324             if (isModified())
325             {
326                 if (isNew())
327                 {
328                     TurbineRolePermissionPeer.doInsert((TurbineRolePermission)this, con);
329                     setNew(false);
330                 }
331                 else
332                 {
333                     TurbineRolePermissionPeer.doUpdate((TurbineRolePermission)this, con);
334                 }
335 
336                       if (isCacheOnSave())
337                 {
338                     TurbineRolePermissionManager.putInstance(this);
339                 }
340               }
341 
342                       alreadyInSave = false;
343         }
344       }
345 
346     /***
347      * Specify whether to cache the object after saving to the db.
348      * This method returns false
349      */
350     protected boolean isCacheOnSave()
351     {
352         return true;
353     }
354 
355                                               
356   
357     private final SimpleKey[] pks = new SimpleKey[2];
358     private final ComboKey comboPK = new ComboKey(pks);
359     /***
360      * Set the PrimaryKey with an ObjectKey
361      */
362     public void setPrimaryKey(ObjectKey key) throws TorqueException
363     {
364         SimpleKey[] keys = (SimpleKey[]) key.getValue();
365         SimpleKey tmpKey = null;
366                       setRoleId(((NumberKey)keys[0]).intValue());
367                         setPermissionId(((NumberKey)keys[1]).intValue());
368               }
369 
370     /***
371      * Set the PrimaryKey using SimpleKeys.
372      *
373          * @param int roleId
374          * @param int permissionId
375          */
376     public void setPrimaryKey( int roleId, int permissionId)
377         throws TorqueException 
378     {
379             setRoleId(roleId);
380             setPermissionId(permissionId);
381         }
382 
383     /***
384      * Set the PrimaryKey using a String.
385      */
386     public void setPrimaryKey(String key) throws TorqueException
387     {
388         setPrimaryKey(new ComboKey(key));
389     }
390   
391     /***
392      * returns an id that differentiates this object from others
393      * of its class.
394      */
395     public ObjectKey getPrimaryKey()
396     {
397               pks[0] = SimpleKey.keyFor(getRoleId());
398                   pks[1] = SimpleKey.keyFor(getPermissionId());
399                   return comboPK;
400       }
401  
402 
403     /***
404      * Makes a copy of this object.
405      * It creates a new object filling in the simple attributes.
406        * It then fills all the association collections.
407        */
408       public TurbineRolePermission copy() throws TorqueException
409     {
410         TurbineRolePermission copyObj = new TurbineRolePermission();
411             copyObj.setRoleId(roleId);
412           copyObj.setPermissionId(permissionId);
413   
414                       copyObj.setRoleId(0);
415                                 copyObj.setPermissionId(0);
416             
417                 return copyObj;
418     }
419 
420     /***
421      * returns a peer instance associated with this om.  Since Peer classes
422      * are not to have any instance attributes, this method returns the
423      * same instance for all member of this class. The method could therefore
424      * be static, but this would prevent one from overriding the behavior.
425      */
426     public TurbineRolePermissionPeer getPeer()
427     {
428         return peer;
429     }
430 }