KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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

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

121     protected List JavaDoc collProducts;
122
123     /**
124      * Temporary storage of collProducts 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 initProducts()
129     {
130         if (collProducts == null)
131         {
132             collProducts = new ArrayList JavaDoc();
133         }
134     }
135
136     /**
137      * Method called to associate a Product object to this object
138      * through the Product foreign key attribute
139      *
140      * @param l Product
141      * @throws TorqueException
142      */

143     public void addProduct(Product l) throws TorqueException
144     {
145         getProducts().add(l);
146         l.setVendor((Vendor) this);
147     }
148
149     /**
150      * The criteria used to select the current contents of collProducts
151      */

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

161     public List JavaDoc getProducts() throws TorqueException
162     {
163               if (collProducts == null)
164         {
165             collProducts = getProducts(new Criteria(10));
166         }
167         return collProducts;
168           }
169
170     /**
171      * If this collection has already been initialized with
172      * an identical criteria, it returns the collection.
173      * Otherwise if this Vendor has previously
174      * been saved, it will retrieve related Products from storage.
175      * If this Vendor 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 getProducts(Criteria criteria) throws TorqueException
182     {
183               if (collProducts == null)
184         {
185             if (isNew())
186             {
187                collProducts = new ArrayList JavaDoc();
188             }
189             else
190             {
191                         criteria.add(ProductPeer.VENDOR_ID, getVendorId() );
192                         collProducts = ProductPeer.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(ProductPeer.VENDOR_ID, getVendorId());
204                             if (!lastProductsCriteria.equals(criteria))
205                 {
206                     collProducts = ProductPeer.doSelect(criteria);
207                 }
208             }
209         }
210         lastProductsCriteria = criteria;
211
212         return collProducts;
213           }
214
215     /**
216      * If this collection has already been initialized, returns
217      * the collection. Otherwise returns the results of
218      * getProducts(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 getProducts(Connection JavaDoc con) throws TorqueException
224     {
225               if (collProducts == null)
226         {
227             collProducts = getProducts(new Criteria(10), con);
228         }
229         return collProducts;
230           }
231
232     /**
233      * If this collection has already been initialized with
234      * an identical criteria, it returns the collection.
235      * Otherwise if this Vendor has previously
236      * been saved, it will retrieve related Products from storage.
237      * If this Vendor 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 getProducts(Criteria criteria, Connection JavaDoc con)
245             throws TorqueException
246     {
247               if (collProducts == null)
248         {
249             if (isNew())
250             {
251                collProducts = new ArrayList JavaDoc();
252             }
253             else
254             {
255                          criteria.add(ProductPeer.VENDOR_ID, getVendorId());
256                          collProducts = ProductPeer.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(ProductPeer.VENDOR_ID, getVendorId());
268                              if (!lastProductsCriteria.equals(criteria))
269                  {
270                      collProducts = ProductPeer.doSelect(criteria, con);
271                  }
272              }
273          }
274          lastProductsCriteria = criteria;
275
276          return collProducts;
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 Vendor is new, it will return
293      * an empty collection; or if this Vendor has previously
294      * been saved, it will retrieve related Products 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 Vendor.
299      */

300     protected List JavaDoc getProductsJoinProductCategory(Criteria criteria)
301         throws TorqueException
302     {
303                     if (collProducts == null)
304         {
305             if (isNew())
306             {
307                collProducts = new ArrayList JavaDoc();
308             }
309             else
310             {
311                               criteria.add(ProductPeer.VENDOR_ID, getVendorId());
312                               collProducts = ProductPeer.doSelectJoinProductCategory(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(ProductPeer.VENDOR_ID, getVendorId());
322                                     if (!lastProductsCriteria.equals(criteria))
323             {
324                 collProducts = ProductPeer.doSelectJoinProductCategory(criteria);
325             }
326         }
327         lastProductsCriteria = criteria;
328
329         return collProducts;
330                 }
331                   
332                     
333                     
334                                 
335                                                               
336                                         
337                     
338                     
339           
340     /**
341      * If this collection has already been initialized with
342      * an identical criteria, it returns the collection.
343      * Otherwise if this Vendor is new, it will return
344      * an empty collection; or if this Vendor has previously
345      * been saved, it will retrieve related Products from storage.
346      *
347      * This method is protected by default in order to keep the public
348      * api reasonable. You can provide public methods for those you
349      * actually need in Vendor.
350      */

351     protected List JavaDoc getProductsJoinUom(Criteria criteria)
352         throws TorqueException
353     {
354                     if (collProducts == null)
355         {
356             if (isNew())
357             {
358                collProducts = new ArrayList JavaDoc();
359             }
360             else
361             {
362                               criteria.add(ProductPeer.VENDOR_ID, getVendorId());
363                               collProducts = ProductPeer.doSelectJoinUom(criteria);
364             }
365         }
366         else
367         {
368             // the following code is to determine if a new query is
369
// called for. If the criteria is the same as the last
370
// one, just return the collection.
371

372                         criteria.add(ProductPeer.VENDOR_ID, getVendorId());
373                                     if (!lastProductsCriteria.equals(criteria))
374             {
375                 collProducts = ProductPeer.doSelectJoinUom(criteria);
376             }
377         }
378         lastProductsCriteria = criteria;
379
380         return collProducts;
381                 }
382                   
383                     
384                               
385                                 
386                                                               
387                                         
388                     
389                     
390           
391     /**
392      * If this collection has already been initialized with
393      * an identical criteria, it returns the collection.
394      * Otherwise if this Vendor is new, it will return
395      * an empty collection; or if this Vendor has previously
396      * been saved, it will retrieve related Products from storage.
397      *
398      * This method is protected by default in order to keep the public
399      * api reasonable. You can provide public methods for those you
400      * actually need in Vendor.
401      */

402     protected List JavaDoc getProductsJoinVendor(Criteria criteria)
403         throws TorqueException
404     {
405                     if (collProducts == null)
406         {
407             if (isNew())
408             {
409                collProducts = new ArrayList JavaDoc();
410             }
411             else
412             {
413                               criteria.add(ProductPeer.VENDOR_ID, getVendorId());
414                               collProducts = ProductPeer.doSelectJoinVendor(criteria);
415             }
416         }
417         else
418         {
419             // the following code is to determine if a new query is
420
// called for. If the criteria is the same as the last
421
// one, just return the collection.
422

423                         criteria.add(ProductPeer.VENDOR_ID, getVendorId());
424                                     if (!lastProductsCriteria.equals(criteria))
425             {
426                 collProducts = ProductPeer.doSelectJoinVendor(criteria);
427             }
428         }
429         lastProductsCriteria = criteria;
430
431         return collProducts;
432                 }
433                             
434
435
436           
437     private static List JavaDoc fieldNames = null;
438
439     /**
440      * Generate a list of field names.
441      *
442      * @return a list of field names
443      */

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

462     public Object JavaDoc getByName(String JavaDoc name)
463     {
464           if (name.equals("VendorId"))
465         {
466                 return new Integer JavaDoc(getVendorId());
467             }
468           if (name.equals("VendorName"))
469         {
470                 return getVendorName();
471             }
472           return null;
473     }
474     
475     /**
476      * Retrieves a field from the object by name passed in
477      * as a String. The String must be one of the static
478      * Strings defined in this Class' Peer.
479      *
480      * @param name peer name
481      * @return value
482      */

483     public Object JavaDoc getByPeerName(String JavaDoc name)
484     {
485           if (name.equals(VendorPeer.VENDOR_ID))
486         {
487                 return new Integer JavaDoc(getVendorId());
488             }
489           if (name.equals(VendorPeer.VENDOR_NAME))
490         {
491                 return getVendorName();
492             }
493           return null;
494     }
495
496     /**
497      * Retrieves a field from the object by Position as specified
498      * in the xml schema. Zero-based.
499      *
500      * @param pos position in xml schema
501      * @return value
502      */

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

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

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

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

567     public void save(Connection JavaDoc con) throws TorqueException
568     {
569           if (!alreadyInSave)
570         {
571             alreadyInSave = true;
572
573
574   
575             // If this object has been modified, then save it to the database.
576
if (isModified())
577             {
578                 if (isNew())
579                 {
580                     VendorPeer.doInsert((Vendor) this, con);
581                     setNew(false);
582                 }
583                 else
584                 {
585                     VendorPeer.doUpdate((Vendor) this, con);
586                 }
587             }
588
589                                       
590                 
591                     if (collProducts != null)
592             {
593                 for (int i = 0; i < collProducts.size(); i++)
594                 {
595                     ((Product) collProducts.get(i)).save(con);
596                 }
597             }
598                                   alreadyInSave = false;
599         }
600       }
601
602                         
603       /**
604      * Set the PrimaryKey using ObjectKey.
605      *
606      * @param key vendorId ObjectKey
607      */

608     public void setPrimaryKey(ObjectKey key)
609         throws TorqueException
610     {
611             setVendorId(((NumberKey) key).intValue());
612         }
613
614     /**
615      * Set the PrimaryKey using a String.
616      *
617      * @param key
618      */

619     public void setPrimaryKey(String JavaDoc key) throws TorqueException
620     {
621             setVendorId(Integer.parseInt(key));
622         }
623
624   
625     /**
626      * returns an id that differentiates this object from others
627      * of its class.
628      */

629     public ObjectKey getPrimaryKey()
630     {
631           return SimpleKey.keyFor(getVendorId());
632       }
633  
634     /**
635      * get an id that differentiates this object from others
636      * of its class.
637      */

638     public String JavaDoc getQueryKey()
639     {
640         if (getPrimaryKey() == null)
641         {
642             return "";
643         }
644         else
645         {
646             return getPrimaryKey().toString();
647         }
648     }
649
650     /**
651      * set an id that differentiates this object from others
652      * of its class.
653      */

654     public void setQueryKey(String JavaDoc key)
655         throws TorqueException
656     {
657         setPrimaryKey(key);
658     }
659
660     /**
661      * Makes a copy of this object.
662      * It creates a new object filling in the simple attributes.
663        * It then fills all the association collections and sets the
664      * related objects to isNew=true.
665        */

666       public Vendor copy() throws TorqueException
667     {
668         return copyInto(new Vendor());
669     }
670   
671     protected Vendor copyInto(Vendor copyObj) throws TorqueException
672     {
673           copyObj.setVendorId(vendorId);
674           copyObj.setVendorName(vendorName);
675   
676                             copyObj.setVendorId( 0);
677                   
678                                       
679                             
680         List JavaDoc v = getProducts();
681         for (int i = 0; i < v.size(); i++)
682         {
683             Product obj = (Product) v.get(i);
684             copyObj.addProduct(obj.copy());
685         }
686                             return copyObj;
687     }
688
689     /**
690      * returns a peer instance associated with this om. Since Peer classes
691      * are not to have any instance attributes, this method returns the
692      * same instance for all member of this class. The method could therefore
693      * be static, but this would prevent one from overriding the behavior.
694      */

695     public VendorPeer getPeer()
696     {
697         return peer;
698     }
699
700     public String JavaDoc toString()
701     {
702         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
703         str.append("Vendor:\n");
704         str.append("VendorId = ")
705                .append(getVendorId())
706              .append("\n");
707         str.append("VendorName = ")
708                .append(getVendorName())
709              .append("\n");
710         return(str.toString());
711     }
712 }
713
Popular Tags