KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > BaseActivitySetType


1 package org.tigris.scarab.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.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 ActivitySetType
29  */

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

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

61     public void setTypeId(Integer JavaDoc v) throws TorqueException
62     {
63     
64                   if (!ObjectUtils.equals(this.typeId, v))
65               {
66             this.typeId = v;
67             setModified(true);
68         }
69     
70           
71                                   
72         // update associated ActivitySet
73
if (collActivitySets != null)
74         {
75             for (int i = 0; i < collActivitySets.size(); i++)
76             {
77                 ((ActivitySet) collActivitySets.get(i))
78                         .setTypeId(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 collActivitySets
116      */

117     protected List JavaDoc collActivitySets;
118
119     /**
120      * Temporary storage of collActivitySets 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 initActivitySets()
125     {
126         if (collActivitySets == null)
127         {
128             collActivitySets = new ArrayList JavaDoc();
129         }
130     }
131
132             
133     /**
134      * Method called to associate a ActivitySet object to this object
135      * through the ActivitySet foreign key attribute
136      *
137      * @param l ActivitySet
138      * @throws TorqueException
139      */

140     public void addActivitySet(ActivitySet l) throws TorqueException
141     {
142         getActivitySets().add(l);
143         l.setActivitySetType((ActivitySetType)this);
144     }
145
146     /**
147      * The criteria used to select the current contents of collActivitySets
148      */

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

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

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

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

241     public List JavaDoc getActivitySets(Criteria criteria,Connection JavaDoc con) throws TorqueException
242     {
243         if (collActivitySets == null)
244         {
245             if (isNew())
246             {
247                collActivitySets = new ArrayList JavaDoc();
248             }
249             else
250             {
251                        criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() );
252                        collActivitySets = ActivitySetPeer.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(ActivitySetPeer.TYPE_ID, getTypeId() );
264                      if (!lastActivitySetsCriteria.equals(criteria))
265                  {
266                      collActivitySets = ActivitySetPeer.doSelect(criteria,con);
267                  }
268              }
269          }
270          lastActivitySetsCriteria = criteria;
271
272          return collActivitySets;
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 ActivitySetType is new, it will return
289      * an empty collection; or if this ActivitySetType has previously
290      * been saved, it will retrieve related ActivitySets 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 ActivitySetType.
295      */

296     protected List JavaDoc getActivitySetsJoinScarabUserImpl(Criteria criteria)
297         throws TorqueException
298     {
299         if (collActivitySets == null)
300         {
301             if (isNew())
302             {
303                collActivitySets = new ArrayList JavaDoc();
304             }
305             else
306             {
307                             criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() );
308                             collActivitySets = ActivitySetPeer.doSelectJoinScarabUserImpl(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

317                             criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() );
318                         if (!lastActivitySetsCriteria.equals(criteria))
319             {
320                 collActivitySets = ActivitySetPeer.doSelectJoinScarabUserImpl(criteria);
321             }
322         }
323         lastActivitySetsCriteria = criteria;
324
325         return collActivitySets;
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 ActivitySetType is new, it will return
340      * an empty collection; or if this ActivitySetType has previously
341      * been saved, it will retrieve related ActivitySets 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 ActivitySetType.
346      */

347     protected List JavaDoc getActivitySetsJoinActivitySetType(Criteria criteria)
348         throws TorqueException
349     {
350         if (collActivitySets == null)
351         {
352             if (isNew())
353             {
354                collActivitySets = new ArrayList JavaDoc();
355             }
356             else
357             {
358                             criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() );
359                             collActivitySets = ActivitySetPeer.doSelectJoinActivitySetType(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

368                             criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() );
369                         if (!lastActivitySetsCriteria.equals(criteria))
370             {
371                 collActivitySets = ActivitySetPeer.doSelectJoinActivitySetType(criteria);
372             }
373         }
374         lastActivitySetsCriteria = criteria;
375
376         return collActivitySets;
377     }
378                   
379                     
380                     
381                                 
382                                                               
383                                         
384                     
385                     
386           
387     /**
388      * If this collection has already been initialized with
389      * an identical criteria, it returns the collection.
390      * Otherwise if this ActivitySetType is new, it will return
391      * an empty collection; or if this ActivitySetType has previously
392      * been saved, it will retrieve related ActivitySets from storage.
393      *
394      * This method is protected by default in order to keep the public
395      * api reasonable. You can provide public methods for those you
396      * actually need in ActivitySetType.
397      */

398     protected List JavaDoc getActivitySetsJoinAttachment(Criteria criteria)
399         throws TorqueException
400     {
401         if (collActivitySets == null)
402         {
403             if (isNew())
404             {
405                collActivitySets = new ArrayList JavaDoc();
406             }
407             else
408             {
409                             criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() );
410                             collActivitySets = ActivitySetPeer.doSelectJoinAttachment(criteria);
411             }
412         }
413         else
414         {
415             // the following code is to determine if a new query is
416
// called for. If the criteria is the same as the last
417
// one, just return the collection.
418

419                             criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() );
420                         if (!lastActivitySetsCriteria.equals(criteria))
421             {
422                 collActivitySets = ActivitySetPeer.doSelectJoinAttachment(criteria);
423             }
424         }
425         lastActivitySetsCriteria = criteria;
426
427         return collActivitySets;
428     }
429                             
430
431
432           
433     private static List JavaDoc fieldNames = null;
434
435     /**
436      * Generate a list of field names.
437      *
438      * @return a list of field names
439      */

440     public static synchronized List JavaDoc getFieldNames()
441     {
442         if (fieldNames == null)
443         {
444             fieldNames = new ArrayList JavaDoc();
445               fieldNames.add("TypeId");
446               fieldNames.add("Name");
447               fieldNames = Collections.unmodifiableList(fieldNames);
448         }
449         return fieldNames;
450     }
451
452     /**
453      * Retrieves a field from the object by name passed in as a String.
454      *
455      * @param name field name
456      * @return value
457      */

458     public Object JavaDoc getByName(String JavaDoc name)
459     {
460           if (name.equals("TypeId"))
461         {
462                 return getTypeId();
463             }
464           if (name.equals("Name"))
465         {
466                 return getName();
467             }
468           return null;
469     }
470     
471     /**
472      * Retrieves a field from the object by name passed in
473      * as a String. The String must be one of the static
474      * Strings defined in this Class' Peer.
475      *
476      * @param name peer name
477      * @return value
478      */

479     public Object JavaDoc getByPeerName(String JavaDoc name)
480     {
481           if (name.equals(ActivitySetTypePeer.TYPE_ID))
482         {
483                 return getTypeId();
484             }
485           if (name.equals(ActivitySetTypePeer.NAME))
486         {
487                 return getName();
488             }
489           return null;
490     }
491
492     /**
493      * Retrieves a field from the object by Position as specified
494      * in the xml schema. Zero-based.
495      *
496      * @param pos position in xml schema
497      * @return value
498      */

499     public Object JavaDoc getByPosition(int pos)
500     {
501             if (pos == 0)
502         {
503                 return getTypeId();
504             }
505               if (pos == 1)
506         {
507                 return getName();
508             }
509               return null;
510     }
511      
512     /**
513      * Stores the object in the database. If the object is new,
514      * it inserts it; otherwise an update is performed.
515      *
516      * @throws Exception
517      */

518     public void save() throws Exception JavaDoc
519     {
520           save(ActivitySetTypePeer.getMapBuilder()
521                 .getDatabaseMap().getName());
522       }
523
524     /**
525      * Stores the object in the database. If the object is new,
526      * it inserts it; otherwise an update is performed.
527        * Note: this code is here because the method body is
528      * auto-generated conditionally and therefore needs to be
529      * in this file instead of in the super class, BaseObject.
530        *
531      * @param dbName
532      * @throws TorqueException
533      */

534     public void save(String JavaDoc dbName) throws TorqueException
535     {
536         Connection JavaDoc con = null;
537           try
538         {
539             con = Transaction.begin(dbName);
540             save(con);
541             Transaction.commit(con);
542         }
543         catch(TorqueException e)
544         {
545             Transaction.safeRollback(con);
546             throw e;
547         }
548       }
549
550       /** flag to prevent endless save loop, if this object is referenced
551         by another object which falls in this transaction. */

552     private boolean alreadyInSave = false;
553       /**
554      * Stores the object in the database. If the object is new,
555      * it inserts it; otherwise an update is performed. This method
556      * is meant to be used as part of a transaction, otherwise use
557      * the save() method and the connection details will be handled
558      * internally
559      *
560      * @param con
561      * @throws TorqueException
562      */

563     public void save(Connection JavaDoc con) throws TorqueException
564     {
565           if (!alreadyInSave)
566         {
567             alreadyInSave = true;
568
569
570   
571             // If this object has been modified, then save it to the database.
572
if (isModified())
573             {
574                 if (isNew())
575                 {
576                     ActivitySetTypePeer.doInsert((ActivitySetType)this, con);
577                     setNew(false);
578                 }
579                 else
580                 {
581                     ActivitySetTypePeer.doUpdate((ActivitySetType)this, con);
582                 }
583
584                       if (isCacheOnSave())
585                 {
586                     ActivitySetTypeManager.putInstance(this);
587                 }
588               }
589
590                                       
591                             if (collActivitySets != null)
592             {
593                 for (int i = 0; i < collActivitySets.size(); i++)
594                 {
595                     ((ActivitySet)collActivitySets.get(i)).save(con);
596                 }
597             }
598                           alreadyInSave = false;
599         }
600       }
601
602     /**
603      * Specify whether to cache the object after saving to the db.
604      * This method returns false
605      */

606     protected boolean isCacheOnSave()
607     {
608         return true;
609     }
610
611                         
612       /**
613      * Set the PrimaryKey using ObjectKey.
614      *
615      * @param typeId ObjectKey
616      */

617     public void setPrimaryKey(ObjectKey typeId)
618         throws TorqueException {
619             setTypeId(new Integer JavaDoc(((NumberKey)typeId).intValue()));
620         }
621
622     /**
623      * Set the PrimaryKey using a String.
624      *
625      * @param key
626      */

627     public void setPrimaryKey(String JavaDoc key) throws TorqueException
628     {
629             setTypeId(new Integer JavaDoc(key));
630         }
631
632   
633     /**
634      * returns an id that differentiates this object from others
635      * of its class.
636      */

637     public ObjectKey getPrimaryKey()
638     {
639           return SimpleKey.keyFor(getTypeId());
640       }
641  
642     /**
643      * get an id that differentiates this object from others
644      * of its class.
645      */

646     public String JavaDoc getQueryKey()
647     {
648         if (getPrimaryKey() == null)
649         {
650             return "";
651         }
652         else
653         {
654             return getPrimaryKey().toString();
655         }
656     }
657
658     /**
659      * set an id that differentiates this object from others
660      * of its class.
661      */

662     public void setQueryKey(String JavaDoc key)
663         throws TorqueException
664     {
665         setPrimaryKey(key);
666     }
667
668     /**
669      * Makes a copy of this object.
670      * It creates a new object filling in the simple attributes.
671        * It then fills all the association collections and sets the
672      * related objects to isNew=true.
673        */

674       public ActivitySetType copy() throws TorqueException
675     {
676         ActivitySetType copyObj = new ActivitySetType();
677             copyObj.setTypeId(typeId);
678           copyObj.setName(name);
679   
680                       copyObj.setTypeId((Integer JavaDoc)null);
681                   
682                                       
683                 
684         List JavaDoc v = getActivitySets();
685         for (int i = 0; i < v.size(); i++)
686         {
687             ActivitySet obj = (ActivitySet) v.get(i);
688             copyObj.addActivitySet(obj.copy());
689         }
690                             return copyObj;
691     }
692
693     /**
694      * returns a peer instance associated with this om. Since Peer classes
695      * are not to have any instance attributes, this method returns the
696      * same instance for all member of this class. The method could therefore
697      * be static, but this would prevent one from overriding the behavior.
698      */

699     public ActivitySetTypePeer getPeer()
700     {
701         return peer;
702     }
703
704     public String JavaDoc toString()
705     {
706         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
707         str.append("ActivitySetType:\n");
708         str.append("TypeId = ")
709                .append(getTypeId())
710              .append("\n");
711         str.append("Name = ")
712                .append(getName())
713              .append("\n");
714         return(str.toString());
715     }
716 }
717
Popular Tags