KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

64     public Integer JavaDoc getIssueTypeId()
65     {
66         return issueTypeId;
67     }
68
69                               
70     /**
71      * Set the value of IssueTypeId
72      *
73      * @param v new value
74      */

75     public void setIssueTypeId(Integer JavaDoc v) throws TorqueException
76     {
77     
78                   if (!ObjectUtils.equals(this.issueTypeId, v))
79               {
80             this.issueTypeId = v;
81             setModified(true);
82         }
83     
84                                   
85                 if (aIssueType != null && !ObjectUtils.equals(aIssueType.getIssueTypeId(), v))
86                 {
87             aIssueType = null;
88         }
89       
90               }
91   
92     /**
93      * Get the OptionId
94      *
95      * @return Integer
96      */

97     public Integer JavaDoc getOptionId()
98     {
99         return optionId;
100     }
101
102                               
103     /**
104      * Set the value of OptionId
105      *
106      * @param v new value
107      */

108     public void setOptionId(Integer JavaDoc v) throws TorqueException
109     {
110     
111                   if (!ObjectUtils.equals(this.optionId, v))
112               {
113             this.optionId = v;
114             setModified(true);
115         }
116     
117                                   
118                 if (aAttributeOption != null && !ObjectUtils.equals(aAttributeOption.getOptionId(), v))
119                 {
120             aAttributeOption = null;
121         }
122       
123               }
124   
125     /**
126      * Get the Active
127      *
128      * @return boolean
129      */

130     public boolean getActive()
131     {
132         return active;
133     }
134
135                         
136     /**
137      * Set the value of Active
138      *
139      * @param v new value
140      */

141     public void setActive(boolean v)
142     {
143     
144                   if (this.active != v)
145               {
146             this.active = v;
147             setModified(true);
148         }
149     
150           
151               }
152   
153     /**
154      * Get the Locked
155      *
156      * @return boolean
157      */

158     public boolean getLocked()
159     {
160         return locked;
161     }
162
163                         
164     /**
165      * Set the value of Locked
166      *
167      * @param v new value
168      */

169     public void setLocked(boolean v)
170     {
171     
172                   if (this.locked != v)
173               {
174             this.locked = v;
175             setModified(true);
176         }
177     
178           
179               }
180   
181     /**
182      * Get the Order
183      *
184      * @return int
185      */

186     public int getOrder()
187     {
188         return order;
189     }
190
191                         
192     /**
193      * Set the value of Order
194      *
195      * @param v new value
196      */

197     public void setOrder(int v)
198     {
199     
200                   if (this.order != v)
201               {
202             this.order = v;
203             setModified(true);
204         }
205     
206           
207               }
208   
209     /**
210      * Get the Weight
211      *
212      * @return int
213      */

214     public int getWeight()
215     {
216         return weight;
217     }
218
219                         
220     /**
221      * Set the value of Weight
222      *
223      * @param v new value
224      */

225     public void setWeight(int v)
226     {
227     
228                   if (this.weight != v)
229               {
230             this.weight = v;
231             setModified(true);
232         }
233     
234           
235               }
236   
237       
238         
239                   
240         private AttributeOption aAttributeOption;
241
242     /**
243      * Declares an association between this object and a AttributeOption object
244      *
245      * @param v AttributeOption
246      * @throws TorqueException
247      */

248     public void setAttributeOption(AttributeOption v) throws TorqueException
249     {
250             if (v == null)
251         {
252                   setOptionId((Integer JavaDoc) null);
253               }
254         else
255         {
256             setOptionId(v.getOptionId());
257         }
258             aAttributeOption = v;
259     }
260
261                         
262     /**
263      * Get the associated AttributeOption object
264      *
265      * @return the associated AttributeOption object
266      * @throws TorqueException
267      */

268     public AttributeOption getAttributeOption() throws TorqueException
269     {
270         if ( !ObjectUtils.equals(getOptionId(), null) )
271         {
272                 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getOptionId()));
273             }
274         return aAttributeOption;
275     }
276
277     /**
278      * Provides convenient way to set a relationship based on a
279      * ObjectKey, for example
280      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
281      *
282          */

283     public void setAttributeOptionKey(ObjectKey key) throws TorqueException
284     {
285     
286                     setOptionId(new Integer JavaDoc(((NumberKey) key).intValue()));
287               }
288   
289         
290                   
291         private IssueType aIssueType;
292
293     /**
294      * Declares an association between this object and a IssueType object
295      *
296      * @param v IssueType
297      * @throws TorqueException
298      */

299     public void setIssueType(IssueType v) throws TorqueException
300     {
301             if (v == null)
302         {
303                   setIssueTypeId((Integer JavaDoc) null);
304               }
305         else
306         {
307             setIssueTypeId(v.getIssueTypeId());
308         }
309             aIssueType = v;
310     }
311
312                         
313     /**
314      * Get the associated IssueType object
315      *
316      * @return the associated IssueType object
317      * @throws TorqueException
318      */

319     public IssueType getIssueType() throws TorqueException
320     {
321         if ( !ObjectUtils.equals(getIssueTypeId(), null) )
322         {
323                 return IssueTypeManager.getInstance(SimpleKey.keyFor(getIssueTypeId()));
324             }
325         return aIssueType;
326     }
327
328     /**
329      * Provides convenient way to set a relationship based on a
330      * ObjectKey, for example
331      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
332      *
333          */

334     public void setIssueTypeKey(ObjectKey key) throws TorqueException
335     {
336     
337                     setIssueTypeId(new Integer JavaDoc(((NumberKey) key).intValue()));
338               }
339      
340                 
341     private static List JavaDoc fieldNames = null;
342
343     /**
344      * Generate a list of field names.
345      *
346      * @return a list of field names
347      */

348     public static synchronized List JavaDoc getFieldNames()
349     {
350         if (fieldNames == null)
351         {
352             fieldNames = new ArrayList JavaDoc();
353               fieldNames.add("IssueTypeId");
354               fieldNames.add("OptionId");
355               fieldNames.add("Active");
356               fieldNames.add("Locked");
357               fieldNames.add("Order");
358               fieldNames.add("Weight");
359               fieldNames = Collections.unmodifiableList(fieldNames);
360         }
361         return fieldNames;
362     }
363
364     /**
365      * Retrieves a field from the object by name passed in as a String.
366      *
367      * @param name field name
368      * @return value
369      */

370     public Object JavaDoc getByName(String JavaDoc name)
371     {
372           if (name.equals("IssueTypeId"))
373         {
374                 return getIssueTypeId();
375             }
376           if (name.equals("OptionId"))
377         {
378                 return getOptionId();
379             }
380           if (name.equals("Active"))
381         {
382                 return Boolean.valueOf(getActive());
383             }
384           if (name.equals("Locked"))
385         {
386                 return Boolean.valueOf(getLocked());
387             }
388           if (name.equals("Order"))
389         {
390                 return new Integer JavaDoc(getOrder());
391             }
392           if (name.equals("Weight"))
393         {
394                 return new Integer JavaDoc(getWeight());
395             }
396           return null;
397     }
398     
399     /**
400      * Retrieves a field from the object by name passed in
401      * as a String. The String must be one of the static
402      * Strings defined in this Class' Peer.
403      *
404      * @param name peer name
405      * @return value
406      */

407     public Object JavaDoc getByPeerName(String JavaDoc name)
408     {
409           if (name.equals(RIssueTypeOptionPeer.ISSUE_TYPE_ID))
410         {
411                 return getIssueTypeId();
412             }
413           if (name.equals(RIssueTypeOptionPeer.OPTION_ID))
414         {
415                 return getOptionId();
416             }
417           if (name.equals(RIssueTypeOptionPeer.ACTIVE))
418         {
419                 return Boolean.valueOf(getActive());
420             }
421           if (name.equals(RIssueTypeOptionPeer.LOCKED))
422         {
423                 return Boolean.valueOf(getLocked());
424             }
425           if (name.equals(RIssueTypeOptionPeer.PREFERRED_ORDER))
426         {
427                 return new Integer JavaDoc(getOrder());
428             }
429           if (name.equals(RIssueTypeOptionPeer.WEIGHT))
430         {
431                 return new Integer JavaDoc(getWeight());
432             }
433           return null;
434     }
435
436     /**
437      * Retrieves a field from the object by Position as specified
438      * in the xml schema. Zero-based.
439      *
440      * @param pos position in xml schema
441      * @return value
442      */

443     public Object JavaDoc getByPosition(int pos)
444     {
445             if (pos == 0)
446         {
447                 return getIssueTypeId();
448             }
449               if (pos == 1)
450         {
451                 return getOptionId();
452             }
453               if (pos == 2)
454         {
455                 return Boolean.valueOf(getActive());
456             }
457               if (pos == 3)
458         {
459                 return Boolean.valueOf(getLocked());
460             }
461               if (pos == 4)
462         {
463                 return new Integer JavaDoc(getOrder());
464             }
465               if (pos == 5)
466         {
467                 return new Integer JavaDoc(getWeight());
468             }
469               return null;
470     }
471      
472     /**
473      * Stores the object in the database. If the object is new,
474      * it inserts it; otherwise an update is performed.
475      *
476      * @throws Exception
477      */

478     public void save() throws Exception JavaDoc
479     {
480           save(RIssueTypeOptionPeer.getMapBuilder()
481                 .getDatabaseMap().getName());
482       }
483
484     /**
485      * Stores the object in the database. If the object is new,
486      * it inserts it; otherwise an update is performed.
487        * Note: this code is here because the method body is
488      * auto-generated conditionally and therefore needs to be
489      * in this file instead of in the super class, BaseObject.
490        *
491      * @param dbName
492      * @throws TorqueException
493      */

494     public void save(String JavaDoc dbName) throws TorqueException
495     {
496         Connection JavaDoc con = null;
497           try
498         {
499             con = Transaction.begin(dbName);
500             save(con);
501             Transaction.commit(con);
502         }
503         catch(TorqueException e)
504         {
505             Transaction.safeRollback(con);
506             throw e;
507         }
508       }
509
510       /** flag to prevent endless save loop, if this object is referenced
511         by another object which falls in this transaction. */

512     private boolean alreadyInSave = false;
513       /**
514      * Stores the object in the database. If the object is new,
515      * it inserts it; otherwise an update is performed. This method
516      * is meant to be used as part of a transaction, otherwise use
517      * the save() method and the connection details will be handled
518      * internally
519      *
520      * @param con
521      * @throws TorqueException
522      */

523     public void save(Connection JavaDoc con) throws TorqueException
524     {
525           if (!alreadyInSave)
526         {
527             alreadyInSave = true;
528
529
530   
531             // If this object has been modified, then save it to the database.
532
if (isModified())
533             {
534                 if (isNew())
535                 {
536                     RIssueTypeOptionPeer.doInsert((RIssueTypeOption)this, con);
537                     setNew(false);
538                 }
539                 else
540                 {
541                     RIssueTypeOptionPeer.doUpdate((RIssueTypeOption)this, con);
542                 }
543
544                       if (isCacheOnSave())
545                 {
546                     RIssueTypeOptionManager.putInstance(this);
547                 }
548               }
549
550                       alreadyInSave = false;
551         }
552       }
553
554     /**
555      * Specify whether to cache the object after saving to the db.
556      * This method returns false
557      */

558     protected boolean isCacheOnSave()
559     {
560         return true;
561     }
562
563                                               
564   
565     private final SimpleKey[] pks = new SimpleKey[2];
566     private final ComboKey comboPK = new ComboKey(pks);
567
568     /**
569      * Set the PrimaryKey with an ObjectKey
570      *
571      * @param key
572      */

573     public void setPrimaryKey(ObjectKey key) throws TorqueException
574     {
575         SimpleKey[] keys = (SimpleKey[]) key.getValue();
576         SimpleKey tmpKey = null;
577                       setIssueTypeId(new Integer JavaDoc(((NumberKey)keys[0]).intValue()));
578                         setOptionId(new Integer JavaDoc(((NumberKey)keys[1]).intValue()));
579               }
580
581     /**
582      * Set the PrimaryKey using SimpleKeys.
583      *
584          * @param issueTypeId Integer
585          * @param optionId Integer
586          */

587     public void setPrimaryKey( Integer JavaDoc issueTypeId, Integer JavaDoc optionId)
588         throws TorqueException
589     {
590             setIssueTypeId(issueTypeId);
591             setOptionId(optionId);
592         }
593
594     /**
595      * Set the PrimaryKey using a String.
596      */

597     public void setPrimaryKey(String JavaDoc key) throws TorqueException
598     {
599         setPrimaryKey(new ComboKey(key));
600     }
601   
602     /**
603      * returns an id that differentiates this object from others
604      * of its class.
605      */

606     public ObjectKey getPrimaryKey()
607     {
608               pks[0] = SimpleKey.keyFor(getIssueTypeId());
609                   pks[1] = SimpleKey.keyFor(getOptionId());
610                   return comboPK;
611       }
612  
613     /**
614      * get an id that differentiates this object from others
615      * of its class.
616      */

617     public String JavaDoc getQueryKey()
618     {
619         if (getPrimaryKey() == null)
620         {
621             return "";
622         }
623         else
624         {
625             return getPrimaryKey().toString();
626         }
627     }
628
629     /**
630      * set an id that differentiates this object from others
631      * of its class.
632      */

633     public void setQueryKey(String JavaDoc key)
634         throws TorqueException
635     {
636         setPrimaryKey(key);
637     }
638
639     /**
640      * Makes a copy of this object.
641      * It creates a new object filling in the simple attributes.
642        * It then fills all the association collections and sets the
643      * related objects to isNew=true.
644        */

645       public RIssueTypeOption copy() throws TorqueException
646     {
647         RIssueTypeOption copyObj = new RIssueTypeOption();
648             copyObj.setIssueTypeId(issueTypeId);
649           copyObj.setOptionId(optionId);
650           copyObj.setActive(active);
651           copyObj.setLocked(locked);
652           copyObj.setOrder(order);
653           copyObj.setWeight(weight);
654   
655                       copyObj.setIssueTypeId((Integer JavaDoc)null);
656                                 copyObj.setOptionId((Integer JavaDoc)null);
657                                     
658                 return copyObj;
659     }
660
661     /**
662      * returns a peer instance associated with this om. Since Peer classes
663      * are not to have any instance attributes, this method returns the
664      * same instance for all member of this class. The method could therefore
665      * be static, but this would prevent one from overriding the behavior.
666      */

667     public RIssueTypeOptionPeer getPeer()
668     {
669         return peer;
670     }
671
672     public String JavaDoc toString()
673     {
674         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
675         str.append("RIssueTypeOption:\n");
676         str.append("IssueTypeId = ")
677                .append(getIssueTypeId())
678              .append("\n");
679         str.append("OptionId = ")
680                .append(getOptionId())
681              .append("\n");
682         str.append("Active = ")
683                .append(getActive())
684              .append("\n");
685         str.append("Locked = ")
686                .append(getLocked())
687              .append("\n");
688         str.append("Order = ")
689                .append(getOrder())
690              .append("\n");
691         str.append("Weight = ")
692                .append(getWeight())
693              .append("\n");
694         return(str.toString());
695     }
696 }
697
Popular Tags