KickJava   Java API By Example, From Geeks To Geeks.

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


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  * This class was autogenerated by Torque on:
28  *
29  * [Wed May 04 09:10:56 CEST 2005]
30  *
31  * You should not use this class directly. It should not even be
32  * extended all references should be to ProjectCategory
33  */

34 public abstract class BaseProjectCategory extends BaseObject
35     implements org.apache.turbine.om.Retrievable
36 {
37     /** The Peer class */
38     private static final ProjectCategoryPeer peer =
39         new ProjectCategoryPeer();
40
41         
42     /** The value for the projectCatId field */
43     private int projectCatId;
44       
45     /** The value for the projectCatName field */
46     private String JavaDoc projectCatName;
47   
48     
49     /**
50      * Get the ProjectCatId
51      *
52      * @return int
53      */

54     public int getProjectCatId()
55     {
56         return projectCatId;
57     }
58
59                                               
60     /**
61      * Set the value of ProjectCatId
62      *
63      * @param v new value
64      */

65     public void setProjectCatId(int v) throws TorqueException
66     {
67     
68                   if (this.projectCatId != v)
69               {
70             this.projectCatId = v;
71             setModified(true);
72         }
73     
74           
75                                   
76                   // update associated Project
77
if (collProjects != null)
78         {
79             for (int i = 0; i < collProjects.size(); i++)
80             {
81                 ((Project) collProjects.get(i))
82                     .setProjectCatId(v);
83             }
84         }
85                                 }
86   
87     /**
88      * Get the ProjectCatName
89      *
90      * @return String
91      */

92     public String JavaDoc getProjectCatName()
93     {
94         return projectCatName;
95     }
96
97                         
98     /**
99      * Set the value of ProjectCatName
100      *
101      * @param v new value
102      */

103     public void setProjectCatName(String JavaDoc v)
104     {
105     
106                   if (!ObjectUtils.equals(this.projectCatName, v))
107               {
108             this.projectCatName = v;
109             setModified(true);
110         }
111     
112           
113               }
114   
115          
116                                 
117             
118           /**
119      * Collection to store aggregation of collProjects
120      */

121     protected List JavaDoc collProjects;
122
123     /**
124      * Temporary storage of collProjects to save a possible db hit in
125      * the event objects are add to the collection, but the
126      * complete collection is never requested.
127      */

128     protected void initProjects()
129     {
130         if (collProjects == null)
131         {
132             collProjects = new ArrayList JavaDoc();
133         }
134     }
135
136     /**
137      * Method called to associate a Project object to this object
138      * through the Project foreign key attribute
139      *
140      * @param l Project
141      * @throws TorqueException
142      */

143     public void addProject(Project l) throws TorqueException
144     {
145         getProjects().add(l);
146         l.setProjectCategory((ProjectCategory) this);
147     }
148
149     /**
150      * The criteria used to select the current contents of collProjects
151      */

152     private Criteria lastProjectsCriteria = null;
153       
154     /**
155      * If this collection has already been initialized, returns
156      * the collection. Otherwise returns the results of
157      * getProjects(new Criteria())
158      *
159      * @throws TorqueException
160      */

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

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

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

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

300     protected List JavaDoc getProjectsJoinProjectCategory(Criteria criteria)
301         throws TorqueException
302     {
303                     if (collProjects == null)
304         {
305             if (isNew())
306             {
307                collProjects = new ArrayList JavaDoc();
308             }
309             else
310             {
311                               criteria.add(ProjectPeer.PROJECT_CAT_ID, getProjectCatId());
312                               collProjects = ProjectPeer.doSelectJoinProjectCategory(criteria);
313             }
314         }
315         else
316         {
317             // the following code is to determine if a new query is
318
// called for. If the criteria is the same as the last
319
// one, just return the collection.
320

321                         criteria.add(ProjectPeer.PROJECT_CAT_ID, getProjectCatId());
322                                     if (!lastProjectsCriteria.equals(criteria))
323             {
324                 collProjects = ProjectPeer.doSelectJoinProjectCategory(criteria);
325             }
326         }
327         lastProjectsCriteria = criteria;
328
329         return collProjects;
330                 }
331                             
332
333
334           
335     private static List JavaDoc fieldNames = null;
336
337     /**
338      * Generate a list of field names.
339      *
340      * @return a list of field names
341      */

342     public static synchronized List JavaDoc getFieldNames()
343     {
344         if (fieldNames == null)
345         {
346             fieldNames = new ArrayList JavaDoc();
347               fieldNames.add("ProjectCatId");
348               fieldNames.add("ProjectCatName");
349               fieldNames = Collections.unmodifiableList(fieldNames);
350         }
351         return fieldNames;
352     }
353
354     /**
355      * Retrieves a field from the object by name passed in as a String.
356      *
357      * @param name field name
358      * @return value
359      */

360     public Object JavaDoc getByName(String JavaDoc name)
361     {
362           if (name.equals("ProjectCatId"))
363         {
364                 return new Integer JavaDoc(getProjectCatId());
365             }
366           if (name.equals("ProjectCatName"))
367         {
368                 return getProjectCatName();
369             }
370           return null;
371     }
372     
373     /**
374      * Retrieves a field from the object by name passed in
375      * as a String. The String must be one of the static
376      * Strings defined in this Class' Peer.
377      *
378      * @param name peer name
379      * @return value
380      */

381     public Object JavaDoc getByPeerName(String JavaDoc name)
382     {
383           if (name.equals(ProjectCategoryPeer.PROJECT_CAT_ID))
384         {
385                 return new Integer JavaDoc(getProjectCatId());
386             }
387           if (name.equals(ProjectCategoryPeer.PROJECT_CAT_NAME))
388         {
389                 return getProjectCatName();
390             }
391           return null;
392     }
393
394     /**
395      * Retrieves a field from the object by Position as specified
396      * in the xml schema. Zero-based.
397      *
398      * @param pos position in xml schema
399      * @return value
400      */

401     public Object JavaDoc getByPosition(int pos)
402     {
403             if (pos == 0)
404         {
405                 return new Integer JavaDoc(getProjectCatId());
406             }
407               if (pos == 1)
408         {
409                 return getProjectCatName();
410             }
411               return null;
412     }
413      
414     /**
415      * Stores the object in the database. If the object is new,
416      * it inserts it; otherwise an update is performed.
417      *
418      * @throws Exception
419      */

420     public void save() throws Exception JavaDoc
421     {
422           save(ProjectCategoryPeer.getMapBuilder()
423                 .getDatabaseMap().getName());
424       }
425
426     /**
427      * Stores the object in the database. If the object is new,
428      * it inserts it; otherwise an update is performed.
429        * Note: this code is here because the method body is
430      * auto-generated conditionally and therefore needs to be
431      * in this file instead of in the super class, BaseObject.
432        *
433      * @param dbName
434      * @throws TorqueException
435      */

436     public void save(String JavaDoc dbName) throws TorqueException
437     {
438         Connection JavaDoc con = null;
439           try
440         {
441             con = Transaction.begin(dbName);
442             save(con);
443             Transaction.commit(con);
444         }
445         catch(TorqueException e)
446         {
447             Transaction.safeRollback(con);
448             throw e;
449         }
450       }
451
452       /** flag to prevent endless save loop, if this object is referenced
453         by another object which falls in this transaction. */

454     private boolean alreadyInSave = false;
455       /**
456      * Stores the object in the database. If the object is new,
457      * it inserts it; otherwise an update is performed. This method
458      * is meant to be used as part of a transaction, otherwise use
459      * the save() method and the connection details will be handled
460      * internally
461      *
462      * @param con
463      * @throws TorqueException
464      */

465     public void save(Connection JavaDoc con) throws TorqueException
466     {
467           if (!alreadyInSave)
468         {
469             alreadyInSave = true;
470
471
472   
473             // If this object has been modified, then save it to the database.
474
if (isModified())
475             {
476                 if (isNew())
477                 {
478                     ProjectCategoryPeer.doInsert((ProjectCategory) this, con);
479                     setNew(false);
480                 }
481                 else
482                 {
483                     ProjectCategoryPeer.doUpdate((ProjectCategory) this, con);
484                 }
485             }
486
487                                       
488                 
489                     if (collProjects != null)
490             {
491                 for (int i = 0; i < collProjects.size(); i++)
492                 {
493                     ((Project) collProjects.get(i)).save(con);
494                 }
495             }
496                                   alreadyInSave = false;
497         }
498       }
499
500                         
501       /**
502      * Set the PrimaryKey using ObjectKey.
503      *
504      * @param key projectCatId ObjectKey
505      */

506     public void setPrimaryKey(ObjectKey key)
507         throws TorqueException
508     {
509             setProjectCatId(((NumberKey) key).intValue());
510         }
511
512     /**
513      * Set the PrimaryKey using a String.
514      *
515      * @param key
516      */

517     public void setPrimaryKey(String JavaDoc key) throws TorqueException
518     {
519             setProjectCatId(Integer.parseInt(key));
520         }
521
522   
523     /**
524      * returns an id that differentiates this object from others
525      * of its class.
526      */

527     public ObjectKey getPrimaryKey()
528     {
529           return SimpleKey.keyFor(getProjectCatId());
530       }
531  
532     /**
533      * get an id that differentiates this object from others
534      * of its class.
535      */

536     public String JavaDoc getQueryKey()
537     {
538         if (getPrimaryKey() == null)
539         {
540             return "";
541         }
542         else
543         {
544             return getPrimaryKey().toString();
545         }
546     }
547
548     /**
549      * set an id that differentiates this object from others
550      * of its class.
551      */

552     public void setQueryKey(String JavaDoc key)
553         throws TorqueException
554     {
555         setPrimaryKey(key);
556     }
557
558     /**
559      * Makes a copy of this object.
560      * It creates a new object filling in the simple attributes.
561        * It then fills all the association collections and sets the
562      * related objects to isNew=true.
563        */

564       public ProjectCategory copy() throws TorqueException
565     {
566         return copyInto(new ProjectCategory());
567     }
568   
569     protected ProjectCategory copyInto(ProjectCategory copyObj) throws TorqueException
570     {
571           copyObj.setProjectCatId(projectCatId);
572           copyObj.setProjectCatName(projectCatName);
573   
574                             copyObj.setProjectCatId( 0);
575                   
576                                       
577                             
578         List JavaDoc v = getProjects();
579         for (int i = 0; i < v.size(); i++)
580         {
581             Project obj = (Project) v.get(i);
582             copyObj.addProject(obj.copy());
583         }
584                             return copyObj;
585     }
586
587     /**
588      * returns a peer instance associated with this om. Since Peer classes
589      * are not to have any instance attributes, this method returns the
590      * same instance for all member of this class. The method could therefore
591      * be static, but this would prevent one from overriding the behavior.
592      */

593     public ProjectCategoryPeer getPeer()
594     {
595         return peer;
596     }
597
598     public String JavaDoc toString()
599     {
600         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
601         str.append("ProjectCategory:\n");
602         str.append("ProjectCatId = ")
603                .append(getProjectCatId())
604              .append("\n");
605         str.append("ProjectCatName = ")
606                .append(getProjectCatName())
607              .append("\n");
608         return(str.toString());
609     }
610 }
611
Popular Tags