KickJava   Java API By Example, From Geeks To Geeks.

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


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

34 public abstract class BaseAttributeValue extends BaseObject
35     implements org.apache.fulcrum.intake.Retrievable
36 {
37     /** The Peer class */
38     private static final AttributeValuePeer peer =
39         new AttributeValuePeer();
40
41         
42     /** The value for the valueId field */
43     private Long JavaDoc valueId;
44       
45     /** The value for the issueId field */
46     private Long JavaDoc issueId;
47       
48     /** The value for the attributeId field */
49     private Integer JavaDoc attributeId;
50       
51     /** The value for the numericValue field */
52     private Integer JavaDoc numericValue;
53       
54     /** The value for the optionId field */
55     private Integer JavaDoc optionId;
56       
57     /** The value for the userId field */
58     private Integer JavaDoc userId;
59       
60     /** The value for the value field */
61     private String JavaDoc value;
62                                                                 
63     /** The value for the deleted field */
64     private boolean deleted = false;
65   
66     
67     /**
68      * Get the ValueId
69      *
70      * @return Long
71      */

72     public Long JavaDoc getValueId()
73     {
74         return valueId;
75     }
76
77                         
78     /**
79      * Set the value of ValueId
80      *
81      * @param v new value
82      */

83     public void setValueId(Long JavaDoc v)
84     {
85     
86                   if (!ObjectUtils.equals(this.valueId, v))
87               {
88             this.valueId = v;
89             setModified(true);
90         }
91     
92           
93               }
94   
95     /**
96      * Get the IssueId
97      *
98      * @return Long
99      */

100     public Long JavaDoc getIssueId()
101     {
102         return issueId;
103     }
104
105                               
106     /**
107      * Set the value of IssueId
108      *
109      * @param v new value
110      */

111     public void setIssueId(Long JavaDoc v) throws TorqueException
112     {
113     
114                   if (!ObjectUtils.equals(this.issueId, v))
115               {
116             this.issueId = v;
117             setModified(true);
118         }
119     
120                                   
121                 if (aIssue != null && !ObjectUtils.equals(aIssue.getIssueId(), v))
122                 {
123             aIssue = null;
124         }
125       
126               }
127   
128     /**
129      * Get the AttributeId
130      *
131      * @return Integer
132      */

133     public Integer JavaDoc getAttributeId()
134     {
135         return attributeId;
136     }
137
138                               
139     /**
140      * Set the value of AttributeId
141      *
142      * @param v new value
143      */

144     public void setAttributeId(Integer JavaDoc v) throws TorqueException
145     {
146     
147                   if (!ObjectUtils.equals(this.attributeId, v))
148               {
149             this.attributeId = v;
150             setModified(true);
151         }
152     
153                                   
154                 if (aAttribute != null && !ObjectUtils.equals(aAttribute.getAttributeId(), v))
155                 {
156             aAttribute = null;
157         }
158       
159               }
160   
161     /**
162      * Get the NumericValue
163      *
164      * @return Integer
165      */

166     public Integer JavaDoc getNumericValue()
167     {
168         return numericValue;
169     }
170
171                         
172     /**
173      * Set the value of NumericValue
174      *
175      * @param v new value
176      */

177     public void setNumericValue(Integer JavaDoc v)
178     {
179     
180                   if (!ObjectUtils.equals(this.numericValue, v))
181               {
182             this.numericValue = v;
183             setModified(true);
184         }
185     
186           
187               }
188   
189     /**
190      * Get the OptionId
191      *
192      * @return Integer
193      */

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

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

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

238     public void setUserId(Integer JavaDoc v) throws TorqueException
239     {
240     
241                   if (!ObjectUtils.equals(this.userId, v))
242               {
243             this.userId = v;
244             setModified(true);
245         }
246     
247                                           
248                 if (aScarabUser != null && !ObjectUtils.equals(aScarabUser.getUserId(), v))
249                 {
250             aScarabUser = null;
251         }
252       
253               }
254   
255     /**
256      * Get the Value
257      *
258      * @return String
259      */

260     public String JavaDoc getValue()
261     {
262         return value;
263     }
264
265                         
266     /**
267      * Set the value of Value
268      *
269      * @param v new value
270      */

271     public void setValue(String JavaDoc v)
272     {
273     
274                   if (!ObjectUtils.equals(this.value, v))
275               {
276             this.value = v;
277             setModified(true);
278         }
279     
280           
281               }
282   
283     /**
284      * Get the Deleted
285      *
286      * @return boolean
287      */

288     public boolean getDeleted()
289     {
290         return deleted;
291     }
292
293                         
294     /**
295      * Set the value of Deleted
296      *
297      * @param v new value
298      */

299     public void setDeleted(boolean v)
300     {
301     
302                   if (this.deleted != v)
303               {
304             this.deleted = v;
305             setModified(true);
306         }
307     
308           
309               }
310   
311       
312         
313                   
314         private Issue aIssue;
315
316     /**
317      * Declares an association between this object and a Issue object
318      *
319      * @param v Issue
320      * @throws TorqueException
321      */

322     public void setIssue(Issue v) throws TorqueException
323     {
324             if (v == null)
325         {
326                   setIssueId((Long JavaDoc) null);
327               }
328         else
329         {
330             setIssueId(v.getIssueId());
331         }
332             aIssue = v;
333     }
334
335                         
336     /**
337      * Get the associated Issue object
338      *
339      * @return the associated Issue object
340      * @throws TorqueException
341      */

342     public Issue getIssue() throws TorqueException
343     {
344         if ( !ObjectUtils.equals(getIssueId(), null) )
345         {
346                 return IssueManager.getInstance(SimpleKey.keyFor(getIssueId()));
347             }
348         return aIssue;
349     }
350
351     /**
352      * Provides convenient way to set a relationship based on a
353      * ObjectKey, for example
354      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
355      *
356          */

357     public void setIssueKey(ObjectKey key) throws TorqueException
358     {
359     
360                     setIssueId(new Long JavaDoc(((NumberKey) key).longValue()));
361               }
362   
363         
364                   
365         private Attribute aAttribute;
366
367     /**
368      * Declares an association between this object and a Attribute object
369      *
370      * @param v Attribute
371      * @throws TorqueException
372      */

373     public void setAttribute(Attribute v) throws TorqueException
374     {
375             if (v == null)
376         {
377                   setAttributeId((Integer JavaDoc) null);
378               }
379         else
380         {
381             setAttributeId(v.getAttributeId());
382         }
383             aAttribute = v;
384     }
385
386                         
387     /**
388      * Get the associated Attribute object
389      *
390      * @return the associated Attribute object
391      * @throws TorqueException
392      */

393     public Attribute getAttribute() throws TorqueException
394     {
395         if ( !ObjectUtils.equals(getAttributeId(), null) )
396         {
397                 return AttributeManager.getInstance(SimpleKey.keyFor(getAttributeId()));
398             }
399         return aAttribute;
400     }
401
402     /**
403      * Provides convenient way to set a relationship based on a
404      * ObjectKey, for example
405      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
406      *
407          */

408     public void setAttributeKey(ObjectKey key) throws TorqueException
409     {
410     
411                     setAttributeId(new Integer JavaDoc(((NumberKey) key).intValue()));
412               }
413   
414         
415                   
416         private AttributeOption aAttributeOption;
417
418     /**
419      * Declares an association between this object and a AttributeOption object
420      *
421      * @param v AttributeOption
422      * @throws TorqueException
423      */

424     public void setAttributeOption(AttributeOption v) throws TorqueException
425     {
426             if (v == null)
427         {
428                   setOptionId((Integer JavaDoc) null);
429               }
430         else
431         {
432             setOptionId(v.getOptionId());
433         }
434             aAttributeOption = v;
435     }
436
437                         
438     /**
439      * Get the associated AttributeOption object
440      *
441      * @return the associated AttributeOption object
442      * @throws TorqueException
443      */

444     public AttributeOption getAttributeOption() throws TorqueException
445     {
446         if ( !ObjectUtils.equals(getOptionId(), null) )
447         {
448                 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getOptionId()));
449             }
450         return aAttributeOption;
451     }
452
453     /**
454      * Provides convenient way to set a relationship based on a
455      * ObjectKey, for example
456      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
457      *
458          */

459     public void setAttributeOptionKey(ObjectKey key) throws TorqueException
460     {
461     
462                     setOptionId(new Integer JavaDoc(((NumberKey) key).intValue()));
463               }
464   
465             
466                   
467         private ScarabUser aScarabUser;
468
469     /**
470      * Declares an association between this object and a ScarabUser object
471      *
472      * @param v ScarabUser
473      * @throws TorqueException
474      */

475     public void setScarabUser(ScarabUser v) throws TorqueException
476     {
477             if (v == null)
478         {
479                   setUserId((Integer JavaDoc) null);
480               }
481         else
482         {
483             setUserId(v.getUserId());
484         }
485             aScarabUser = v;
486     }
487
488                         
489     /**
490      * Get the associated ScarabUser object
491      *
492      * @return the associated ScarabUser object
493      * @throws TorqueException
494      */

495     public ScarabUser getScarabUser() throws TorqueException
496     {
497         if ( !ObjectUtils.equals(getUserId(), null) )
498         {
499                 return ScarabUserManager.getInstance(SimpleKey.keyFor(getUserId()));
500             }
501         return aScarabUser;
502     }
503
504     /**
505      * Provides convenient way to set a relationship based on a
506      * ObjectKey, for example
507      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
508      *
509          */

510     public void setScarabUserKey(ObjectKey key) throws TorqueException
511     {
512     
513                     setUserId(new Integer JavaDoc(((NumberKey) key).intValue()));
514               }
515      
516                 
517     private static List JavaDoc fieldNames = null;
518
519     /**
520      * Generate a list of field names.
521      *
522      * @return a list of field names
523      */

524     public static synchronized List JavaDoc getFieldNames()
525     {
526         if (fieldNames == null)
527         {
528             fieldNames = new ArrayList JavaDoc();
529               fieldNames.add("ValueId");
530               fieldNames.add("IssueId");
531               fieldNames.add("AttributeId");
532               fieldNames.add("NumericValue");
533               fieldNames.add("OptionId");
534               fieldNames.add("UserId");
535               fieldNames.add("Value");
536               fieldNames.add("Deleted");
537               fieldNames = Collections.unmodifiableList(fieldNames);
538         }
539         return fieldNames;
540     }
541
542     /**
543      * Retrieves a field from the object by name passed in as a String.
544      *
545      * @param name field name
546      * @return value
547      */

548     public Object JavaDoc getByName(String JavaDoc name)
549     {
550           if (name.equals("ValueId"))
551         {
552                 return getValueId();
553             }
554           if (name.equals("IssueId"))
555         {
556                 return getIssueId();
557             }
558           if (name.equals("AttributeId"))
559         {
560                 return getAttributeId();
561             }
562           if (name.equals("NumericValue"))
563         {
564                 return getNumericValue();
565             }
566           if (name.equals("OptionId"))
567         {
568                 return getOptionId();
569             }
570           if (name.equals("UserId"))
571         {
572                 return getUserId();
573             }
574           if (name.equals("Value"))
575         {
576                 return getValue();
577             }
578           if (name.equals("Deleted"))
579         {
580                 return Boolean.valueOf(getDeleted());
581             }
582           return null;
583     }
584     
585     /**
586      * Retrieves a field from the object by name passed in
587      * as a String. The String must be one of the static
588      * Strings defined in this Class' Peer.
589      *
590      * @param name peer name
591      * @return value
592      */

593     public Object JavaDoc getByPeerName(String JavaDoc name)
594     {
595           if (name.equals(AttributeValuePeer.VALUE_ID))
596         {
597                 return getValueId();
598             }
599           if (name.equals(AttributeValuePeer.ISSUE_ID))
600         {
601                 return getIssueId();
602             }
603           if (name.equals(AttributeValuePeer.ATTRIBUTE_ID))
604         {
605                 return getAttributeId();
606             }
607           if (name.equals(AttributeValuePeer.NUMERIC_VALUE))
608         {
609                 return getNumericValue();
610             }
611           if (name.equals(AttributeValuePeer.OPTION_ID))
612         {
613                 return getOptionId();
614             }
615           if (name.equals(AttributeValuePeer.USER_ID))
616         {
617                 return getUserId();
618             }
619           if (name.equals(AttributeValuePeer.VALUE))
620         {
621                 return getValue();
622             }
623           if (name.equals(AttributeValuePeer.DELETED))
624         {
625                 return Boolean.valueOf(getDeleted());
626             }
627           return null;
628     }
629
630     /**
631      * Retrieves a field from the object by Position as specified
632      * in the xml schema. Zero-based.
633      *
634      * @param pos position in xml schema
635      * @return value
636      */

637     public Object JavaDoc getByPosition(int pos)
638     {
639             if (pos == 0)
640         {
641                 return getValueId();
642             }
643               if (pos == 1)
644         {
645                 return getIssueId();
646             }
647               if (pos == 2)
648         {
649                 return getAttributeId();
650             }
651               if (pos == 3)
652         {
653                 return getNumericValue();
654             }
655               if (pos == 4)
656         {
657                 return getOptionId();
658             }
659               if (pos == 5)
660         {
661                 return getUserId();
662             }
663               if (pos == 6)
664         {
665                 return getValue();
666             }
667               if (pos == 7)
668         {
669                 return Boolean.valueOf(getDeleted());
670             }
671               return null;
672     }
673      
674     /**
675      * Stores the object in the database. If the object is new,
676      * it inserts it; otherwise an update is performed.
677      *
678      * @throws Exception
679      */

680     public void save() throws Exception JavaDoc
681     {
682           save(AttributeValuePeer.getMapBuilder()
683                 .getDatabaseMap().getName());
684       }
685
686     /**
687      * Stores the object in the database. If the object is new,
688      * it inserts it; otherwise an update is performed.
689        * Note: this code is here because the method body is
690      * auto-generated conditionally and therefore needs to be
691      * in this file instead of in the super class, BaseObject.
692        *
693      * @param dbName
694      * @throws TorqueException
695      */

696     public void save(String JavaDoc dbName) throws TorqueException
697     {
698         Connection JavaDoc con = null;
699           try
700         {
701             con = Transaction.begin(dbName);
702             save(con);
703             Transaction.commit(con);
704         }
705         catch(TorqueException e)
706         {
707             Transaction.safeRollback(con);
708             throw e;
709         }
710       }
711
712       /** flag to prevent endless save loop, if this object is referenced
713         by another object which falls in this transaction. */

714     private boolean alreadyInSave = false;
715       /**
716      * Stores the object in the database. If the object is new,
717      * it inserts it; otherwise an update is performed. This method
718      * is meant to be used as part of a transaction, otherwise use
719      * the save() method and the connection details will be handled
720      * internally
721      *
722      * @param con
723      * @throws TorqueException
724      */

725     public void save(Connection JavaDoc con) throws TorqueException
726     {
727           if (!alreadyInSave)
728         {
729             alreadyInSave = true;
730
731
732   
733             // If this object has been modified, then save it to the database.
734
if (isModified())
735             {
736                 if (isNew())
737                 {
738                     AttributeValuePeer.doInsert((AttributeValue)this, con);
739                     setNew(false);
740                 }
741                 else
742                 {
743                     AttributeValuePeer.doUpdate((AttributeValue)this, con);
744                 }
745
746                       if (isCacheOnSave())
747                 {
748                     AttributeValueManager.putInstance(this);
749                 }
750               }
751
752                       alreadyInSave = false;
753         }
754       }
755
756     /**
757      * Specify whether to cache the object after saving to the db.
758      * This method returns false
759      */

760     protected boolean isCacheOnSave()
761     {
762         return true;
763     }
764
765                   
766       /**
767      * Set the PrimaryKey using ObjectKey.
768      *
769      * @param valueId ObjectKey
770      */

771     public void setPrimaryKey(ObjectKey valueId)
772          {
773             setValueId(new Long JavaDoc(((NumberKey)valueId).longValue()));
774         }
775
776     /**
777      * Set the PrimaryKey using a String.
778      *
779      * @param key
780      */

781     public void setPrimaryKey(String JavaDoc key)
782     {
783             setValueId(new Long JavaDoc(key));
784         }
785
786   
787     /**
788      * returns an id that differentiates this object from others
789      * of its class.
790      */

791     public ObjectKey getPrimaryKey()
792     {
793           return SimpleKey.keyFor(getValueId());
794       }
795  
796     /**
797      * get an id that differentiates this object from others
798      * of its class.
799      */

800     public String JavaDoc getQueryKey()
801     {
802         if (getPrimaryKey() == null)
803         {
804             return "";
805         }
806         else
807         {
808             return getPrimaryKey().toString();
809         }
810     }
811
812     /**
813      * set an id that differentiates this object from others
814      * of its class.
815      */

816     public void setQueryKey(String JavaDoc key)
817         throws TorqueException
818     {
819         setPrimaryKey(key);
820     }
821
822     /**
823      * Makes a copy of this object.
824      * It creates a new object filling in the simple attributes.
825        * It then fills all the association collections and sets the
826      * related objects to isNew=true.
827        */

828       public AttributeValue copyInto(AttributeValue copyObj) throws TorqueException
829     {
830             copyObj.setValueId(valueId);
831           copyObj.setIssueId(issueId);
832           copyObj.setAttributeId(attributeId);
833           copyObj.setNumericValue(numericValue);
834           copyObj.setOptionId(optionId);
835           copyObj.setUserId(userId);
836           copyObj.setValue(value);
837           copyObj.setDeleted(deleted);
838   
839                       copyObj.setValueId((Long JavaDoc)null);
840                                                       
841                 return copyObj;
842     }
843
844     /**
845      * returns a peer instance associated with this om. Since Peer classes
846      * are not to have any instance attributes, this method returns the
847      * same instance for all member of this class. The method could therefore
848      * be static, but this would prevent one from overriding the behavior.
849      */

850     public AttributeValuePeer getPeer()
851     {
852         return peer;
853     }
854
855     public String JavaDoc toString()
856     {
857         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
858         str.append("AttributeValue:\n");
859         str.append("ValueId = ")
860                .append(getValueId())
861              .append("\n");
862         str.append("IssueId = ")
863                .append(getIssueId())
864              .append("\n");
865         str.append("AttributeId = ")
866                .append(getAttributeId())
867              .append("\n");
868         str.append("NumericValue = ")
869                .append(getNumericValue())
870              .append("\n");
871         str.append("OptionId = ")
872                .append(getOptionId())
873              .append("\n");
874         str.append("UserId = ")
875                .append(getUserId())
876              .append("\n");
877         str.append("Value = ")
878                .append(getValue())
879              .append("\n");
880         str.append("Deleted = ")
881                .append(getDeleted())
882              .append("\n");
883         return(str.toString());
884     }
885 }
886
Popular Tags