KickJava   Java API By Example, From Geeks To Geeks.

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


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     
28   
29 /**
30  * You should not use this class directly. It should not even be
31  * extended all references should be to ROptionOption
32  */

33 public abstract class BaseROptionOption extends BaseObject
34     implements org.apache.fulcrum.intake.Retrievable
35 {
36     /** The Peer class */
37     private static final ROptionOptionPeer peer =
38         new ROptionOptionPeer();
39
40         
41     /** The value for the option1Id field */
42     private Integer JavaDoc option1Id;
43       
44     /** The value for the option2Id field */
45     private Integer JavaDoc option2Id;
46       
47     /** The value for the relationshipId field */
48     private Integer JavaDoc relationshipId;
49       
50     /** The value for the weight field */
51     private int weight;
52       
53     /** The value for the preferredOrder field */
54     private int preferredOrder;
55   
56     
57     /**
58      * Get the Option1Id
59      *
60      * @return Integer
61      */

62     public Integer JavaDoc getOption1Id()
63     {
64         return option1Id;
65     }
66
67                               
68     /**
69      * Set the value of Option1Id
70      *
71      * @param v new value
72      */

73     public void setOption1Id(Integer JavaDoc v) throws TorqueException
74     {
75     
76                   if (!ObjectUtils.equals(this.option1Id, v))
77               {
78             this.option1Id = v;
79             setModified(true);
80         }
81     
82                                                                           
83                 if (aAttributeOptionRelatedByOption1Id != null && !ObjectUtils.equals(aAttributeOptionRelatedByOption1Id.getOptionId(), v))
84                 {
85             aAttributeOptionRelatedByOption1Id = null;
86         }
87       
88               }
89   
90     /**
91      * Get the Option2Id
92      *
93      * @return Integer
94      */

95     public Integer JavaDoc getOption2Id()
96     {
97         return option2Id;
98     }
99
100                               
101     /**
102      * Set the value of Option2Id
103      *
104      * @param v new value
105      */

106     public void setOption2Id(Integer JavaDoc v) throws TorqueException
107     {
108     
109                   if (!ObjectUtils.equals(this.option2Id, v))
110               {
111             this.option2Id = v;
112             setModified(true);
113         }
114     
115                                                                           
116                 if (aAttributeOptionRelatedByOption2Id != null && !ObjectUtils.equals(aAttributeOptionRelatedByOption2Id.getOptionId(), v))
117                 {
118             aAttributeOptionRelatedByOption2Id = null;
119         }
120       
121               }
122   
123     /**
124      * Get the RelationshipId
125      *
126      * @return Integer
127      */

128     public Integer JavaDoc getRelationshipId()
129     {
130         return relationshipId;
131     }
132
133                               
134     /**
135      * Set the value of RelationshipId
136      *
137      * @param v new value
138      */

139     public void setRelationshipId(Integer JavaDoc v) throws TorqueException
140     {
141     
142                   if (!ObjectUtils.equals(this.relationshipId, v))
143               {
144             this.relationshipId = v;
145             setModified(true);
146         }
147     
148                                   
149                 if (aOptionRelationship != null && !ObjectUtils.equals(aOptionRelationship.getRelationshipId(), v))
150                 {
151             aOptionRelationship = null;
152         }
153       
154               }
155   
156     /**
157      * Get the Weight
158      *
159      * @return int
160      */

161     public int getWeight()
162     {
163         return weight;
164     }
165
166                         
167     /**
168      * Set the value of Weight
169      *
170      * @param v new value
171      */

172     public void setWeight(int v)
173     {
174     
175                   if (this.weight != v)
176               {
177             this.weight = v;
178             setModified(true);
179         }
180     
181           
182               }
183   
184     /**
185      * Get the PreferredOrder
186      *
187      * @return int
188      */

189     public int getPreferredOrder()
190     {
191         return preferredOrder;
192     }
193
194                         
195     /**
196      * Set the value of PreferredOrder
197      *
198      * @param v new value
199      */

200     public void setPreferredOrder(int v)
201     {
202     
203                   if (this.preferredOrder != v)
204               {
205             this.preferredOrder = v;
206             setModified(true);
207         }
208     
209           
210               }
211   
212       
213         
214                         
215             private AttributeOption aAttributeOptionRelatedByOption1Id;
216
217     /**
218      * Declares an association between this object and a AttributeOption object
219      *
220      * @param v AttributeOption
221      * @throws TorqueException
222      */

223     public void setAttributeOptionRelatedByOption1Id(AttributeOption v) throws TorqueException
224     {
225             if (v == null)
226         {
227                   setOption1Id((Integer JavaDoc) null);
228               }
229         else
230         {
231             setOption1Id(v.getOptionId());
232         }
233             aAttributeOptionRelatedByOption1Id = v;
234     }
235
236                         
237     /**
238      * Get the associated AttributeOption object
239      *
240      * @return the associated AttributeOption object
241      * @throws TorqueException
242      */

243     public AttributeOption getAttributeOptionRelatedByOption1Id() throws TorqueException
244     {
245         if ( !ObjectUtils.equals(getOption1Id(), null) )
246         {
247                 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getOption1Id()));
248             }
249         return aAttributeOptionRelatedByOption1Id;
250     }
251
252     /**
253      * Provides convenient way to set a relationship based on a
254      * ObjectKey, for example
255      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
256      *
257          */

258     public void setAttributeOptionRelatedByOption1IdKey(ObjectKey key) throws TorqueException
259     {
260     
261                     setOption1Id(new Integer JavaDoc(((NumberKey) key).intValue()));
262               }
263   
264         
265                         
266             private AttributeOption aAttributeOptionRelatedByOption2Id;
267
268     /**
269      * Declares an association between this object and a AttributeOption object
270      *
271      * @param v AttributeOption
272      * @throws TorqueException
273      */

274     public void setAttributeOptionRelatedByOption2Id(AttributeOption v) throws TorqueException
275     {
276             if (v == null)
277         {
278                   setOption2Id((Integer JavaDoc) null);
279               }
280         else
281         {
282             setOption2Id(v.getOptionId());
283         }
284             aAttributeOptionRelatedByOption2Id = v;
285     }
286
287                         
288     /**
289      * Get the associated AttributeOption object
290      *
291      * @return the associated AttributeOption object
292      * @throws TorqueException
293      */

294     public AttributeOption getAttributeOptionRelatedByOption2Id() throws TorqueException
295     {
296         if ( !ObjectUtils.equals(getOption2Id(), null) )
297         {
298                 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getOption2Id()));
299             }
300         return aAttributeOptionRelatedByOption2Id;
301     }
302
303     /**
304      * Provides convenient way to set a relationship based on a
305      * ObjectKey, for example
306      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
307      *
308          */

309     public void setAttributeOptionRelatedByOption2IdKey(ObjectKey key) throws TorqueException
310     {
311     
312                     setOption2Id(new Integer JavaDoc(((NumberKey) key).intValue()));
313               }
314   
315         
316                   
317         private OptionRelationship aOptionRelationship;
318
319     /**
320      * Declares an association between this object and a OptionRelationship object
321      *
322      * @param v OptionRelationship
323      * @throws TorqueException
324      */

325     public void setOptionRelationship(OptionRelationship v) throws TorqueException
326     {
327             if (v == null)
328         {
329                   setRelationshipId((Integer JavaDoc) null);
330               }
331         else
332         {
333             setRelationshipId(v.getRelationshipId());
334         }
335             aOptionRelationship = v;
336     }
337
338                         
339     /**
340      * Get the associated OptionRelationship object
341      *
342      * @return the associated OptionRelationship object
343      * @throws TorqueException
344      */

345     public OptionRelationship getOptionRelationship() throws TorqueException
346     {
347         if ( !ObjectUtils.equals(getRelationshipId(), null) )
348         {
349                 return OptionRelationshipManager.getInstance(SimpleKey.keyFor(getRelationshipId()));
350             }
351         return aOptionRelationship;
352     }
353
354     /**
355      * Provides convenient way to set a relationship based on a
356      * ObjectKey, for example
357      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
358      *
359          */

360     public void setOptionRelationshipKey(ObjectKey key) throws TorqueException
361     {
362     
363                     setRelationshipId(new Integer JavaDoc(((NumberKey) key).intValue()));
364               }
365      
366                 
367     private static List JavaDoc fieldNames = null;
368
369     /**
370      * Generate a list of field names.
371      *
372      * @return a list of field names
373      */

374     public static synchronized List JavaDoc getFieldNames()
375     {
376         if (fieldNames == null)
377         {
378             fieldNames = new ArrayList JavaDoc();
379               fieldNames.add("Option1Id");
380               fieldNames.add("Option2Id");
381               fieldNames.add("RelationshipId");
382               fieldNames.add("Weight");
383               fieldNames.add("PreferredOrder");
384               fieldNames = Collections.unmodifiableList(fieldNames);
385         }
386         return fieldNames;
387     }
388
389     /**
390      * Retrieves a field from the object by name passed in as a String.
391      *
392      * @param name field name
393      * @return value
394      */

395     public Object JavaDoc getByName(String JavaDoc name)
396     {
397           if (name.equals("Option1Id"))
398         {
399                 return getOption1Id();
400             }
401           if (name.equals("Option2Id"))
402         {
403                 return getOption2Id();
404             }
405           if (name.equals("RelationshipId"))
406         {
407                 return getRelationshipId();
408             }
409           if (name.equals("Weight"))
410         {
411                 return new Integer JavaDoc(getWeight());
412             }
413           if (name.equals("PreferredOrder"))
414         {
415                 return new Integer JavaDoc(getPreferredOrder());
416             }
417           return null;
418     }
419     
420     /**
421      * Retrieves a field from the object by name passed in
422      * as a String. The String must be one of the static
423      * Strings defined in this Class' Peer.
424      *
425      * @param name peer name
426      * @return value
427      */

428     public Object JavaDoc getByPeerName(String JavaDoc name)
429     {
430           if (name.equals(ROptionOptionPeer.OPTION1_ID))
431         {
432                 return getOption1Id();
433             }
434           if (name.equals(ROptionOptionPeer.OPTION2_ID))
435         {
436                 return getOption2Id();
437             }
438           if (name.equals(ROptionOptionPeer.RELATIONSHIP_ID))
439         {
440                 return getRelationshipId();
441             }
442           if (name.equals(ROptionOptionPeer.WEIGHT))
443         {
444                 return new Integer JavaDoc(getWeight());
445             }
446           if (name.equals(ROptionOptionPeer.PREFERRED_ORDER))
447         {
448                 return new Integer JavaDoc(getPreferredOrder());
449             }
450           return null;
451     }
452
453     /**
454      * Retrieves a field from the object by Position as specified
455      * in the xml schema. Zero-based.
456      *
457      * @param pos position in xml schema
458      * @return value
459      */

460     public Object JavaDoc getByPosition(int pos)
461     {
462             if (pos == 0)
463         {
464                 return getOption1Id();
465             }
466               if (pos == 1)
467         {
468                 return getOption2Id();
469             }
470               if (pos == 2)
471         {
472                 return getRelationshipId();
473             }
474               if (pos == 3)
475         {
476                 return new Integer JavaDoc(getWeight());
477             }
478               if (pos == 4)
479         {
480                 return new Integer JavaDoc(getPreferredOrder());
481             }
482               return null;
483     }
484      
485     /**
486      * Stores the object in the database. If the object is new,
487      * it inserts it; otherwise an update is performed.
488      *
489      * @throws Exception
490      */

491     public void save() throws Exception JavaDoc
492     {
493           save(ROptionOptionPeer.getMapBuilder()
494                 .getDatabaseMap().getName());
495       }
496
497     /**
498      * Stores the object in the database. If the object is new,
499      * it inserts it; otherwise an update is performed.
500        * Note: this code is here because the method body is
501      * auto-generated conditionally and therefore needs to be
502      * in this file instead of in the super class, BaseObject.
503        *
504      * @param dbName
505      * @throws TorqueException
506      */

507     public void save(String JavaDoc dbName) throws TorqueException
508     {
509         Connection JavaDoc con = null;
510           try
511         {
512             con = Transaction.begin(dbName);
513             save(con);
514             Transaction.commit(con);
515         }
516         catch(TorqueException e)
517         {
518             Transaction.safeRollback(con);
519             throw e;
520         }
521       }
522
523       /** flag to prevent endless save loop, if this object is referenced
524         by another object which falls in this transaction. */

525     private boolean alreadyInSave = false;
526       /**
527      * Stores the object in the database. If the object is new,
528      * it inserts it; otherwise an update is performed. This method
529      * is meant to be used as part of a transaction, otherwise use
530      * the save() method and the connection details will be handled
531      * internally
532      *
533      * @param con
534      * @throws TorqueException
535      */

536     public void save(Connection JavaDoc con) throws TorqueException
537     {
538           if (!alreadyInSave)
539         {
540             alreadyInSave = true;
541
542
543   
544             // If this object has been modified, then save it to the database.
545
if (isModified())
546             {
547                 if (isNew())
548                 {
549                     ROptionOptionPeer.doInsert((ROptionOption)this, con);
550                     setNew(false);
551                 }
552                 else
553                 {
554                     ROptionOptionPeer.doUpdate((ROptionOption)this, con);
555                 }
556
557                       if (isCacheOnSave())
558                 {
559                     ROptionOptionManager.putInstance(this);
560                 }
561               }
562
563                       alreadyInSave = false;
564         }
565       }
566
567     /**
568      * Specify whether to cache the object after saving to the db.
569      * This method returns false
570      */

571     protected boolean isCacheOnSave()
572     {
573         return true;
574     }
575
576                                               
577   
578     private final SimpleKey[] pks = new SimpleKey[2];
579     private final ComboKey comboPK = new ComboKey(pks);
580
581     /**
582      * Set the PrimaryKey with an ObjectKey
583      *
584      * @param key
585      */

586     public void setPrimaryKey(ObjectKey key) throws TorqueException
587     {
588         SimpleKey[] keys = (SimpleKey[]) key.getValue();
589         SimpleKey tmpKey = null;
590                       setOption1Id(new Integer JavaDoc(((NumberKey)keys[0]).intValue()));
591                         setOption2Id(new Integer JavaDoc(((NumberKey)keys[1]).intValue()));
592               }
593
594     /**
595      * Set the PrimaryKey using SimpleKeys.
596      *
597          * @param option1Id Integer
598          * @param option2Id Integer
599          */

600     public void setPrimaryKey( Integer JavaDoc option1Id, Integer JavaDoc option2Id)
601         throws TorqueException
602     {
603             setOption1Id(option1Id);
604             setOption2Id(option2Id);
605         }
606
607     /**
608      * Set the PrimaryKey using a String.
609      */

610     public void setPrimaryKey(String JavaDoc key) throws TorqueException
611     {
612         setPrimaryKey(new ComboKey(key));
613     }
614   
615     /**
616      * returns an id that differentiates this object from others
617      * of its class.
618      */

619     public ObjectKey getPrimaryKey()
620     {
621               pks[0] = SimpleKey.keyFor(getOption1Id());
622                   pks[1] = SimpleKey.keyFor(getOption2Id());
623                   return comboPK;
624       }
625  
626     /**
627      * get an id that differentiates this object from others
628      * of its class.
629      */

630     public String JavaDoc getQueryKey()
631     {
632         if (getPrimaryKey() == null)
633         {
634             return "";
635         }
636         else
637         {
638             return getPrimaryKey().toString();
639         }
640     }
641
642     /**
643      * set an id that differentiates this object from others
644      * of its class.
645      */

646     public void setQueryKey(String JavaDoc key)
647         throws TorqueException
648     {
649         setPrimaryKey(key);
650     }
651
652     /**
653      * Makes a copy of this object.
654      * It creates a new object filling in the simple attributes.
655        * It then fills all the association collections and sets the
656      * related objects to isNew=true.
657        */

658       public ROptionOption copy() throws TorqueException
659     {
660         ROptionOption copyObj = new ROptionOption();
661             copyObj.setOption1Id(option1Id);
662           copyObj.setOption2Id(option2Id);
663           copyObj.setRelationshipId(relationshipId);
664           copyObj.setWeight(weight);
665           copyObj.setPreferredOrder(preferredOrder);
666   
667                       copyObj.setOption1Id((Integer JavaDoc)null);
668                                 copyObj.setOption2Id((Integer JavaDoc)null);
669                               
670                 return copyObj;
671     }
672
673     /**
674      * returns a peer instance associated with this om. Since Peer classes
675      * are not to have any instance attributes, this method returns the
676      * same instance for all member of this class. The method could therefore
677      * be static, but this would prevent one from overriding the behavior.
678      */

679     public ROptionOptionPeer getPeer()
680     {
681         return peer;
682     }
683
684     public String JavaDoc toString()
685     {
686         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
687         str.append("ROptionOption:\n");
688         str.append("Option1Id = ")
689                .append(getOption1Id())
690              .append("\n");
691         str.append("Option2Id = ")
692                .append(getOption2Id())
693              .append("\n");
694         str.append("RelationshipId = ")
695                .append(getRelationshipId())
696              .append("\n");
697         str.append("Weight = ")
698                .append(getWeight())
699              .append("\n");
700         str.append("PreferredOrder = ")
701                .append(getPreferredOrder())
702              .append("\n");
703         return(str.toString());
704     }
705 }
706
Popular Tags