KickJava   Java API By Example, From Geeks To Geeks.

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


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 RModuleOption
32  */

33 public abstract class BaseRModuleOption extends BaseObject
34     implements org.apache.fulcrum.intake.Retrievable
35 {
36     /** The Peer class */
37     private static final RModuleOptionPeer peer =
38         new RModuleOptionPeer();
39
40         
41     /** The value for the moduleId field */
42     private Integer JavaDoc moduleId;
43       
44     /** The value for the issueTypeId field */
45     private Integer JavaDoc issueTypeId;
46       
47     /** The value for the optionId field */
48     private Integer JavaDoc optionId;
49       
50     /** The value for the displayValue field */
51     private String JavaDoc displayValue;
52                                                                 
53     /** The value for the active field */
54     private boolean active = true;
55                                           
56     /** The value for the order field */
57     private int order = -1;
58                                           
59     /** The value for the weight field */
60     private int weight = -1;
61   
62     
63     /**
64      * Get the ModuleId
65      *
66      * @return Integer
67      */

68     public Integer JavaDoc getModuleId()
69     {
70         return moduleId;
71     }
72
73                               
74     /**
75      * Set the value of ModuleId
76      *
77      * @param v new value
78      */

79     public void setModuleId(Integer JavaDoc v) throws TorqueException
80     {
81     
82                   if (!ObjectUtils.equals(this.moduleId, v))
83               {
84             this.moduleId = v;
85             setModified(true);
86         }
87     
88                                           
89                 if (aModule != null && !ObjectUtils.equals(aModule.getModuleId(), v))
90                 {
91             aModule = null;
92         }
93       
94               }
95   
96     /**
97      * Get the IssueTypeId
98      *
99      * @return Integer
100      */

101     public Integer JavaDoc getIssueTypeId()
102     {
103         return issueTypeId;
104     }
105
106                               
107     /**
108      * Set the value of IssueTypeId
109      *
110      * @param v new value
111      */

112     public void setIssueTypeId(Integer JavaDoc v) throws TorqueException
113     {
114     
115                   if (!ObjectUtils.equals(this.issueTypeId, v))
116               {
117             this.issueTypeId = v;
118             setModified(true);
119         }
120     
121                                   
122                 if (aIssueType != null && !ObjectUtils.equals(aIssueType.getIssueTypeId(), v))
123                 {
124             aIssueType = null;
125         }
126       
127               }
128   
129     /**
130      * Get the OptionId
131      *
132      * @return Integer
133      */

134     public Integer JavaDoc getOptionId()
135     {
136         return optionId;
137     }
138
139                               
140     /**
141      * Set the value of OptionId
142      *
143      * @param v new value
144      */

145     public void setOptionId(Integer JavaDoc v) throws TorqueException
146     {
147     
148                   if (!ObjectUtils.equals(this.optionId, v))
149               {
150             this.optionId = v;
151             setModified(true);
152         }
153     
154                                   
155                 if (aAttributeOption != null && !ObjectUtils.equals(aAttributeOption.getOptionId(), v))
156                 {
157             aAttributeOption = null;
158         }
159       
160               }
161   
162     /**
163      * Get the DisplayValue
164      *
165      * @return String
166      */

167     public String JavaDoc getDisplayValue()
168     {
169         return displayValue;
170     }
171
172                         
173     /**
174      * Set the value of DisplayValue
175      *
176      * @param v new value
177      */

178     public void setDisplayValue(String JavaDoc v)
179     {
180     
181                   if (!ObjectUtils.equals(this.displayValue, v))
182               {
183             this.displayValue = v;
184             setModified(true);
185         }
186     
187           
188               }
189   
190     /**
191      * Get the Active
192      *
193      * @return boolean
194      */

195     public boolean getActive()
196     {
197         return active;
198     }
199
200                         
201     /**
202      * Set the value of Active
203      *
204      * @param v new value
205      */

206     public void setActive(boolean v)
207     {
208     
209                   if (this.active != v)
210               {
211             this.active = v;
212             setModified(true);
213         }
214     
215           
216               }
217   
218     /**
219      * Get the Order
220      *
221      * @return int
222      */

223     public int getOrder()
224     {
225         return order;
226     }
227
228                         
229     /**
230      * Set the value of Order
231      *
232      * @param v new value
233      */

234     public void setOrder(int v)
235     {
236     
237                   if (this.order != v)
238               {
239             this.order = v;
240             setModified(true);
241         }
242     
243           
244               }
245   
246     /**
247      * Get the Weight
248      *
249      * @return int
250      */

251     public int getWeight()
252     {
253         return weight;
254     }
255
256                         
257     /**
258      * Set the value of Weight
259      *
260      * @param v new value
261      */

262     public void setWeight(int v)
263     {
264     
265                   if (this.weight != v)
266               {
267             this.weight = v;
268             setModified(true);
269         }
270     
271           
272               }
273   
274       
275         
276                   
277         private AttributeOption aAttributeOption;
278
279     /**
280      * Declares an association between this object and a AttributeOption object
281      *
282      * @param v AttributeOption
283      * @throws TorqueException
284      */

285     public void setAttributeOption(AttributeOption v) throws TorqueException
286     {
287             if (v == null)
288         {
289                   setOptionId((Integer JavaDoc) null);
290               }
291         else
292         {
293             setOptionId(v.getOptionId());
294         }
295             aAttributeOption = v;
296     }
297
298                         
299     /**
300      * Get the associated AttributeOption object
301      *
302      * @return the associated AttributeOption object
303      * @throws TorqueException
304      */

305     public AttributeOption getAttributeOption() throws TorqueException
306     {
307         if ( !ObjectUtils.equals(getOptionId(), null) )
308         {
309                 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getOptionId()));
310             }
311         return aAttributeOption;
312     }
313
314     /**
315      * Provides convenient way to set a relationship based on a
316      * ObjectKey, for example
317      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
318      *
319          */

320     public void setAttributeOptionKey(ObjectKey key) throws TorqueException
321     {
322     
323                     setOptionId(new Integer JavaDoc(((NumberKey) key).intValue()));
324               }
325   
326             
327                   
328         private Module aModule;
329
330     /**
331      * Declares an association between this object and a Module object
332      *
333      * @param v Module
334      * @throws TorqueException
335      */

336     public void setModule(Module v) throws TorqueException
337     {
338             if (v == null)
339         {
340                   setModuleId((Integer JavaDoc) null);
341               }
342         else
343         {
344             setModuleId(v.getModuleId());
345         }
346             aModule = v;
347     }
348
349                         
350     /**
351      * Get the associated Module object
352      *
353      * @return the associated Module object
354      * @throws TorqueException
355      */

356     public Module getModule() throws TorqueException
357     {
358         if ( !ObjectUtils.equals(getModuleId(), null) )
359         {
360                 return ModuleManager.getInstance(SimpleKey.keyFor(getModuleId()));
361             }
362         return aModule;
363     }
364
365     /**
366      * Provides convenient way to set a relationship based on a
367      * ObjectKey, for example
368      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
369      *
370          */

371     public void setModuleKey(ObjectKey key) throws TorqueException
372     {
373     
374                     setModuleId(new Integer JavaDoc(((NumberKey) key).intValue()));
375               }
376   
377         
378                   
379         private IssueType aIssueType;
380
381     /**
382      * Declares an association between this object and a IssueType object
383      *
384      * @param v IssueType
385      * @throws TorqueException
386      */

387     public void setIssueType(IssueType v) throws TorqueException
388     {
389             if (v == null)
390         {
391                   setIssueTypeId((Integer JavaDoc) null);
392               }
393         else
394         {
395             setIssueTypeId(v.getIssueTypeId());
396         }
397             aIssueType = v;
398     }
399
400                         
401     /**
402      * Get the associated IssueType object
403      *
404      * @return the associated IssueType object
405      * @throws TorqueException
406      */

407     public IssueType getIssueType() throws TorqueException
408     {
409         if ( !ObjectUtils.equals(getIssueTypeId(), null) )
410         {
411                 return IssueTypeManager.getInstance(SimpleKey.keyFor(getIssueTypeId()));
412             }
413         return aIssueType;
414     }
415
416     /**
417      * Provides convenient way to set a relationship based on a
418      * ObjectKey, for example
419      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
420      *
421          */

422     public void setIssueTypeKey(ObjectKey key) throws TorqueException
423     {
424     
425                     setIssueTypeId(new Integer JavaDoc(((NumberKey) key).intValue()));
426               }
427      
428                 
429     private static List JavaDoc fieldNames = null;
430
431     /**
432      * Generate a list of field names.
433      *
434      * @return a list of field names
435      */

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

459     public Object JavaDoc getByName(String JavaDoc name)
460     {
461           if (name.equals("ModuleId"))
462         {
463                 return getModuleId();
464             }
465           if (name.equals("IssueTypeId"))
466         {
467                 return getIssueTypeId();
468             }
469           if (name.equals("OptionId"))
470         {
471                 return getOptionId();
472             }
473           if (name.equals("DisplayValue"))
474         {
475                 return getDisplayValue();
476             }
477           if (name.equals("Active"))
478         {
479                 return Boolean.valueOf(getActive());
480             }
481           if (name.equals("Order"))
482         {
483                 return new Integer JavaDoc(getOrder());
484             }
485           if (name.equals("Weight"))
486         {
487                 return new Integer JavaDoc(getWeight());
488             }
489           return null;
490     }
491     
492     /**
493      * Retrieves a field from the object by name passed in
494      * as a String. The String must be one of the static
495      * Strings defined in this Class' Peer.
496      *
497      * @param name peer name
498      * @return value
499      */

500     public Object JavaDoc getByPeerName(String JavaDoc name)
501     {
502           if (name.equals(RModuleOptionPeer.MODULE_ID))
503         {
504                 return getModuleId();
505             }
506           if (name.equals(RModuleOptionPeer.ISSUE_TYPE_ID))
507         {
508                 return getIssueTypeId();
509             }
510           if (name.equals(RModuleOptionPeer.OPTION_ID))
511         {
512                 return getOptionId();
513             }
514           if (name.equals(RModuleOptionPeer.DISPLAY_VALUE))
515         {
516                 return getDisplayValue();
517             }
518           if (name.equals(RModuleOptionPeer.ACTIVE))
519         {
520                 return Boolean.valueOf(getActive());
521             }
522           if (name.equals(RModuleOptionPeer.PREFERRED_ORDER))
523         {
524                 return new Integer JavaDoc(getOrder());
525             }
526           if (name.equals(RModuleOptionPeer.WEIGHT))
527         {
528                 return new Integer JavaDoc(getWeight());
529             }
530           return null;
531     }
532
533     /**
534      * Retrieves a field from the object by Position as specified
535      * in the xml schema. Zero-based.
536      *
537      * @param pos position in xml schema
538      * @return value
539      */

540     public Object JavaDoc getByPosition(int pos)
541     {
542             if (pos == 0)
543         {
544                 return getModuleId();
545             }
546               if (pos == 1)
547         {
548                 return getIssueTypeId();
549             }
550               if (pos == 2)
551         {
552                 return getOptionId();
553             }
554               if (pos == 3)
555         {
556                 return getDisplayValue();
557             }
558               if (pos == 4)
559         {
560                 return Boolean.valueOf(getActive());
561             }
562               if (pos == 5)
563         {
564                 return new Integer JavaDoc(getOrder());
565             }
566               if (pos == 6)
567         {
568                 return new Integer JavaDoc(getWeight());
569             }
570               return null;
571     }
572      
573     /**
574      * Stores the object in the database. If the object is new,
575      * it inserts it; otherwise an update is performed.
576      *
577      * @throws Exception
578      */

579     public void save() throws Exception JavaDoc
580     {
581           save(RModuleOptionPeer.getMapBuilder()
582                 .getDatabaseMap().getName());
583       }
584
585     /**
586      * Stores the object in the database. If the object is new,
587      * it inserts it; otherwise an update is performed.
588        * Note: this code is here because the method body is
589      * auto-generated conditionally and therefore needs to be
590      * in this file instead of in the super class, BaseObject.
591        *
592      * @param dbName
593      * @throws TorqueException
594      */

595     public void save(String JavaDoc dbName) throws TorqueException
596     {
597         Connection JavaDoc con = null;
598           try
599         {
600             con = Transaction.begin(dbName);
601             save(con);
602             Transaction.commit(con);
603         }
604         catch(TorqueException e)
605         {
606             Transaction.safeRollback(con);
607             throw e;
608         }
609       }
610
611       /** flag to prevent endless save loop, if this object is referenced
612         by another object which falls in this transaction. */

613     private boolean alreadyInSave = false;
614       /**
615      * Stores the object in the database. If the object is new,
616      * it inserts it; otherwise an update is performed. This method
617      * is meant to be used as part of a transaction, otherwise use
618      * the save() method and the connection details will be handled
619      * internally
620      *
621      * @param con
622      * @throws TorqueException
623      */

624     public void save(Connection JavaDoc con) throws TorqueException
625     {
626           if (!alreadyInSave)
627         {
628             alreadyInSave = true;
629
630
631   
632             // If this object has been modified, then save it to the database.
633
if (isModified())
634             {
635                 if (isNew())
636                 {
637                     RModuleOptionPeer.doInsert((RModuleOption)this, con);
638                     setNew(false);
639                 }
640                 else
641                 {
642                     RModuleOptionPeer.doUpdate((RModuleOption)this, con);
643                 }
644
645                       if (isCacheOnSave())
646                 {
647                     RModuleOptionManager.putInstance(this);
648                 }
649               }
650
651                       alreadyInSave = false;
652         }
653       }
654
655     /**
656      * Specify whether to cache the object after saving to the db.
657      * This method returns false
658      */

659     protected boolean isCacheOnSave()
660     {
661         return true;
662     }
663
664                                                                     
665   
666     private final SimpleKey[] pks = new SimpleKey[3];
667     private final ComboKey comboPK = new ComboKey(pks);
668
669     /**
670      * Set the PrimaryKey with an ObjectKey
671      *
672      * @param key
673      */

674     public void setPrimaryKey(ObjectKey key) throws TorqueException
675     {
676         SimpleKey[] keys = (SimpleKey[]) key.getValue();
677         SimpleKey tmpKey = null;
678                       setModuleId(new Integer JavaDoc(((NumberKey)keys[0]).intValue()));
679                         setIssueTypeId(new Integer JavaDoc(((NumberKey)keys[1]).intValue()));
680                         setOptionId(new Integer JavaDoc(((NumberKey)keys[2]).intValue()));
681               }
682
683     /**
684      * Set the PrimaryKey using SimpleKeys.
685      *
686          * @param moduleId Integer
687          * @param issueTypeId Integer
688          * @param optionId Integer
689          */

690     public void setPrimaryKey( Integer JavaDoc moduleId, Integer JavaDoc issueTypeId, Integer JavaDoc optionId)
691         throws TorqueException
692     {
693             setModuleId(moduleId);
694             setIssueTypeId(issueTypeId);
695             setOptionId(optionId);
696         }
697
698     /**
699      * Set the PrimaryKey using a String.
700      */

701     public void setPrimaryKey(String JavaDoc key) throws TorqueException
702     {
703         setPrimaryKey(new ComboKey(key));
704     }
705   
706     /**
707      * returns an id that differentiates this object from others
708      * of its class.
709      */

710     public ObjectKey getPrimaryKey()
711     {
712               pks[0] = SimpleKey.keyFor(getModuleId());
713                   pks[1] = SimpleKey.keyFor(getIssueTypeId());
714                   pks[2] = SimpleKey.keyFor(getOptionId());
715                   return comboPK;
716       }
717  
718     /**
719      * get an id that differentiates this object from others
720      * of its class.
721      */

722     public String JavaDoc getQueryKey()
723     {
724         if (getPrimaryKey() == null)
725         {
726             return "";
727         }
728         else
729         {
730             return getPrimaryKey().toString();
731         }
732     }
733
734     /**
735      * set an id that differentiates this object from others
736      * of its class.
737      */

738     public void setQueryKey(String JavaDoc key)
739         throws TorqueException
740     {
741         setPrimaryKey(key);
742     }
743
744     /**
745      * Makes a copy of this object.
746      * It creates a new object filling in the simple attributes.
747        * It then fills all the association collections and sets the
748      * related objects to isNew=true.
749        */

750       public RModuleOption copy() throws TorqueException
751     {
752         RModuleOption copyObj = new RModuleOption();
753             copyObj.setModuleId(moduleId);
754           copyObj.setIssueTypeId(issueTypeId);
755           copyObj.setOptionId(optionId);
756           copyObj.setDisplayValue(displayValue);
757           copyObj.setActive(active);
758           copyObj.setOrder(order);
759           copyObj.setWeight(weight);
760   
761                       copyObj.setModuleId((Integer JavaDoc)null);
762                                 copyObj.setIssueTypeId((Integer JavaDoc)null);
763                                 copyObj.setOptionId((Integer JavaDoc)null);
764                                     
765                 return copyObj;
766     }
767
768     /**
769      * returns a peer instance associated with this om. Since Peer classes
770      * are not to have any instance attributes, this method returns the
771      * same instance for all member of this class. The method could therefore
772      * be static, but this would prevent one from overriding the behavior.
773      */

774     public RModuleOptionPeer getPeer()
775     {
776         return peer;
777     }
778
779     public String JavaDoc toString()
780     {
781         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
782         str.append("RModuleOption:\n");
783         str.append("ModuleId = ")
784                .append(getModuleId())
785              .append("\n");
786         str.append("IssueTypeId = ")
787                .append(getIssueTypeId())
788              .append("\n");
789         str.append("OptionId = ")
790                .append(getOptionId())
791              .append("\n");
792         str.append("DisplayValue = ")
793                .append(getDisplayValue())
794              .append("\n");
795         str.append("Active = ")
796                .append(getActive())
797              .append("\n");
798         str.append("Order = ")
799                .append(getOrder())
800              .append("\n");
801         str.append("Weight = ")
802                .append(getWeight())
803              .append("\n");
804         return(str.toString());
805     }
806 }
807
Popular Tags