KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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

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

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

143     public void addCustomer(Customer l) throws TorqueException
144     {
145         getCustomers().add(l);
146         l.setRegion((Region) this);
147     }
148
149     /**
150      * The criteria used to select the current contents of collCustomers
151      */

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

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

300     protected List JavaDoc getCustomersJoinCustomerCategory(Criteria criteria)
301         throws TorqueException
302     {
303                     if (collCustomers == null)
304         {
305             if (isNew())
306             {
307                collCustomers = new ArrayList JavaDoc();
308             }
309             else
310             {
311                               criteria.add(CustomerPeer.REGION_ID, getRegionId());
312                               collCustomers = CustomerPeer.doSelectJoinCustomerCategory(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(CustomerPeer.REGION_ID, getRegionId());
322                                     if (!lastCustomersCriteria.equals(criteria))
323             {
324                 collCustomers = CustomerPeer.doSelectJoinCustomerCategory(criteria);
325             }
326         }
327         lastCustomersCriteria = criteria;
328
329         return collCustomers;
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 Region is new, it will return
344      * an empty collection; or if this Region has previously
345      * been saved, it will retrieve related Customers 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 Region.
350      */

351     protected List JavaDoc getCustomersJoinCountry(Criteria criteria)
352         throws TorqueException
353     {
354                     if (collCustomers == null)
355         {
356             if (isNew())
357             {
358                collCustomers = new ArrayList JavaDoc();
359             }
360             else
361             {
362                               criteria.add(CustomerPeer.REGION_ID, getRegionId());
363                               collCustomers = CustomerPeer.doSelectJoinCountry(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(CustomerPeer.REGION_ID, getRegionId());
373                                     if (!lastCustomersCriteria.equals(criteria))
374             {
375                 collCustomers = CustomerPeer.doSelectJoinCountry(criteria);
376             }
377         }
378         lastCustomersCriteria = criteria;
379
380         return collCustomers;
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 Region is new, it will return
395      * an empty collection; or if this Region has previously
396      * been saved, it will retrieve related Customers 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 Region.
401      */

402     protected List JavaDoc getCustomersJoinRegion(Criteria criteria)
403         throws TorqueException
404     {
405                     if (collCustomers == null)
406         {
407             if (isNew())
408             {
409                collCustomers = new ArrayList JavaDoc();
410             }
411             else
412             {
413                               criteria.add(CustomerPeer.REGION_ID, getRegionId());
414                               collCustomers = CustomerPeer.doSelectJoinRegion(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(CustomerPeer.REGION_ID, getRegionId());
424                                     if (!lastCustomersCriteria.equals(criteria))
425             {
426                 collCustomers = CustomerPeer.doSelectJoinRegion(criteria);
427             }
428         }
429         lastCustomersCriteria = criteria;
430
431         return collCustomers;
432                 }
433                   
434                     
435                     
436                                 
437                                                               
438                                         
439                     
440                     
441           
442     /**
443      * If this collection has already been initialized with
444      * an identical criteria, it returns the collection.
445      * Otherwise if this Region is new, it will return
446      * an empty collection; or if this Region has previously
447      * been saved, it will retrieve related Customers from storage.
448      *
449      * This method is protected by default in order to keep the public
450      * api reasonable. You can provide public methods for those you
451      * actually need in Region.
452      */

453     protected List JavaDoc getCustomersJoinLanguage(Criteria criteria)
454         throws TorqueException
455     {
456                     if (collCustomers == null)
457         {
458             if (isNew())
459             {
460                collCustomers = new ArrayList JavaDoc();
461             }
462             else
463             {
464                               criteria.add(CustomerPeer.REGION_ID, getRegionId());
465                               collCustomers = CustomerPeer.doSelectJoinLanguage(criteria);
466             }
467         }
468         else
469         {
470             // the following code is to determine if a new query is
471
// called for. If the criteria is the same as the last
472
// one, just return the collection.
473

474                         criteria.add(CustomerPeer.REGION_ID, getRegionId());
475                                     if (!lastCustomersCriteria.equals(criteria))
476             {
477                 collCustomers = CustomerPeer.doSelectJoinLanguage(criteria);
478             }
479         }
480         lastCustomersCriteria = criteria;
481
482         return collCustomers;
483                 }
484                   
485                     
486                     
487                                 
488                                                               
489                                         
490                     
491                     
492           
493     /**
494      * If this collection has already been initialized with
495      * an identical criteria, it returns the collection.
496      * Otherwise if this Region is new, it will return
497      * an empty collection; or if this Region has previously
498      * been saved, it will retrieve related Customers from storage.
499      *
500      * This method is protected by default in order to keep the public
501      * api reasonable. You can provide public methods for those you
502      * actually need in Region.
503      */

504     protected List JavaDoc getCustomersJoinEducationCategory(Criteria criteria)
505         throws TorqueException
506     {
507                     if (collCustomers == null)
508         {
509             if (isNew())
510             {
511                collCustomers = new ArrayList JavaDoc();
512             }
513             else
514             {
515                               criteria.add(CustomerPeer.REGION_ID, getRegionId());
516                               collCustomers = CustomerPeer.doSelectJoinEducationCategory(criteria);
517             }
518         }
519         else
520         {
521             // the following code is to determine if a new query is
522
// called for. If the criteria is the same as the last
523
// one, just return the collection.
524

525                         criteria.add(CustomerPeer.REGION_ID, getRegionId());
526                                     if (!lastCustomersCriteria.equals(criteria))
527             {
528                 collCustomers = CustomerPeer.doSelectJoinEducationCategory(criteria);
529             }
530         }
531         lastCustomersCriteria = criteria;
532
533         return collCustomers;
534                 }
535                   
536                     
537                     
538                                 
539                                                               
540                                         
541                     
542                     
543           
544     /**
545      * If this collection has already been initialized with
546      * an identical criteria, it returns the collection.
547      * Otherwise if this Region is new, it will return
548      * an empty collection; or if this Region has previously
549      * been saved, it will retrieve related Customers from storage.
550      *
551      * This method is protected by default in order to keep the public
552      * api reasonable. You can provide public methods for those you
553      * actually need in Region.
554      */

555     protected List JavaDoc getCustomersJoinHouseholdCategory(Criteria criteria)
556         throws TorqueException
557     {
558                     if (collCustomers == null)
559         {
560             if (isNew())
561             {
562                collCustomers = new ArrayList JavaDoc();
563             }
564             else
565             {
566                               criteria.add(CustomerPeer.REGION_ID, getRegionId());
567                               collCustomers = CustomerPeer.doSelectJoinHouseholdCategory(criteria);
568             }
569         }
570         else
571         {
572             // the following code is to determine if a new query is
573
// called for. If the criteria is the same as the last
574
// one, just return the collection.
575

576                         criteria.add(CustomerPeer.REGION_ID, getRegionId());
577                                     if (!lastCustomersCriteria.equals(criteria))
578             {
579                 collCustomers = CustomerPeer.doSelectJoinHouseholdCategory(criteria);
580             }
581         }
582         lastCustomersCriteria = criteria;
583
584         return collCustomers;
585                 }
586                             
587
588
589           
590     private static List JavaDoc fieldNames = null;
591
592     /**
593      * Generate a list of field names.
594      *
595      * @return a list of field names
596      */

597     public static synchronized List JavaDoc getFieldNames()
598     {
599         if (fieldNames == null)
600         {
601             fieldNames = new ArrayList JavaDoc();
602               fieldNames.add("RegionId");
603               fieldNames.add("RegionName");
604               fieldNames = Collections.unmodifiableList(fieldNames);
605         }
606         return fieldNames;
607     }
608
609     /**
610      * Retrieves a field from the object by name passed in as a String.
611      *
612      * @param name field name
613      * @return value
614      */

615     public Object JavaDoc getByName(String JavaDoc name)
616     {
617           if (name.equals("RegionId"))
618         {
619                 return new Integer JavaDoc(getRegionId());
620             }
621           if (name.equals("RegionName"))
622         {
623                 return getRegionName();
624             }
625           return null;
626     }
627     
628     /**
629      * Retrieves a field from the object by name passed in
630      * as a String. The String must be one of the static
631      * Strings defined in this Class' Peer.
632      *
633      * @param name peer name
634      * @return value
635      */

636     public Object JavaDoc getByPeerName(String JavaDoc name)
637     {
638           if (name.equals(RegionPeer.REGION_ID))
639         {
640                 return new Integer JavaDoc(getRegionId());
641             }
642           if (name.equals(RegionPeer.REGION_NAME))
643         {
644                 return getRegionName();
645             }
646           return null;
647     }
648
649     /**
650      * Retrieves a field from the object by Position as specified
651      * in the xml schema. Zero-based.
652      *
653      * @param pos position in xml schema
654      * @return value
655      */

656     public Object JavaDoc getByPosition(int pos)
657     {
658             if (pos == 0)
659         {
660                 return new Integer JavaDoc(getRegionId());
661             }
662               if (pos == 1)
663         {
664                 return getRegionName();
665             }
666               return null;
667     }
668      
669     /**
670      * Stores the object in the database. If the object is new,
671      * it inserts it; otherwise an update is performed.
672      *
673      * @throws Exception
674      */

675     public void save() throws Exception JavaDoc
676     {
677           save(RegionPeer.getMapBuilder()
678                 .getDatabaseMap().getName());
679       }
680
681     /**
682      * Stores the object in the database. If the object is new,
683      * it inserts it; otherwise an update is performed.
684        * Note: this code is here because the method body is
685      * auto-generated conditionally and therefore needs to be
686      * in this file instead of in the super class, BaseObject.
687        *
688      * @param dbName
689      * @throws TorqueException
690      */

691     public void save(String JavaDoc dbName) throws TorqueException
692     {
693         Connection JavaDoc con = null;
694           try
695         {
696             con = Transaction.begin(dbName);
697             save(con);
698             Transaction.commit(con);
699         }
700         catch(TorqueException e)
701         {
702             Transaction.safeRollback(con);
703             throw e;
704         }
705       }
706
707       /** flag to prevent endless save loop, if this object is referenced
708         by another object which falls in this transaction. */

709     private boolean alreadyInSave = false;
710       /**
711      * Stores the object in the database. If the object is new,
712      * it inserts it; otherwise an update is performed. This method
713      * is meant to be used as part of a transaction, otherwise use
714      * the save() method and the connection details will be handled
715      * internally
716      *
717      * @param con
718      * @throws TorqueException
719      */

720     public void save(Connection JavaDoc con) throws TorqueException
721     {
722           if (!alreadyInSave)
723         {
724             alreadyInSave = true;
725
726
727   
728             // If this object has been modified, then save it to the database.
729
if (isModified())
730             {
731                 if (isNew())
732                 {
733                     RegionPeer.doInsert((Region) this, con);
734                     setNew(false);
735                 }
736                 else
737                 {
738                     RegionPeer.doUpdate((Region) this, con);
739                 }
740             }
741
742                                       
743                 
744                     if (collCustomers != null)
745             {
746                 for (int i = 0; i < collCustomers.size(); i++)
747                 {
748                     ((Customer) collCustomers.get(i)).save(con);
749                 }
750             }
751                                   alreadyInSave = false;
752         }
753       }
754
755                         
756       /**
757      * Set the PrimaryKey using ObjectKey.
758      *
759      * @param key regionId ObjectKey
760      */

761     public void setPrimaryKey(ObjectKey key)
762         throws TorqueException
763     {
764             setRegionId(((NumberKey) key).intValue());
765         }
766
767     /**
768      * Set the PrimaryKey using a String.
769      *
770      * @param key
771      */

772     public void setPrimaryKey(String JavaDoc key) throws TorqueException
773     {
774             setRegionId(Integer.parseInt(key));
775         }
776
777   
778     /**
779      * returns an id that differentiates this object from others
780      * of its class.
781      */

782     public ObjectKey getPrimaryKey()
783     {
784           return SimpleKey.keyFor(getRegionId());
785       }
786  
787     /**
788      * get an id that differentiates this object from others
789      * of its class.
790      */

791     public String JavaDoc getQueryKey()
792     {
793         if (getPrimaryKey() == null)
794         {
795             return "";
796         }
797         else
798         {
799             return getPrimaryKey().toString();
800         }
801     }
802
803     /**
804      * set an id that differentiates this object from others
805      * of its class.
806      */

807     public void setQueryKey(String JavaDoc key)
808         throws TorqueException
809     {
810         setPrimaryKey(key);
811     }
812
813     /**
814      * Makes a copy of this object.
815      * It creates a new object filling in the simple attributes.
816        * It then fills all the association collections and sets the
817      * related objects to isNew=true.
818        */

819       public Region copy() throws TorqueException
820     {
821         return copyInto(new Region());
822     }
823   
824     protected Region copyInto(Region copyObj) throws TorqueException
825     {
826           copyObj.setRegionId(regionId);
827           copyObj.setRegionName(regionName);
828   
829                             copyObj.setRegionId( 0);
830                   
831                                       
832                             
833         List JavaDoc v = getCustomers();
834         for (int i = 0; i < v.size(); i++)
835         {
836             Customer obj = (Customer) v.get(i);
837             copyObj.addCustomer(obj.copy());
838         }
839                             return copyObj;
840     }
841
842     /**
843      * returns a peer instance associated with this om. Since Peer classes
844      * are not to have any instance attributes, this method returns the
845      * same instance for all member of this class. The method could therefore
846      * be static, but this would prevent one from overriding the behavior.
847      */

848     public RegionPeer getPeer()
849     {
850         return peer;
851     }
852
853     public String JavaDoc toString()
854     {
855         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
856         str.append("Region:\n");
857         str.append("RegionId = ")
858                .append(getRegionId())
859              .append("\n");
860         str.append("RegionName = ")
861                .append(getRegionName())
862              .append("\n");
863         return(str.toString());
864     }
865 }
866
Popular Tags