KickJava   Java API By Example, From Geeks To Geeks.

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


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

35 public abstract class BaseCondition extends BaseObject
36     implements org.apache.fulcrum.intake.Retrievable
37 {
38     /** The Peer class */
39     private static final ConditionPeer peer =
40         new ConditionPeer();
41
42         
43     /** The value for the conditionId field */
44     private Long JavaDoc conditionId;
45       
46     /** The value for the transitionId field */
47     private Integer JavaDoc transitionId;
48       
49     /** The value for the moduleId field */
50     private Integer JavaDoc moduleId;
51       
52     /** The value for the issueTypeId field */
53     private Integer JavaDoc issueTypeId;
54       
55     /** The value for the attributeId field */
56     private Integer JavaDoc attributeId;
57       
58     /** The value for the optionId field */
59     private Integer JavaDoc optionId;
60   
61     
62     /**
63      * Get the ConditionId
64      *
65      * @return Long
66      */

67     public Long JavaDoc getConditionId()
68     {
69         return conditionId;
70     }
71
72                         
73     /**
74      * Set the value of ConditionId
75      *
76      * @param v new value
77      */

78     public void setConditionId(Long JavaDoc v)
79     {
80     
81                   if (!ObjectUtils.equals(this.conditionId, v))
82               {
83             this.conditionId = v;
84             setModified(true);
85         }
86     
87           
88               }
89   
90     /**
91      * Get the TransitionId
92      *
93      * @return Integer
94      */

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

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

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

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

161     public Integer JavaDoc getIssueTypeId()
162     {
163         return issueTypeId;
164     }
165
166                               
167     /**
168      * Set the value of IssueTypeId
169      *
170      * @param v new value
171      */

172     public void setIssueTypeId(Integer JavaDoc v) throws TorqueException
173     {
174     
175                   if (!ObjectUtils.equals(this.issueTypeId, v))
176               {
177             this.issueTypeId = v;
178             setModified(true);
179         }
180     
181                                   
182                 if (aRModuleAttribute != null && !ObjectUtils.equals(aRModuleAttribute.getIssueTypeId(), v))
183                 {
184             aRModuleAttribute = null;
185         }
186       
187               }
188   
189     /**
190      * Get the AttributeId
191      *
192      * @return Integer
193      */

194     public Integer JavaDoc getAttributeId()
195     {
196         return attributeId;
197     }
198
199                               
200     /**
201      * Set the value of AttributeId
202      *
203      * @param v new value
204      */

205     public void setAttributeId(Integer JavaDoc v) throws TorqueException
206     {
207     
208                   if (!ObjectUtils.equals(this.attributeId, v))
209               {
210             this.attributeId = v;
211             setModified(true);
212         }
213     
214                                   
215                 if (aRModuleAttribute != null && !ObjectUtils.equals(aRModuleAttribute.getAttributeId(), v))
216                 {
217             aRModuleAttribute = null;
218         }
219       
220               }
221   
222     /**
223      * Get the OptionId
224      *
225      * @return Integer
226      */

227     public Integer JavaDoc getOptionId()
228     {
229         return optionId;
230     }
231
232                               
233     /**
234      * Set the value of OptionId
235      *
236      * @param v new value
237      */

238     public void setOptionId(Integer JavaDoc v) throws TorqueException
239     {
240     
241                   if (!ObjectUtils.equals(this.optionId, v))
242               {
243             this.optionId = v;
244             setModified(true);
245         }
246     
247                                   
248                 if (aAttributeOption != null && !ObjectUtils.equals(aAttributeOption.getOptionId(), v))
249                 {
250             aAttributeOption = null;
251         }
252       
253               }
254   
255       
256         
257                                       
258         private RModuleAttribute aRModuleAttribute;
259
260     /**
261      * Declares an association between this object and a RModuleAttribute object
262      *
263      * @param v RModuleAttribute
264      * @throws TorqueException
265      */

266     public void setRModuleAttribute(RModuleAttribute v) throws TorqueException
267     {
268             if (v == null)
269         {
270                   setModuleId((Integer JavaDoc) null);
271               }
272         else
273         {
274             setModuleId(v.getModuleId());
275         }
276             if (v == null)
277         {
278                   setAttributeId((Integer JavaDoc) null);
279               }
280         else
281         {
282             setAttributeId(v.getAttributeId());
283         }
284             if (v == null)
285         {
286                   setIssueTypeId((Integer JavaDoc) null);
287               }
288         else
289         {
290             setIssueTypeId(v.getIssueTypeId());
291         }
292             aRModuleAttribute = v;
293     }
294
295                                                         
296     /**
297      * Get the associated RModuleAttribute object
298      *
299      * @return the associated RModuleAttribute object
300      * @throws TorqueException
301      */

302     public RModuleAttribute getRModuleAttribute() throws TorqueException
303     {
304         if ( !ObjectUtils.equals(getModuleId(), null) && !ObjectUtils.equals(getAttributeId(), null) && !ObjectUtils.equals(getIssueTypeId(), null) )
305         {
306                 SimpleKey[] keys = { SimpleKey.keyFor(getModuleId()), SimpleKey.keyFor(getAttributeId()), SimpleKey.keyFor(getIssueTypeId()) };
307             return RModuleAttributeManager.getInstance(new ComboKey(keys));
308             }
309         return aRModuleAttribute;
310     }
311
312     /**
313      * Provides convenient way to set a relationship based on a
314      * ObjectKey, for example
315      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
316      *
317          * Note: It is important that the xml schema used to create this class
318      * maintains consistency in the order of related columns between
319      * SCARAB_CONDITION and SCARAB_R_MODULE_ATTRIBUTE.
320      * If for some reason this is impossible, this method should be
321      * overridden in <code>Condition</code>.
322          */

323     public void setRModuleAttributeKey(ObjectKey key) throws TorqueException
324     {
325             SimpleKey[] keys = (SimpleKey[])key.getValue();
326                             setModuleId(new Integer JavaDoc(((NumberKey) keys[0]).intValue()));
327         
328                               setAttributeId(new Integer JavaDoc(((NumberKey) keys[1]).intValue()));
329         
330                               setIssueTypeId(new Integer JavaDoc(((NumberKey) keys[2]).intValue()));
331         
332                       }
333   
334         
335                   
336         private Transition aTransition;
337
338     /**
339      * Declares an association between this object and a Transition object
340      *
341      * @param v Transition
342      * @throws TorqueException
343      */

344     public void setTransition(Transition v) throws TorqueException
345     {
346             if (v == null)
347         {
348                   setTransitionId((Integer JavaDoc) null);
349               }
350         else
351         {
352             setTransitionId(v.getTransitionId());
353         }
354             aTransition = v;
355     }
356
357                         
358     /**
359      * Get the associated Transition object
360      *
361      * @return the associated Transition object
362      * @throws TorqueException
363      */

364     public Transition getTransition() throws TorqueException
365     {
366         if ( !ObjectUtils.equals(getTransitionId(), null) )
367         {
368                 return TransitionManager.getInstance(SimpleKey.keyFor(getTransitionId()));
369             }
370         return aTransition;
371     }
372
373     /**
374      * Provides convenient way to set a relationship based on a
375      * ObjectKey, for example
376      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
377      *
378          */

379     public void setTransitionKey(ObjectKey key) throws TorqueException
380     {
381     
382                     setTransitionId(new Integer JavaDoc(((NumberKey) key).intValue()));
383               }
384   
385         
386                   
387         private Attribute aAttribute;
388
389     /**
390      * Declares an association between this object and a Attribute object
391      *
392      * @param v Attribute
393      * @throws TorqueException
394      */

395     public void setAttribute(Attribute v) throws TorqueException
396     {
397             if (v == null)
398         {
399                   setAttributeId((Integer JavaDoc) null);
400               }
401         else
402         {
403             setAttributeId(v.getAttributeId());
404         }
405             aAttribute = v;
406     }
407
408                         
409     /**
410      * Get the associated Attribute object
411      *
412      * @return the associated Attribute object
413      * @throws TorqueException
414      */

415     public Attribute getAttribute() throws TorqueException
416     {
417         if ( !ObjectUtils.equals(getAttributeId(), null) )
418         {
419                 return AttributeManager.getInstance(SimpleKey.keyFor(getAttributeId()));
420             }
421         return aAttribute;
422     }
423
424     /**
425      * Provides convenient way to set a relationship based on a
426      * ObjectKey, for example
427      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
428      *
429          */

430     public void setAttributeKey(ObjectKey key) throws TorqueException
431     {
432     
433                     setAttributeId(new Integer JavaDoc(((NumberKey) key).intValue()));
434               }
435   
436         
437                   
438         private AttributeOption aAttributeOption;
439
440     /**
441      * Declares an association between this object and a AttributeOption object
442      *
443      * @param v AttributeOption
444      * @throws TorqueException
445      */

446     public void setAttributeOption(AttributeOption v) throws TorqueException
447     {
448             if (v == null)
449         {
450                   setOptionId((Integer JavaDoc) null);
451               }
452         else
453         {
454             setOptionId(v.getOptionId());
455         }
456             aAttributeOption = v;
457     }
458
459                         
460     /**
461      * Get the associated AttributeOption object
462      *
463      * @return the associated AttributeOption object
464      * @throws TorqueException
465      */

466     public AttributeOption getAttributeOption() throws TorqueException
467     {
468         if ( !ObjectUtils.equals(getOptionId(), null) )
469         {
470                 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getOptionId()));
471             }
472         return aAttributeOption;
473     }
474
475     /**
476      * Provides convenient way to set a relationship based on a
477      * ObjectKey, for example
478      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
479      *
480          */

481     public void setAttributeOptionKey(ObjectKey key) throws TorqueException
482     {
483     
484                     setOptionId(new Integer JavaDoc(((NumberKey) key).intValue()));
485               }
486   
487         
488                             
489         private RModuleIssueType aRModuleIssueType;
490
491     /**
492      * Declares an association between this object and a RModuleIssueType object
493      *
494      * @param v RModuleIssueType
495      * @throws TorqueException
496      */

497     public void setRModuleIssueType(RModuleIssueType v) throws TorqueException
498     {
499             if (v == null)
500         {
501                   setModuleId((Integer JavaDoc) null);
502               }
503         else
504         {
505             setModuleId(v.getModuleId());
506         }
507             if (v == null)
508         {
509                   setIssueTypeId((Integer JavaDoc) null);
510               }
511         else
512         {
513             setIssueTypeId(v.getIssueTypeId());
514         }
515             aRModuleIssueType = v;
516     }
517
518                                         
519     /**
520      * Get the associated RModuleIssueType object
521      *
522      * @return the associated RModuleIssueType object
523      * @throws TorqueException
524      */

525     public RModuleIssueType getRModuleIssueType() throws TorqueException
526     {
527         if ( !ObjectUtils.equals(getModuleId(), null) && !ObjectUtils.equals(getIssueTypeId(), null) )
528         {
529                 SimpleKey[] keys = { SimpleKey.keyFor(getModuleId()), SimpleKey.keyFor(getIssueTypeId()) };
530             return RModuleIssueTypeManager.getInstance(new ComboKey(keys));
531             }
532         return aRModuleIssueType;
533     }
534
535     /**
536      * Provides convenient way to set a relationship based on a
537      * ObjectKey, for example
538      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
539      *
540          * Note: It is important that the xml schema used to create this class
541      * maintains consistency in the order of related columns between
542      * SCARAB_CONDITION and SCARAB_R_MODULE_ISSUE_TYPE.
543      * If for some reason this is impossible, this method should be
544      * overridden in <code>Condition</code>.
545          */

546     public void setRModuleIssueTypeKey(ObjectKey key) throws TorqueException
547     {
548             SimpleKey[] keys = (SimpleKey[])key.getValue();
549                             setModuleId(new Integer JavaDoc(((NumberKey) keys[0]).intValue()));
550         
551                               setIssueTypeId(new Integer JavaDoc(((NumberKey) keys[1]).intValue()));
552         
553                       }
554      
555                 
556     private static List JavaDoc fieldNames = null;
557
558     /**
559      * Generate a list of field names.
560      *
561      * @return a list of field names
562      */

563     public static synchronized List JavaDoc getFieldNames()
564     {
565         if (fieldNames == null)
566         {
567             fieldNames = new ArrayList JavaDoc();
568               fieldNames.add("ConditionId");
569               fieldNames.add("TransitionId");
570               fieldNames.add("ModuleId");
571               fieldNames.add("IssueTypeId");
572               fieldNames.add("AttributeId");
573               fieldNames.add("OptionId");
574               fieldNames = Collections.unmodifiableList(fieldNames);
575         }
576         return fieldNames;
577     }
578
579     /**
580      * Retrieves a field from the object by name passed in as a String.
581      *
582      * @param name field name
583      * @return value
584      */

585     public Object JavaDoc getByName(String JavaDoc name)
586     {
587           if (name.equals("ConditionId"))
588         {
589                 return getConditionId();
590             }
591           if (name.equals("TransitionId"))
592         {
593                 return getTransitionId();
594             }
595           if (name.equals("ModuleId"))
596         {
597                 return getModuleId();
598             }
599           if (name.equals("IssueTypeId"))
600         {
601                 return getIssueTypeId();
602             }
603           if (name.equals("AttributeId"))
604         {
605                 return getAttributeId();
606             }
607           if (name.equals("OptionId"))
608         {
609                 return getOptionId();
610             }
611           return null;
612     }
613     
614     /**
615      * Retrieves a field from the object by name passed in
616      * as a String. The String must be one of the static
617      * Strings defined in this Class' Peer.
618      *
619      * @param name peer name
620      * @return value
621      */

622     public Object JavaDoc getByPeerName(String JavaDoc name)
623     {
624           if (name.equals(ConditionPeer.CONDITION_ID))
625         {
626                 return getConditionId();
627             }
628           if (name.equals(ConditionPeer.TRANSITION_ID))
629         {
630                 return getTransitionId();
631             }
632           if (name.equals(ConditionPeer.MODULE_ID))
633         {
634                 return getModuleId();
635             }
636           if (name.equals(ConditionPeer.ISSUE_TYPE_ID))
637         {
638                 return getIssueTypeId();
639             }
640           if (name.equals(ConditionPeer.ATTRIBUTE_ID))
641         {
642                 return getAttributeId();
643             }
644           if (name.equals(ConditionPeer.OPTION_ID))
645         {
646                 return getOptionId();
647             }
648           return null;
649     }
650
651     /**
652      * Retrieves a field from the object by Position as specified
653      * in the xml schema. Zero-based.
654      *
655      * @param pos position in xml schema
656      * @return value
657      */

658     public Object JavaDoc getByPosition(int pos)
659     {
660             if (pos == 0)
661         {
662                 return getConditionId();
663             }
664               if (pos == 1)
665         {
666                 return getTransitionId();
667             }
668               if (pos == 2)
669         {
670                 return getModuleId();
671             }
672               if (pos == 3)
673         {
674                 return getIssueTypeId();
675             }
676               if (pos == 4)
677         {
678                 return getAttributeId();
679             }
680               if (pos == 5)
681         {
682                 return getOptionId();
683             }
684               return null;
685     }
686      
687     /**
688      * Stores the object in the database. If the object is new,
689      * it inserts it; otherwise an update is performed.
690      *
691      * @throws Exception
692      */

693     public void save() throws Exception JavaDoc
694     {
695           save(ConditionPeer.getMapBuilder()
696                 .getDatabaseMap().getName());
697       }
698
699     /**
700      * Stores the object in the database. If the object is new,
701      * it inserts it; otherwise an update is performed.
702        * Note: this code is here because the method body is
703      * auto-generated conditionally and therefore needs to be
704      * in this file instead of in the super class, BaseObject.
705        *
706      * @param dbName
707      * @throws TorqueException
708      */

709     public void save(String JavaDoc dbName) throws TorqueException
710     {
711         Connection JavaDoc con = null;
712           try
713         {
714             con = Transaction.begin(dbName);
715             save(con);
716             Transaction.commit(con);
717         }
718         catch(TorqueException e)
719         {
720             Transaction.safeRollback(con);
721             throw e;
722         }
723       }
724
725       /** flag to prevent endless save loop, if this object is referenced
726         by another object which falls in this transaction. */

727     private boolean alreadyInSave = false;
728       /**
729      * Stores the object in the database. If the object is new,
730      * it inserts it; otherwise an update is performed. This method
731      * is meant to be used as part of a transaction, otherwise use
732      * the save() method and the connection details will be handled
733      * internally
734      *
735      * @param con
736      * @throws TorqueException
737      */

738     public void save(Connection JavaDoc con) throws TorqueException
739     {
740           if (!alreadyInSave)
741         {
742             alreadyInSave = true;
743
744
745   
746             // If this object has been modified, then save it to the database.
747
if (isModified())
748             {
749                 if (isNew())
750                 {
751                     ConditionPeer.doInsert((Condition)this, con);
752                     setNew(false);
753                 }
754                 else
755                 {
756                     ConditionPeer.doUpdate((Condition)this, con);
757                 }
758
759                       if (isCacheOnSave())
760                 {
761                     ConditionManager.putInstance(this);
762                 }
763               }
764
765                       alreadyInSave = false;
766         }
767       }
768
769     /**
770      * Specify whether to cache the object after saving to the db.
771      * This method returns false
772      */

773     protected boolean isCacheOnSave()
774     {
775         return true;
776     }
777
778                   
779       /**
780      * Set the PrimaryKey using ObjectKey.
781      *
782      * @param conditionId ObjectKey
783      */

784     public void setPrimaryKey(ObjectKey conditionId)
785          {
786             setConditionId(new Long JavaDoc(((NumberKey)conditionId).longValue()));
787         }
788
789     /**
790      * Set the PrimaryKey using a String.
791      *
792      * @param key
793      */

794     public void setPrimaryKey(String JavaDoc key)
795     {
796             setConditionId(new Long JavaDoc(key));
797         }
798
799   
800     /**
801      * returns an id that differentiates this object from others
802      * of its class.
803      */

804     public ObjectKey getPrimaryKey()
805     {
806           return SimpleKey.keyFor(getConditionId());
807       }
808  
809     /**
810      * get an id that differentiates this object from others
811      * of its class.
812      */

813     public String JavaDoc getQueryKey()
814     {
815         if (getPrimaryKey() == null)
816         {
817             return "";
818         }
819         else
820         {
821             return getPrimaryKey().toString();
822         }
823     }
824
825     /**
826      * set an id that differentiates this object from others
827      * of its class.
828      */

829     public void setQueryKey(String JavaDoc key)
830         throws TorqueException
831     {
832         setPrimaryKey(key);
833     }
834
835     /**
836      * Makes a copy of this object.
837      * It creates a new object filling in the simple attributes.
838        * It then fills all the association collections and sets the
839      * related objects to isNew=true.
840        */

841       public Condition copy() throws TorqueException
842     {
843         Condition copyObj = new Condition();
844             copyObj.setConditionId(conditionId);
845           copyObj.setTransitionId(transitionId);
846           copyObj.setModuleId(moduleId);
847           copyObj.setIssueTypeId(issueTypeId);
848           copyObj.setAttributeId(attributeId);
849           copyObj.setOptionId(optionId);
850   
851                       copyObj.setConditionId((Long JavaDoc)null);
852                                           
853                 return copyObj;
854     }
855
856     /**
857      * returns a peer instance associated with this om. Since Peer classes
858      * are not to have any instance attributes, this method returns the
859      * same instance for all member of this class. The method could therefore
860      * be static, but this would prevent one from overriding the behavior.
861      */

862     public ConditionPeer getPeer()
863     {
864         return peer;
865     }
866
867     public String JavaDoc toString()
868     {
869         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
870         str.append("Condition:\n");
871         str.append("ConditionId = ")
872                .append(getConditionId())
873              .append("\n");
874         str.append("TransitionId = ")
875                .append(getTransitionId())
876              .append("\n");
877         str.append("ModuleId = ")
878                .append(getModuleId())
879              .append("\n");
880         str.append("IssueTypeId = ")
881                .append(getIssueTypeId())
882              .append("\n");
883         str.append("AttributeId = ")
884                .append(getAttributeId())
885              .append("\n");
886         str.append("OptionId = ")
887                .append(getOptionId())
888              .append("\n");
889         return(str.toString());
890     }
891 }
892
Popular Tags