KickJava   Java API By Example, From Geeks To Geeks.

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


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 Uom
33  */

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

57     public int getUomId()
58     {
59         return uomId;
60     }
61
62                                               
63     /**
64      * Set the value of UomId
65      *
66      * @param v new value
67      */

68     public void setUomId(int v) throws TorqueException
69     {
70     
71                   if (this.uomId != v)
72               {
73             this.uomId = v;
74             setModified(true);
75         }
76     
77           
78                                   
79                   // update associated Product
80
if (collProducts != null)
81         {
82             for (int i = 0; i < collProducts.size(); i++)
83             {
84                 ((Product) collProducts.get(i))
85                     .setUomId(v);
86             }
87         }
88                                 }
89   
90     /**
91      * Get the UomName
92      *
93      * @return String
94      */

95     public String JavaDoc getUomName()
96     {
97         return uomName;
98     }
99
100                         
101     /**
102      * Set the value of UomName
103      *
104      * @param v new value
105      */

106     public void setUomName(String JavaDoc v)
107     {
108     
109                   if (!ObjectUtils.equals(this.uomName, v))
110               {
111             this.uomName = v;
112             setModified(true);
113         }
114     
115           
116               }
117   
118     /**
119      * Get the UomCode
120      *
121      * @return String
122      */

123     public String JavaDoc getUomCode()
124     {
125         return uomCode;
126     }
127
128                         
129     /**
130      * Set the value of UomCode
131      *
132      * @param v new value
133      */

134     public void setUomCode(String JavaDoc v)
135     {
136     
137                   if (!ObjectUtils.equals(this.uomCode, v))
138               {
139             this.uomCode = v;
140             setModified(true);
141         }
142     
143           
144               }
145   
146          
147                                 
148             
149           /**
150      * Collection to store aggregation of collProducts
151      */

152     protected List JavaDoc collProducts;
153
154     /**
155      * Temporary storage of collProducts to save a possible db hit in
156      * the event objects are add to the collection, but the
157      * complete collection is never requested.
158      */

159     protected void initProducts()
160     {
161         if (collProducts == null)
162         {
163             collProducts = new ArrayList JavaDoc();
164         }
165     }
166
167     /**
168      * Method called to associate a Product object to this object
169      * through the Product foreign key attribute
170      *
171      * @param l Product
172      * @throws TorqueException
173      */

174     public void addProduct(Product l) throws TorqueException
175     {
176         getProducts().add(l);
177         l.setUom((Uom) this);
178     }
179
180     /**
181      * The criteria used to select the current contents of collProducts
182      */

183     private Criteria lastProductsCriteria = null;
184       
185     /**
186      * If this collection has already been initialized, returns
187      * the collection. Otherwise returns the results of
188      * getProducts(new Criteria())
189      *
190      * @throws TorqueException
191      */

192     public List JavaDoc getProducts() throws TorqueException
193     {
194               if (collProducts == null)
195         {
196             collProducts = getProducts(new Criteria(10));
197         }
198         return collProducts;
199           }
200
201     /**
202      * If this collection has already been initialized with
203      * an identical criteria, it returns the collection.
204      * Otherwise if this Uom has previously
205      * been saved, it will retrieve related Products from storage.
206      * If this Uom is new, it will return
207      * an empty collection or the current collection, the criteria
208      * is ignored on a new object.
209      *
210      * @throws TorqueException
211      */

212     public List JavaDoc getProducts(Criteria criteria) throws TorqueException
213     {
214               if (collProducts == null)
215         {
216             if (isNew())
217             {
218                collProducts = new ArrayList JavaDoc();
219             }
220             else
221             {
222                         criteria.add(ProductPeer.UOM_ID, getUomId() );
223                         collProducts = ProductPeer.doSelect(criteria);
224             }
225         }
226         else
227         {
228             // criteria has no effect for a new object
229
if (!isNew())
230             {
231                 // the following code is to determine if a new query is
232
// called for. If the criteria is the same as the last
233
// one, just return the collection.
234
criteria.add(ProductPeer.UOM_ID, getUomId());
235                             if (!lastProductsCriteria.equals(criteria))
236                 {
237                     collProducts = ProductPeer.doSelect(criteria);
238                 }
239             }
240         }
241         lastProductsCriteria = criteria;
242
243         return collProducts;
244           }
245
246     /**
247      * If this collection has already been initialized, returns
248      * the collection. Otherwise returns the results of
249      * getProducts(new Criteria(),Connection)
250      * This method takes in the Connection also as input so that
251      * referenced objects can also be obtained using a Connection
252      * that is taken as input
253      */

254     public List JavaDoc getProducts(Connection JavaDoc con) throws TorqueException
255     {
256               if (collProducts == null)
257         {
258             collProducts = getProducts(new Criteria(10), con);
259         }
260         return collProducts;
261           }
262
263     /**
264      * If this collection has already been initialized with
265      * an identical criteria, it returns the collection.
266      * Otherwise if this Uom has previously
267      * been saved, it will retrieve related Products from storage.
268      * If this Uom is new, it will return
269      * an empty collection or the current collection, the criteria
270      * is ignored on a new object.
271      * This method takes in the Connection also as input so that
272      * referenced objects can also be obtained using a Connection
273      * that is taken as input
274      */

275     public List JavaDoc getProducts(Criteria criteria, Connection JavaDoc con)
276             throws TorqueException
277     {
278               if (collProducts == null)
279         {
280             if (isNew())
281             {
282                collProducts = new ArrayList JavaDoc();
283             }
284             else
285             {
286                          criteria.add(ProductPeer.UOM_ID, getUomId());
287                          collProducts = ProductPeer.doSelect(criteria, con);
288              }
289          }
290          else
291          {
292              // criteria has no effect for a new object
293
if (!isNew())
294              {
295                  // the following code is to determine if a new query is
296
// called for. If the criteria is the same as the last
297
// one, just return the collection.
298
criteria.add(ProductPeer.UOM_ID, getUomId());
299                              if (!lastProductsCriteria.equals(criteria))
300                  {
301                      collProducts = ProductPeer.doSelect(criteria, con);
302                  }
303              }
304          }
305          lastProductsCriteria = criteria;
306
307          return collProducts;
308            }
309
310                               
311               
312                     
313                     
314                                 
315                                                               
316                                         
317                     
318                     
319           
320     /**
321      * If this collection has already been initialized with
322      * an identical criteria, it returns the collection.
323      * Otherwise if this Uom is new, it will return
324      * an empty collection; or if this Uom has previously
325      * been saved, it will retrieve related Products from storage.
326      *
327      * This method is protected by default in order to keep the public
328      * api reasonable. You can provide public methods for those you
329      * actually need in Uom.
330      */

331     protected List JavaDoc getProductsJoinProductCategory(Criteria criteria)
332         throws TorqueException
333     {
334                     if (collProducts == null)
335         {
336             if (isNew())
337             {
338                collProducts = new ArrayList JavaDoc();
339             }
340             else
341             {
342                               criteria.add(ProductPeer.UOM_ID, getUomId());
343                               collProducts = ProductPeer.doSelectJoinProductCategory(criteria);
344             }
345         }
346         else
347         {
348             // the following code is to determine if a new query is
349
// called for. If the criteria is the same as the last
350
// one, just return the collection.
351

352                         criteria.add(ProductPeer.UOM_ID, getUomId());
353                                     if (!lastProductsCriteria.equals(criteria))
354             {
355                 collProducts = ProductPeer.doSelectJoinProductCategory(criteria);
356             }
357         }
358         lastProductsCriteria = criteria;
359
360         return collProducts;
361                 }
362                   
363                     
364                               
365                                 
366                                                               
367                                         
368                     
369                     
370           
371     /**
372      * If this collection has already been initialized with
373      * an identical criteria, it returns the collection.
374      * Otherwise if this Uom is new, it will return
375      * an empty collection; or if this Uom has previously
376      * been saved, it will retrieve related Products from storage.
377      *
378      * This method is protected by default in order to keep the public
379      * api reasonable. You can provide public methods for those you
380      * actually need in Uom.
381      */

382     protected List JavaDoc getProductsJoinUom(Criteria criteria)
383         throws TorqueException
384     {
385                     if (collProducts == null)
386         {
387             if (isNew())
388             {
389                collProducts = new ArrayList JavaDoc();
390             }
391             else
392             {
393                               criteria.add(ProductPeer.UOM_ID, getUomId());
394                               collProducts = ProductPeer.doSelectJoinUom(criteria);
395             }
396         }
397         else
398         {
399             // the following code is to determine if a new query is
400
// called for. If the criteria is the same as the last
401
// one, just return the collection.
402

403                         criteria.add(ProductPeer.UOM_ID, getUomId());
404                                     if (!lastProductsCriteria.equals(criteria))
405             {
406                 collProducts = ProductPeer.doSelectJoinUom(criteria);
407             }
408         }
409         lastProductsCriteria = criteria;
410
411         return collProducts;
412                 }
413                   
414                     
415                     
416                                 
417                                                               
418                                         
419                     
420                     
421           
422     /**
423      * If this collection has already been initialized with
424      * an identical criteria, it returns the collection.
425      * Otherwise if this Uom is new, it will return
426      * an empty collection; or if this Uom has previously
427      * been saved, it will retrieve related Products from storage.
428      *
429      * This method is protected by default in order to keep the public
430      * api reasonable. You can provide public methods for those you
431      * actually need in Uom.
432      */

433     protected List JavaDoc getProductsJoinVendor(Criteria criteria)
434         throws TorqueException
435     {
436                     if (collProducts == null)
437         {
438             if (isNew())
439             {
440                collProducts = new ArrayList JavaDoc();
441             }
442             else
443             {
444                               criteria.add(ProductPeer.UOM_ID, getUomId());
445                               collProducts = ProductPeer.doSelectJoinVendor(criteria);
446             }
447         }
448         else
449         {
450             // the following code is to determine if a new query is
451
// called for. If the criteria is the same as the last
452
// one, just return the collection.
453

454                         criteria.add(ProductPeer.UOM_ID, getUomId());
455                                     if (!lastProductsCriteria.equals(criteria))
456             {
457                 collProducts = ProductPeer.doSelectJoinVendor(criteria);
458             }
459         }
460         lastProductsCriteria = criteria;
461
462         return collProducts;
463                 }
464                             
465
466
467           
468     private static List JavaDoc fieldNames = null;
469
470     /**
471      * Generate a list of field names.
472      *
473      * @return a list of field names
474      */

475     public static synchronized List JavaDoc getFieldNames()
476     {
477         if (fieldNames == null)
478         {
479             fieldNames = new ArrayList JavaDoc();
480               fieldNames.add("UomId");
481               fieldNames.add("UomName");
482               fieldNames.add("UomCode");
483               fieldNames = Collections.unmodifiableList(fieldNames);
484         }
485         return fieldNames;
486     }
487
488     /**
489      * Retrieves a field from the object by name passed in as a String.
490      *
491      * @param name field name
492      * @return value
493      */

494     public Object JavaDoc getByName(String JavaDoc name)
495     {
496           if (name.equals("UomId"))
497         {
498                 return new Integer JavaDoc(getUomId());
499             }
500           if (name.equals("UomName"))
501         {
502                 return getUomName();
503             }
504           if (name.equals("UomCode"))
505         {
506                 return getUomCode();
507             }
508           return null;
509     }
510     
511     /**
512      * Retrieves a field from the object by name passed in
513      * as a String. The String must be one of the static
514      * Strings defined in this Class' Peer.
515      *
516      * @param name peer name
517      * @return value
518      */

519     public Object JavaDoc getByPeerName(String JavaDoc name)
520     {
521           if (name.equals(UomPeer.UOM_ID))
522         {
523                 return new Integer JavaDoc(getUomId());
524             }
525           if (name.equals(UomPeer.UOM_NAME))
526         {
527                 return getUomName();
528             }
529           if (name.equals(UomPeer.UOM_CODE))
530         {
531                 return getUomCode();
532             }
533           return null;
534     }
535
536     /**
537      * Retrieves a field from the object by Position as specified
538      * in the xml schema. Zero-based.
539      *
540      * @param pos position in xml schema
541      * @return value
542      */

543     public Object JavaDoc getByPosition(int pos)
544     {
545             if (pos == 0)
546         {
547                 return new Integer JavaDoc(getUomId());
548             }
549               if (pos == 1)
550         {
551                 return getUomName();
552             }
553               if (pos == 2)
554         {
555                 return getUomCode();
556             }
557               return null;
558     }
559      
560     /**
561      * Stores the object in the database. If the object is new,
562      * it inserts it; otherwise an update is performed.
563      *
564      * @throws Exception
565      */

566     public void save() throws Exception JavaDoc
567     {
568           save(UomPeer.getMapBuilder()
569                 .getDatabaseMap().getName());
570       }
571
572     /**
573      * Stores the object in the database. If the object is new,
574      * it inserts it; otherwise an update is performed.
575        * Note: this code is here because the method body is
576      * auto-generated conditionally and therefore needs to be
577      * in this file instead of in the super class, BaseObject.
578        *
579      * @param dbName
580      * @throws TorqueException
581      */

582     public void save(String JavaDoc dbName) throws TorqueException
583     {
584         Connection JavaDoc con = null;
585           try
586         {
587             con = Transaction.begin(dbName);
588             save(con);
589             Transaction.commit(con);
590         }
591         catch(TorqueException e)
592         {
593             Transaction.safeRollback(con);
594             throw e;
595         }
596       }
597
598       /** flag to prevent endless save loop, if this object is referenced
599         by another object which falls in this transaction. */

600     private boolean alreadyInSave = false;
601       /**
602      * Stores the object in the database. If the object is new,
603      * it inserts it; otherwise an update is performed. This method
604      * is meant to be used as part of a transaction, otherwise use
605      * the save() method and the connection details will be handled
606      * internally
607      *
608      * @param con
609      * @throws TorqueException
610      */

611     public void save(Connection JavaDoc con) throws TorqueException
612     {
613           if (!alreadyInSave)
614         {
615             alreadyInSave = true;
616
617
618   
619             // If this object has been modified, then save it to the database.
620
if (isModified())
621             {
622                 if (isNew())
623                 {
624                     UomPeer.doInsert((Uom) this, con);
625                     setNew(false);
626                 }
627                 else
628                 {
629                     UomPeer.doUpdate((Uom) this, con);
630                 }
631             }
632
633                                       
634                 
635                     if (collProducts != null)
636             {
637                 for (int i = 0; i < collProducts.size(); i++)
638                 {
639                     ((Product) collProducts.get(i)).save(con);
640                 }
641             }
642                                   alreadyInSave = false;
643         }
644       }
645
646                         
647       /**
648      * Set the PrimaryKey using ObjectKey.
649      *
650      * @param key uomId ObjectKey
651      */

652     public void setPrimaryKey(ObjectKey key)
653         throws TorqueException
654     {
655             setUomId(((NumberKey) key).intValue());
656         }
657
658     /**
659      * Set the PrimaryKey using a String.
660      *
661      * @param key
662      */

663     public void setPrimaryKey(String JavaDoc key) throws TorqueException
664     {
665             setUomId(Integer.parseInt(key));
666         }
667
668   
669     /**
670      * returns an id that differentiates this object from others
671      * of its class.
672      */

673     public ObjectKey getPrimaryKey()
674     {
675           return SimpleKey.keyFor(getUomId());
676       }
677  
678     /**
679      * get an id that differentiates this object from others
680      * of its class.
681      */

682     public String JavaDoc getQueryKey()
683     {
684         if (getPrimaryKey() == null)
685         {
686             return "";
687         }
688         else
689         {
690             return getPrimaryKey().toString();
691         }
692     }
693
694     /**
695      * set an id that differentiates this object from others
696      * of its class.
697      */

698     public void setQueryKey(String JavaDoc key)
699         throws TorqueException
700     {
701         setPrimaryKey(key);
702     }
703
704     /**
705      * Makes a copy of this object.
706      * It creates a new object filling in the simple attributes.
707        * It then fills all the association collections and sets the
708      * related objects to isNew=true.
709        */

710       public Uom copy() throws TorqueException
711     {
712         return copyInto(new Uom());
713     }
714   
715     protected Uom copyInto(Uom copyObj) throws TorqueException
716     {
717           copyObj.setUomId(uomId);
718           copyObj.setUomName(uomName);
719           copyObj.setUomCode(uomCode);
720   
721                             copyObj.setUomId( 0);
722                         
723                                       
724                             
725         List JavaDoc v = getProducts();
726         for (int i = 0; i < v.size(); i++)
727         {
728             Product obj = (Product) v.get(i);
729             copyObj.addProduct(obj.copy());
730         }
731                             return copyObj;
732     }
733
734     /**
735      * returns a peer instance associated with this om. Since Peer classes
736      * are not to have any instance attributes, this method returns the
737      * same instance for all member of this class. The method could therefore
738      * be static, but this would prevent one from overriding the behavior.
739      */

740     public UomPeer getPeer()
741     {
742         return peer;
743     }
744
745     public String JavaDoc toString()
746     {
747         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
748         str.append("Uom:\n");
749         str.append("UomId = ")
750                .append(getUomId())
751              .append("\n");
752         str.append("UomName = ")
753                .append(getUomName())
754              .append("\n");
755         str.append("UomCode = ")
756                .append(getUomCode())
757              .append("\n");
758         return(str.toString());
759     }
760 }
761
Popular Tags