KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.tigris.scarab.om;
2
3
4 import java.math.BigDecimal JavaDoc;
5 import java.sql.Connection JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Collections JavaDoc;
8 import java.util.Date JavaDoc;
9 import java.util.List JavaDoc;
10
11 import org.apache.commons.lang.ObjectUtils;
12 import org.apache.fulcrum.intake.Retrievable;
13 import org.apache.torque.TorqueException;
14 import org.apache.torque.om.BaseObject;
15 import org.apache.torque.om.ComboKey;
16 import org.apache.torque.om.DateKey;
17 import org.apache.torque.om.NumberKey;
18 import org.apache.torque.om.ObjectKey;
19 import org.apache.torque.om.SimpleKey;
20 import org.apache.torque.om.StringKey;
21 import org.apache.torque.om.Persistent;
22 import org.apache.torque.util.Criteria;
23 import org.apache.torque.util.Transaction;
24
25
26 /**
27  * You should not use this class directly. It should not even be
28  * extended all references should be to OptionRelationship
29  */

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

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

61     public void setRelationshipId(Integer JavaDoc v) throws TorqueException
62     {
63     
64                   if (!ObjectUtils.equals(this.relationshipId, v))
65               {
66             this.relationshipId = v;
67             setModified(true);
68         }
69     
70           
71                                   
72         // update associated ROptionOption
73
if (collROptionOptions != null)
74         {
75             for (int i = 0; i < collROptionOptions.size(); i++)
76             {
77                 ((ROptionOption) collROptionOptions.get(i))
78                         .setRelationshipId(v);
79             }
80         }
81                       }
82   
83     /**
84      * Get the Name
85      *
86      * @return String
87      */

88     public String JavaDoc getName()
89     {
90         return name;
91     }
92
93                         
94     /**
95      * Set the value of Name
96      *
97      * @param v new value
98      */

99     public void setName(String JavaDoc v)
100     {
101     
102                   if (!ObjectUtils.equals(this.name, v))
103               {
104             this.name = v;
105             setModified(true);
106         }
107     
108           
109               }
110   
111          
112                                 
113             
114     /**
115      * Collection to store aggregation of collROptionOptions
116      */

117     protected List JavaDoc collROptionOptions;
118
119     /**
120      * Temporary storage of collROptionOptions to save a possible db hit in
121      * the event objects are add to the collection, but the
122      * complete collection is never requested.
123      */

124     protected void initROptionOptions()
125     {
126         if (collROptionOptions == null)
127         {
128             collROptionOptions = new ArrayList JavaDoc();
129         }
130     }
131
132             
133     /**
134      * Method called to associate a ROptionOption object to this object
135      * through the ROptionOption foreign key attribute
136      *
137      * @param l ROptionOption
138      * @throws TorqueException
139      */

140     public void addROptionOption(ROptionOption l) throws TorqueException
141     {
142         getROptionOptions().add(l);
143         l.setOptionRelationship((OptionRelationship)this);
144     }
145
146     /**
147      * The criteria used to select the current contents of collROptionOptions
148      */

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

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

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

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

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

296     protected List JavaDoc getROptionOptionsJoinAttributeOptionRelatedByOption1Id(Criteria criteria)
297         throws TorqueException
298     {
299         if (collROptionOptions == null)
300         {
301             if (isNew())
302             {
303                collROptionOptions = new ArrayList JavaDoc();
304             }
305             else
306             {
307                             criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() );
308                             collROptionOptions = ROptionOptionPeer.doSelectJoinAttributeOptionRelatedByOption1Id(criteria);
309             }
310         }
311         else
312         {
313             // the following code is to determine if a new query is
314
// called for. If the criteria is the same as the last
315
// one, just return the collection.
316

317                             criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() );
318                         if (!lastROptionOptionsCriteria.equals(criteria))
319             {
320                 collROptionOptions = ROptionOptionPeer.doSelectJoinAttributeOptionRelatedByOption1Id(criteria);
321             }
322         }
323         lastROptionOptionsCriteria = criteria;
324
325         return collROptionOptions;
326     }
327                   
328                     
329                     
330                                             
331                                                                           
332                                         
333                     
334                     
335           
336     /**
337      * If this collection has already been initialized with
338      * an identical criteria, it returns the collection.
339      * Otherwise if this OptionRelationship is new, it will return
340      * an empty collection; or if this OptionRelationship has previously
341      * been saved, it will retrieve related ROptionOptions from storage.
342      *
343      * This method is protected by default in order to keep the public
344      * api reasonable. You can provide public methods for those you
345      * actually need in OptionRelationship.
346      */

347     protected List JavaDoc getROptionOptionsJoinAttributeOptionRelatedByOption2Id(Criteria criteria)
348         throws TorqueException
349     {
350         if (collROptionOptions == null)
351         {
352             if (isNew())
353             {
354                collROptionOptions = new ArrayList JavaDoc();
355             }
356             else
357             {
358                             criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() );
359                             collROptionOptions = ROptionOptionPeer.doSelectJoinAttributeOptionRelatedByOption2Id(criteria);
360             }
361         }
362         else
363         {
364             // the following code is to determine if a new query is
365
// called for. If the criteria is the same as the last
366
// one, just return the collection.
367

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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