View Javadoc

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