KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

50     public Integer JavaDoc getPermissionId()
51     {
52         return permissionId;
53     }
54
55                                               
56     /**
57      * Set the value of PermissionId
58      *
59      * @param v new value
60      */

61     public void setPermissionId(Integer JavaDoc v) throws TorqueException
62     {
63     
64                   if (!ObjectUtils.equals(this.permissionId, v))
65               {
66             this.permissionId = v;
67             setModified(true);
68         }
69     
70           
71                                   
72         // update associated TurbineRolePermission
73
if (collTurbineRolePermissions != null)
74         {
75             for (int i = 0; i < collTurbineRolePermissions.size(); i++)
76             {
77                 ((TurbineRolePermission) collTurbineRolePermissions.get(i))
78                     .setPermissionId(v);
79             }
80         }
81                       }
82   
83     /**
84      * Get the Name
85      *
86      * @return String
87      */

88     public String JavaDoc getName()
89     {
90         return name;
91     }
92
93                         
94     /**
95      * Set the value of Name
96      *
97      * @param v new value
98      */

99     public void setName(String JavaDoc v)
100     {
101     
102                   if (!ObjectUtils.equals(this.name, v))
103               {
104             this.name = v;
105             setModified(true);
106         }
107     
108           
109               }
110   
111          
112                                 
113             
114     /**
115      * Collection to store aggregation of collTurbineRolePermissions
116      */

117     protected List JavaDoc collTurbineRolePermissions;
118
119     /**
120      * Temporary storage of collTurbineRolePermissions to save a possible db hit in
121      * the event objects are add to the collection, but the
122      * complete collection is never requested.
123      */

124     protected void initTurbineRolePermissions()
125     {
126         if (collTurbineRolePermissions == null)
127         {
128             collTurbineRolePermissions = new ArrayList JavaDoc();
129         }
130     }
131
132     /**
133      * Method called to associate a TurbineRolePermission object to this object
134      * through the TurbineRolePermission foreign key attribute
135      *
136      * @param l TurbineRolePermission
137      * @throws TorqueException
138      */

139     public void addTurbineRolePermission(TurbineRolePermission l) throws TorqueException
140     {
141         getTurbineRolePermissions().add(l);
142         l.setTurbinePermission((TurbinePermission) this);
143     }
144
145     /**
146      * The criteria used to select the current contents of collTurbineRolePermissions
147      */

148     private Criteria lastTurbineRolePermissionsCriteria = null;
149
150     /**
151      * If this collection has already been initialized, returns
152      * the collection. Otherwise returns the results of
153      * getTurbineRolePermissions(new Criteria())
154      *
155      * @throws TorqueException
156      */

157     public List JavaDoc getTurbineRolePermissions() throws TorqueException
158     {
159         if (collTurbineRolePermissions == null)
160         {
161             collTurbineRolePermissions = getTurbineRolePermissions(new Criteria(10));
162         }
163         return collTurbineRolePermissions;
164     }
165
166     /**
167      * If this collection has already been initialized with
168      * an identical criteria, it returns the collection.
169      * Otherwise if this TurbinePermission has previously
170      * been saved, it will retrieve related TurbineRolePermissions from storage.
171      * If this TurbinePermission is new, it will return
172      * an empty collection or the current collection, the criteria
173      * is ignored on a new object.
174      *
175      * @throws TorqueException
176      */

177     public List JavaDoc getTurbineRolePermissions(Criteria criteria) throws TorqueException
178     {
179         if (collTurbineRolePermissions == null)
180         {
181             if (isNew())
182             {
183                collTurbineRolePermissions = new ArrayList JavaDoc();
184             }
185             else
186             {
187                       criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() );
188                       collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria);
189             }
190         }
191         else
192         {
193             // criteria has no effect for a new object
194
if (!isNew())
195             {
196                 // the following code is to determine if a new query is
197
// called for. If the criteria is the same as the last
198
// one, just return the collection.
199
criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
200                       if (!lastTurbineRolePermissionsCriteria.equals(criteria))
201                 {
202                     collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria);
203                 }
204             }
205         }
206         lastTurbineRolePermissionsCriteria = criteria;
207
208         return collTurbineRolePermissions;
209     }
210
211     /**
212      * If this collection has already been initialized, returns
213      * the collection. Otherwise returns the results of
214      * getTurbineRolePermissions(new Criteria(),Connection)
215      * This method takes in the Connection also as input so that
216      * referenced objects can also be obtained using a Connection
217      * that is taken as input
218      */

219     public List JavaDoc getTurbineRolePermissions(Connection JavaDoc con) throws TorqueException
220     {
221         if (collTurbineRolePermissions == null)
222         {
223             collTurbineRolePermissions = getTurbineRolePermissions(new Criteria(10), con);
224         }
225         return collTurbineRolePermissions;
226     }
227
228     /**
229      * If this collection has already been initialized with
230      * an identical criteria, it returns the collection.
231      * Otherwise if this TurbinePermission has previously
232      * been saved, it will retrieve related TurbineRolePermissions from storage.
233      * If this TurbinePermission is new, it will return
234      * an empty collection or the current collection, the criteria
235      * is ignored on a new object.
236      * This method takes in the Connection also as input so that
237      * referenced objects can also be obtained using a Connection
238      * that is taken as input
239      */

240     public List JavaDoc getTurbineRolePermissions(Criteria criteria, Connection JavaDoc con)
241             throws TorqueException
242     {
243         if (collTurbineRolePermissions == null)
244         {
245             if (isNew())
246             {
247                collTurbineRolePermissions = new ArrayList JavaDoc();
248             }
249             else
250             {
251                        criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
252                        collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria, con);
253              }
254          }
255          else
256          {
257              // criteria has no effect for a new object
258
if (!isNew())
259              {
260                  // the following code is to determine if a new query is
261
// called for. If the criteria is the same as the last
262
// one, just return the collection.
263
criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
264                        if (!lastTurbineRolePermissionsCriteria.equals(criteria))
265                  {
266                      collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria, con);
267                  }
268              }
269          }
270          lastTurbineRolePermissionsCriteria = criteria;
271
272          return collTurbineRolePermissions;
273      }
274
275                         
276               
277                     
278                     
279                                 
280                                                               
281                                         
282                     
283                     
284           
285     /**
286      * If this collection has already been initialized with
287      * an identical criteria, it returns the collection.
288      * Otherwise if this TurbinePermission is new, it will return
289      * an empty collection; or if this TurbinePermission has previously
290      * been saved, it will retrieve related TurbineRolePermissions from storage.
291      *
292      * This method is protected by default in order to keep the public
293      * api reasonable. You can provide public methods for those you
294      * actually need in TurbinePermission.
295      */

296     protected List JavaDoc getTurbineRolePermissionsJoinTurbineRole(Criteria criteria)
297         throws TorqueException
298     {
299         if (collTurbineRolePermissions == null)
300         {
301             if (isNew())
302             {
303                collTurbineRolePermissions = new ArrayList JavaDoc();
304             }
305             else
306             {
307                             criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
308                             collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria);
309             }
310         }
311         else
312         {
313             // the following code is to determine if a new query is
314
// called for. If the criteria is the same as the last
315
// one, just return the collection.
316
boolean newCriteria = true;
317                         criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
318                         if (!lastTurbineRolePermissionsCriteria.equals(criteria))
319             {
320                 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria);
321             }
322         }
323         lastTurbineRolePermissionsCriteria = criteria;
324
325         return collTurbineRolePermissions;
326     }
327                   
328                     
329                               
330                                 
331                                                               
332                                         
333                     
334                     
335           
336     /**
337      * If this collection has already been initialized with
338      * an identical criteria, it returns the collection.
339      * Otherwise if this TurbinePermission is new, it will return
340      * an empty collection; or if this TurbinePermission has previously
341      * been saved, it will retrieve related TurbineRolePermissions from storage.
342      *
343      * This method is protected by default in order to keep the public
344      * api reasonable. You can provide public methods for those you
345      * actually need in TurbinePermission.
346      */

347     protected List JavaDoc getTurbineRolePermissionsJoinTurbinePermission(Criteria criteria)
348         throws TorqueException
349     {
350         if (collTurbineRolePermissions == null)
351         {
352             if (isNew())
353             {
354                collTurbineRolePermissions = new ArrayList JavaDoc();
355             }
356             else
357             {
358                             criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
359                             collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria);
360             }
361         }
362         else
363         {
364             // the following code is to determine if a new query is
365
// called for. If the criteria is the same as the last
366
// one, just return the collection.
367
boolean newCriteria = true;
368                         criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId());
369                         if (!lastTurbineRolePermissionsCriteria.equals(criteria))
370             {
371                 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria);
372             }
373         }
374         lastTurbineRolePermissionsCriteria = criteria;
375
376         return collTurbineRolePermissions;
377     }
378                             
379
380
381           
382     private static List JavaDoc fieldNames = null;
383
384     /**
385      * Generate a list of field names.
386      *
387      * @return a list of field names
388      */

389     public static synchronized List JavaDoc getFieldNames()
390     {
391         if (fieldNames == null)
392         {
393             fieldNames = new ArrayList JavaDoc();
394               fieldNames.add("PermissionId");
395               fieldNames.add("Name");
396               fieldNames = Collections.unmodifiableList(fieldNames);
397         }
398         return fieldNames;
399     }
400
401     /**
402      * Retrieves a field from the object by name passed in as a String.
403      *
404      * @param name field name
405      * @return value
406      */

407     public Object JavaDoc getByName(String JavaDoc name)
408     {
409           if (name.equals("PermissionId"))
410         {
411                 return getPermissionId();
412             }
413           if (name.equals("Name"))
414         {
415                 return getName();
416             }
417           return null;
418     }
419     
420     /**
421      * Retrieves a field from the object by name passed in
422      * as a String. The String must be one of the static
423      * Strings defined in this Class' Peer.
424      *
425      * @param name peer name
426      * @return value
427      */

428     public Object JavaDoc getByPeerName(String JavaDoc name)
429     {
430           if (name.equals(TurbinePermissionPeer.PERMISSION_ID))
431         {
432                 return getPermissionId();
433             }
434           if (name.equals(TurbinePermissionPeer.PERMISSION_NAME))
435         {
436                 return getName();
437             }
438           return null;
439     }
440
441     /**
442      * Retrieves a field from the object by Position as specified
443      * in the xml schema. Zero-based.
444      *
445      * @param pos position in xml schema
446      * @return value
447      */

448     public Object JavaDoc getByPosition(int pos)
449     {
450             if (pos == 0)
451         {
452                 return getPermissionId();
453             }
454               if (pos == 1)
455         {
456                 return getName();
457             }
458               return null;
459     }
460      
461     /**
462      * Stores the object in the database. If the object is new,
463      * it inserts it; otherwise an update is performed.
464      *
465      * @throws Exception
466      */

467     public void save() throws Exception JavaDoc
468     {
469           save(TurbinePermissionPeer.getMapBuilder()
470                 .getDatabaseMap().getName());
471       }
472
473     /**
474      * Stores the object in the database. If the object is new,
475      * it inserts it; otherwise an update is performed.
476        * Note: this code is here because the method body is
477      * auto-generated conditionally and therefore needs to be
478      * in this file instead of in the super class, BaseObject.
479        *
480      * @param dbName
481      * @throws TorqueException
482      */

483     public void save(String JavaDoc dbName) throws TorqueException
484     {
485         Connection JavaDoc con = null;
486           try
487         {
488             con = Transaction.begin(dbName);
489             save(con);
490             Transaction.commit(con);
491         }
492         catch(TorqueException e)
493         {
494             Transaction.safeRollback(con);
495             throw e;
496         }
497       }
498
499       /** flag to prevent endless save loop, if this object is referenced
500         by another object which falls in this transaction. */

501     private boolean alreadyInSave = false;
502       /**
503      * Stores the object in the database. If the object is new,
504      * it inserts it; otherwise an update is performed. This method
505      * is meant to be used as part of a transaction, otherwise use
506      * the save() method and the connection details will be handled
507      * internally
508      *
509      * @param con
510      * @throws TorqueException
511      */

512     public void save(Connection JavaDoc con) throws TorqueException
513     {
514           if (!alreadyInSave)
515         {
516             alreadyInSave = true;
517
518
519   
520             // If this object has been modified, then save it to the database.
521
if (isModified())
522             {
523                 if (isNew())
524                 {
525                     TurbinePermissionPeer.doInsert((TurbinePermission) this, con);
526                     setNew(false);
527                 }
528                 else
529                 {
530                     TurbinePermissionPeer.doUpdate((TurbinePermission) this, con);
531                 }
532             }
533
534                                       
535                 
536             if (collTurbineRolePermissions != null)
537             {
538                 for (int i = 0; i < collTurbineRolePermissions.size(); i++)
539                 {
540                     ((TurbineRolePermission) collTurbineRolePermissions.get(i)).save(con);
541                 }
542             }
543                           alreadyInSave = false;
544         }
545       }
546
547
548                           
549       /**
550      * Set the PrimaryKey using ObjectKey.
551      *
552      * @param permissionId ObjectKey
553      */

554     public void setPrimaryKey(ObjectKey key)
555         throws TorqueException
556     {
557             setPermissionId(new Integer JavaDoc(((NumberKey) key).intValue()));
558         }
559
560     /**
561      * Set the PrimaryKey using a String.
562      *
563      * @param key
564      */

565     public void setPrimaryKey(String JavaDoc key) throws TorqueException
566     {
567             setPermissionId(new Integer JavaDoc(key));
568         }
569
570   
571     /**
572      * returns an id that differentiates this object from others
573      * of its class.
574      */

575     public ObjectKey getPrimaryKey()
576     {
577           return SimpleKey.keyFor(getPermissionId());
578       }
579
580  
581     /**
582      * get an id that differentiates this object from others
583      * of its class.
584      */

585     public String JavaDoc getQueryKey()
586     {
587         if (getPrimaryKey() == null)
588         {
589             return "";
590         }
591         else
592         {
593             return getPrimaryKey().toString();
594         }
595     }
596
597     /**
598      * set an id that differentiates this object from others
599      * of its class.
600      */

601     public void setQueryKey(String JavaDoc key)
602         throws TorqueException
603     {
604         setPrimaryKey(key);
605     }
606
607     /**
608      * Makes a copy of this object.
609      * It creates a new object filling in the simple attributes.
610        * It then fills all the association collections and sets the
611      * related objects to isNew=true.
612        */

613       public TurbinePermission copy() throws TorqueException
614     {
615         return copyInto(new TurbinePermission());
616     }
617   
618     protected TurbinePermission copyInto(TurbinePermission copyObj) throws TorqueException
619     {
620           copyObj.setPermissionId(permissionId);
621           copyObj.setName(name);
622   
623                     copyObj.setPermissionId((Integer JavaDoc)null);
624                   
625                                       
626                 
627         List JavaDoc v = getTurbineRolePermissions();
628         for (int i = 0; i < v.size(); i++)
629         {
630             TurbineRolePermission obj = (TurbineRolePermission) v.get(i);
631             copyObj.addTurbineRolePermission(obj.copy());
632         }
633                     
634         return copyObj;
635     }
636
637     /**
638      * returns a peer instance associated with this om. Since Peer classes
639      * are not to have any instance attributes, this method returns the
640      * same instance for all member of this class. The method could therefore
641      * be static, but this would prevent one from overriding the behavior.
642      */

643     public TurbinePermissionPeer getPeer()
644     {
645         return peer;
646     }
647
648     public String JavaDoc toString()
649     {
650         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
651         str.append("TurbinePermission:\n");
652         str.append("PermissionId = ")
653            .append(getPermissionId())
654            .append("\n");
655         str.append("Name = ")
656            .append(getName())
657            .append("\n");
658         return(str.toString());
659     }
660 }
661
Popular Tags