KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > campware > cream > om > BaseTurbineRolePermission


1 package org.campware.cream.om;
2
3
4 import java.math.BigDecimal JavaDoc;
5 import java.sql.Connection JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Collections JavaDoc;
8 import java.util.Date JavaDoc;
9 import java.util.List JavaDoc;
10
11 import org.apache.commons.lang.ObjectUtils;
12 import org.apache.turbine.om.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  * This class was autogenerated by Torque on:
30  *
31  * [Wed May 04 09:10:56 CEST 2005]
32  *
33  * You should not use this class directly. It should not even be
34  * extended all references should be to TurbineRolePermission
35  */

36 public abstract class BaseTurbineRolePermission extends BaseObject
37     implements org.apache.turbine.om.Retrievable
38 {
39     /** The Peer class */
40     private static final TurbineRolePermissionPeer peer =
41         new TurbineRolePermissionPeer();
42
43         
44     /** The value for the roleId field */
45     private int roleId;
46       
47     /** The value for the permissionId field */
48     private int permissionId;
49   
50     
51     /**
52      * Get the RoleId
53      *
54      * @return int
55      */

56     public int getRoleId()
57     {
58         return roleId;
59     }
60
61                               
62     /**
63      * Set the value of RoleId
64      *
65      * @param v new value
66      */

67     public void setRoleId(int v) throws TorqueException
68     {
69     
70                   if (this.roleId != v)
71               {
72             this.roleId = v;
73             setModified(true);
74         }
75     
76                           
77                 if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v))
78                 {
79             aTurbineRole = null;
80         }
81       
82               }
83   
84     /**
85      * Get the PermissionId
86      *
87      * @return int
88      */

89     public int getPermissionId()
90     {
91         return permissionId;
92     }
93
94                               
95     /**
96      * Set the value of PermissionId
97      *
98      * @param v new value
99      */

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

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

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

164         }
165         return aTurbineRole;
166     }
167
168     /**
169      * Provides convenient way to set a relationship based on a
170      * ObjectKey, for example
171      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
172      *
173          */

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

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

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

226         }
227         return aTurbinePermission;
228     }
229
230     /**
231      * Provides convenient way to set a relationship based on a
232      * ObjectKey, for example
233      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
234      *
235          */

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

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

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

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

309     public Object JavaDoc getByPosition(int pos)
310     {
311             if (pos == 0)
312         {
313                 return new Integer JavaDoc(getRoleId());
314             }
315               if (pos == 1)
316         {
317                 return new Integer JavaDoc(getPermissionId());
318             }
319               return null;
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      *
326      * @throws Exception
327      */

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

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

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

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

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

423     public void setPrimaryKey( int roleId, int permissionId)
424         throws TorqueException
425     {
426             setRoleId(roleId);
427             setPermissionId(permissionId);
428         }
429
430     /**
431      * Set the PrimaryKey using a String.
432      */

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

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

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

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

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

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