KickJava   Java API By Example, From Geeks To Geeks.

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


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 Report
33  */

34 public abstract class BaseReport extends BaseObject
35     implements org.apache.fulcrum.intake.Retrievable
36 {
37     /** The Peer class */
38     private static final ReportPeer peer =
39         new ReportPeer();
40
41         
42     /** The value for the reportId field */
43     private Integer JavaDoc reportId;
44       
45     /** The value for the userId field */
46     private Integer JavaDoc userId;
47       
48     /** The value for the moduleId field */
49     private Integer JavaDoc moduleId;
50       
51     /** The value for the issueTypeId field */
52     private Integer JavaDoc issueTypeId;
53       
54     /** The value for the name field */
55     private String JavaDoc name;
56       
57     /** The value for the description field */
58     private String JavaDoc description;
59       
60     /** The value for the queryString field */
61     private String JavaDoc queryString;
62       
63     /** The value for the scopeId field */
64     private Integer JavaDoc scopeId;
65                                                                 
66     /** The value for the deleted field */
67     private boolean deleted = false;
68       
69     /** The value for the createdDate field */
70     private Date JavaDoc createdDate;
71   
72     
73     /**
74      * Get the ReportId
75      *
76      * @return Integer
77      */

78     public Integer JavaDoc getReportId()
79     {
80         return reportId;
81     }
82
83                         
84     /**
85      * Set the value of ReportId
86      *
87      * @param v new value
88      */

89     public void setReportId(Integer JavaDoc v)
90     {
91     
92                   if (!ObjectUtils.equals(this.reportId, v))
93               {
94             this.reportId = v;
95             setModified(true);
96         }
97     
98           
99               }
100   
101     /**
102      * Get the UserId
103      *
104      * @return Integer
105      */

106     public Integer JavaDoc getUserId()
107     {
108         return userId;
109     }
110
111                               
112     /**
113      * Set the value of UserId
114      *
115      * @param v new value
116      */

117     public void setUserId(Integer JavaDoc v) throws TorqueException
118     {
119     
120                   if (!ObjectUtils.equals(this.userId, v))
121               {
122             this.userId = v;
123             setModified(true);
124         }
125     
126                                           
127                 if (aScarabUser != null && !ObjectUtils.equals(aScarabUser.getUserId(), v))
128                 {
129             aScarabUser = null;
130         }
131       
132               }
133   
134     /**
135      * Get the ModuleId
136      *
137      * @return Integer
138      */

139     public Integer JavaDoc getModuleId()
140     {
141         return moduleId;
142     }
143
144                               
145     /**
146      * Set the value of ModuleId
147      *
148      * @param v new value
149      */

150     public void setModuleId(Integer JavaDoc v) throws TorqueException
151     {
152     
153                   if (!ObjectUtils.equals(this.moduleId, v))
154               {
155             this.moduleId = v;
156             setModified(true);
157         }
158     
159                                           
160                 if (aModule != null && !ObjectUtils.equals(aModule.getModuleId(), v))
161                 {
162             aModule = null;
163         }
164       
165               }
166   
167     /**
168      * Get the IssueTypeId
169      *
170      * @return Integer
171      */

172     public Integer JavaDoc getIssueTypeId()
173     {
174         return issueTypeId;
175     }
176
177                               
178     /**
179      * Set the value of IssueTypeId
180      *
181      * @param v new value
182      */

183     public void setIssueTypeId(Integer JavaDoc v) throws TorqueException
184     {
185     
186                   if (!ObjectUtils.equals(this.issueTypeId, v))
187               {
188             this.issueTypeId = v;
189             setModified(true);
190         }
191     
192                                   
193                 if (aIssueType != null && !ObjectUtils.equals(aIssueType.getIssueTypeId(), v))
194                 {
195             aIssueType = null;
196         }
197       
198               }
199   
200     /**
201      * Get the Name
202      *
203      * @return String
204      */

205     public String JavaDoc getName()
206     {
207         return name;
208     }
209
210                         
211     /**
212      * Set the value of Name
213      *
214      * @param v new value
215      */

216     public void setName(String JavaDoc v)
217     {
218     
219                   if (!ObjectUtils.equals(this.name, v))
220               {
221             this.name = v;
222             setModified(true);
223         }
224     
225           
226               }
227   
228     /**
229      * Get the Description
230      *
231      * @return String
232      */

233     public String JavaDoc getDescription()
234     {
235         return description;
236     }
237
238                         
239     /**
240      * Set the value of Description
241      *
242      * @param v new value
243      */

244     public void setDescription(String JavaDoc v)
245     {
246     
247                   if (!ObjectUtils.equals(this.description, v))
248               {
249             this.description = v;
250             setModified(true);
251         }
252     
253           
254               }
255   
256     /**
257      * Get the QueryString
258      *
259      * @return String
260      */

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

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

289     public Integer JavaDoc getScopeId()
290     {
291         return scopeId;
292     }
293
294                               
295     /**
296      * Set the value of ScopeId
297      *
298      * @param v new value
299      */

300     public void setScopeId(Integer JavaDoc v) throws TorqueException
301     {
302     
303                   if (!ObjectUtils.equals(this.scopeId, v))
304               {
305             this.scopeId = v;
306             setModified(true);
307         }
308     
309                                   
310                 if (aScope != null && !ObjectUtils.equals(aScope.getScopeId(), v))
311                 {
312             aScope = null;
313         }
314       
315               }
316   
317     /**
318      * Get the Deleted
319      *
320      * @return boolean
321      */

322     public boolean getDeleted()
323     {
324         return deleted;
325     }
326
327                         
328     /**
329      * Set the value of Deleted
330      *
331      * @param v new value
332      */

333     public void setDeleted(boolean v)
334     {
335     
336                   if (this.deleted != v)
337               {
338             this.deleted = v;
339             setModified(true);
340         }
341     
342           
343               }
344   
345     /**
346      * Get the CreatedDate
347      *
348      * @return Date
349      */

350     public Date JavaDoc getCreatedDate()
351     {
352         return createdDate;
353     }
354
355                         
356     /**
357      * Set the value of CreatedDate
358      *
359      * @param v new value
360      */

361     public void setCreatedDate(Date JavaDoc v)
362     {
363     
364                   if (!ObjectUtils.equals(this.createdDate, v))
365               {
366             this.createdDate = v;
367             setModified(true);
368         }
369     
370           
371               }
372   
373       
374         
375                   
376         private IssueType aIssueType;
377
378     /**
379      * Declares an association between this object and a IssueType object
380      *
381      * @param v IssueType
382      * @throws TorqueException
383      */

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

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

419     public void setIssueTypeKey(ObjectKey key) throws TorqueException
420     {
421     
422                     setIssueTypeId(new Integer JavaDoc(((NumberKey) key).intValue()));
423               }
424   
425             
426                   
427         private ScarabUser aScarabUser;
428
429     /**
430      * Declares an association between this object and a ScarabUser object
431      *
432      * @param v ScarabUser
433      * @throws TorqueException
434      */

435     public void setScarabUser(ScarabUser v) throws TorqueException
436     {
437             if (v == null)
438         {
439                   setUserId((Integer JavaDoc) null);
440               }
441         else
442         {
443             setUserId(v.getUserId());
444         }
445             aScarabUser = v;
446     }
447
448                         
449     /**
450      * Get the associated ScarabUser object
451      *
452      * @return the associated ScarabUser object
453      * @throws TorqueException
454      */

455     public ScarabUser getScarabUser() throws TorqueException
456     {
457         if ( !ObjectUtils.equals(getUserId(), null) )
458         {
459                 return ScarabUserManager.getInstance(SimpleKey.keyFor(getUserId()));
460             }
461         return aScarabUser;
462     }
463
464     /**
465      * Provides convenient way to set a relationship based on a
466      * ObjectKey, for example
467      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
468      *
469          */

470     public void setScarabUserKey(ObjectKey key) throws TorqueException
471     {
472     
473                     setUserId(new Integer JavaDoc(((NumberKey) key).intValue()));
474               }
475   
476             
477                   
478         private Module aModule;
479
480     /**
481      * Declares an association between this object and a Module object
482      *
483      * @param v Module
484      * @throws TorqueException
485      */

486     public void setModule(Module v) throws TorqueException
487     {
488             if (v == null)
489         {
490                   setModuleId((Integer JavaDoc) null);
491               }
492         else
493         {
494             setModuleId(v.getModuleId());
495         }
496             aModule = v;
497     }
498
499                         
500     /**
501      * Get the associated Module object
502      *
503      * @return the associated Module object
504      * @throws TorqueException
505      */

506     public Module getModule() throws TorqueException
507     {
508         if ( !ObjectUtils.equals(getModuleId(), null) )
509         {
510                 return ModuleManager.getInstance(SimpleKey.keyFor(getModuleId()));
511             }
512         return aModule;
513     }
514
515     /**
516      * Provides convenient way to set a relationship based on a
517      * ObjectKey, for example
518      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
519      *
520          */

521     public void setModuleKey(ObjectKey key) throws TorqueException
522     {
523     
524                     setModuleId(new Integer JavaDoc(((NumberKey) key).intValue()));
525               }
526   
527         
528                   
529         private Scope aScope;
530
531     /**
532      * Declares an association between this object and a Scope object
533      *
534      * @param v Scope
535      * @throws TorqueException
536      */

537     public void setScope(Scope v) throws TorqueException
538     {
539             if (v == null)
540         {
541                   setScopeId((Integer JavaDoc) null);
542               }
543         else
544         {
545             setScopeId(v.getScopeId());
546         }
547             aScope = v;
548     }
549
550                         
551     /**
552      * Get the associated Scope object
553      *
554      * @return the associated Scope object
555      * @throws TorqueException
556      */

557     public Scope getScope() throws TorqueException
558     {
559         if ( !ObjectUtils.equals(getScopeId(), null) )
560         {
561                 return ScopeManager.getInstance(SimpleKey.keyFor(getScopeId()));
562             }
563         return aScope;
564     }
565
566     /**
567      * Provides convenient way to set a relationship based on a
568      * ObjectKey, for example
569      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
570      *
571          */

572     public void setScopeKey(ObjectKey key) throws TorqueException
573     {
574     
575                     setScopeId(new Integer JavaDoc(((NumberKey) key).intValue()));
576               }
577      
578                 
579     private static List JavaDoc fieldNames = null;
580
581     /**
582      * Generate a list of field names.
583      *
584      * @return a list of field names
585      */

586     public static synchronized List JavaDoc getFieldNames()
587     {
588         if (fieldNames == null)
589         {
590             fieldNames = new ArrayList JavaDoc();
591               fieldNames.add("ReportId");
592               fieldNames.add("UserId");
593               fieldNames.add("ModuleId");
594               fieldNames.add("IssueTypeId");
595               fieldNames.add("Name");
596               fieldNames.add("Description");
597               fieldNames.add("QueryString");
598               fieldNames.add("ScopeId");
599               fieldNames.add("Deleted");
600               fieldNames.add("CreatedDate");
601               fieldNames = Collections.unmodifiableList(fieldNames);
602         }
603         return fieldNames;
604     }
605
606     /**
607      * Retrieves a field from the object by name passed in as a String.
608      *
609      * @param name field name
610      * @return value
611      */

612     public Object JavaDoc getByName(String JavaDoc name)
613     {
614           if (name.equals("ReportId"))
615         {
616                 return getReportId();
617             }
618           if (name.equals("UserId"))
619         {
620                 return getUserId();
621             }
622           if (name.equals("ModuleId"))
623         {
624                 return getModuleId();
625             }
626           if (name.equals("IssueTypeId"))
627         {
628                 return getIssueTypeId();
629             }
630           if (name.equals("Name"))
631         {
632                 return getName();
633             }
634           if (name.equals("Description"))
635         {
636                 return getDescription();
637             }
638           if (name.equals("QueryString"))
639         {
640                 return getQueryString();
641             }
642           if (name.equals("ScopeId"))
643         {
644                 return getScopeId();
645             }
646           if (name.equals("Deleted"))
647         {
648                 return Boolean.valueOf(getDeleted());
649             }
650           if (name.equals("CreatedDate"))
651         {
652                 return getCreatedDate();
653             }
654           return null;
655     }
656     
657     /**
658      * Retrieves a field from the object by name passed in
659      * as a String. The String must be one of the static
660      * Strings defined in this Class' Peer.
661      *
662      * @param name peer name
663      * @return value
664      */

665     public Object JavaDoc getByPeerName(String JavaDoc name)
666     {
667           if (name.equals(ReportPeer.REPORT_ID))
668         {
669                 return getReportId();
670             }
671           if (name.equals(ReportPeer.USER_ID))
672         {
673                 return getUserId();
674             }
675           if (name.equals(ReportPeer.MODULE_ID))
676         {
677                 return getModuleId();
678             }
679           if (name.equals(ReportPeer.ISSUE_TYPE_ID))
680         {
681                 return getIssueTypeId();
682             }
683           if (name.equals(ReportPeer.NAME))
684         {
685                 return getName();
686             }
687           if (name.equals(ReportPeer.DESCRIPTION))
688         {
689                 return getDescription();
690             }
691           if (name.equals(ReportPeer.QUERY_STRING))
692         {
693                 return getQueryString();
694             }
695           if (name.equals(ReportPeer.SCOPE_ID))
696         {
697                 return getScopeId();
698             }
699           if (name.equals(ReportPeer.DELETED))
700         {
701                 return Boolean.valueOf(getDeleted());
702             }
703           if (name.equals(ReportPeer.CREATED_DATE))
704         {
705                 return getCreatedDate();
706             }
707           return null;
708     }
709
710     /**
711      * Retrieves a field from the object by Position as specified
712      * in the xml schema. Zero-based.
713      *
714      * @param pos position in xml schema
715      * @return value
716      */

717     public Object JavaDoc getByPosition(int pos)
718     {
719             if (pos == 0)
720         {
721                 return getReportId();
722             }
723               if (pos == 1)
724         {
725                 return getUserId();
726             }
727               if (pos == 2)
728         {
729                 return getModuleId();
730             }
731               if (pos == 3)
732         {
733                 return getIssueTypeId();
734             }
735               if (pos == 4)
736         {
737                 return getName();
738             }
739               if (pos == 5)
740         {
741                 return getDescription();
742             }
743               if (pos == 6)
744         {
745                 return getQueryString();
746             }
747               if (pos == 7)
748         {
749                 return getScopeId();
750             }
751               if (pos == 8)
752         {
753                 return Boolean.valueOf(getDeleted());
754             }
755               if (pos == 9)
756         {
757                 return getCreatedDate();
758             }
759               return null;
760     }
761      
762     /**
763      * Stores the object in the database. If the object is new,
764      * it inserts it; otherwise an update is performed.
765      *
766      * @throws Exception
767      */

768     public void save() throws Exception JavaDoc
769     {
770           save(ReportPeer.getMapBuilder()
771                 .getDatabaseMap().getName());
772       }
773
774     /**
775      * Stores the object in the database. If the object is new,
776      * it inserts it; otherwise an update is performed.
777        * Note: this code is here because the method body is
778      * auto-generated conditionally and therefore needs to be
779      * in this file instead of in the super class, BaseObject.
780        *
781      * @param dbName
782      * @throws TorqueException
783      */

784     public void save(String JavaDoc dbName) throws TorqueException
785     {
786         Connection JavaDoc con = null;
787           try
788         {
789             con = Transaction.begin(dbName);
790             save(con);
791             Transaction.commit(con);
792         }
793         catch(TorqueException e)
794         {
795             Transaction.safeRollback(con);
796             throw e;
797         }
798       }
799
800       /** flag to prevent endless save loop, if this object is referenced
801         by another object which falls in this transaction. */

802     private boolean alreadyInSave = false;
803       /**
804      * Stores the object in the database. If the object is new,
805      * it inserts it; otherwise an update is performed. This method
806      * is meant to be used as part of a transaction, otherwise use
807      * the save() method and the connection details will be handled
808      * internally
809      *
810      * @param con
811      * @throws TorqueException
812      */

813     public void save(Connection JavaDoc con) throws TorqueException
814     {
815           if (!alreadyInSave)
816         {
817             alreadyInSave = true;
818
819
820   
821             // If this object has been modified, then save it to the database.
822
if (isModified())
823             {
824                 if (isNew())
825                 {
826                     ReportPeer.doInsert((Report)this, con);
827                     setNew(false);
828                 }
829                 else
830                 {
831                     ReportPeer.doUpdate((Report)this, con);
832                 }
833
834                       if (isCacheOnSave())
835                 {
836                     ReportManager.putInstance(this);
837                 }
838               }
839
840                       alreadyInSave = false;
841         }
842       }
843
844     /**
845      * Specify whether to cache the object after saving to the db.
846      * This method returns false
847      */

848     protected boolean isCacheOnSave()
849     {
850         return true;
851     }
852
853                   
854       /**
855      * Set the PrimaryKey using ObjectKey.
856      *
857      * @param reportId ObjectKey
858      */

859     public void setPrimaryKey(ObjectKey reportId)
860          {
861             setReportId(new Integer JavaDoc(((NumberKey)reportId).intValue()));
862         }
863
864     /**
865      * Set the PrimaryKey using a String.
866      *
867      * @param key
868      */

869     public void setPrimaryKey(String JavaDoc key)
870     {
871             setReportId(new Integer JavaDoc(key));
872         }
873
874   
875     /**
876      * returns an id that differentiates this object from others
877      * of its class.
878      */

879     public ObjectKey getPrimaryKey()
880     {
881           return SimpleKey.keyFor(getReportId());
882       }
883  
884     /**
885      * get an id that differentiates this object from others
886      * of its class.
887      */

888     public String JavaDoc getQueryKey()
889     {
890         if (getPrimaryKey() == null)
891         {
892             return "";
893         }
894         else
895         {
896             return getPrimaryKey().toString();
897         }
898     }
899
900     /**
901      * set an id that differentiates this object from others
902      * of its class.
903      */

904     public void setQueryKey(String JavaDoc key)
905         throws TorqueException
906     {
907         setPrimaryKey(key);
908     }
909
910     /**
911      * Makes a copy of this object.
912      * It creates a new object filling in the simple attributes.
913        * It then fills all the association collections and sets the
914      * related objects to isNew=true.
915        */

916       public Report copy() throws TorqueException
917     {
918         Report copyObj = new Report();
919             copyObj.setReportId(reportId);
920           copyObj.setUserId(userId);
921           copyObj.setModuleId(moduleId);
922           copyObj.setIssueTypeId(issueTypeId);
923           copyObj.setName(name);
924           copyObj.setDescription(description);
925           copyObj.setQueryString(queryString);
926           copyObj.setScopeId(scopeId);
927           copyObj.setDeleted(deleted);
928           copyObj.setCreatedDate(createdDate);
929   
930                       copyObj.setReportId((Integer JavaDoc)null);
931                                                                   
932                 return copyObj;
933     }
934
935     /**
936      * returns a peer instance associated with this om. Since Peer classes
937      * are not to have any instance attributes, this method returns the
938      * same instance for all member of this class. The method could therefore
939      * be static, but this would prevent one from overriding the behavior.
940      */

941     public ReportPeer getPeer()
942     {
943         return peer;
944     }
945
946     public String JavaDoc toString()
947     {
948         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
949         str.append("Report:\n");
950         str.append("ReportId = ")
951                .append(getReportId())
952              .append("\n");
953         str.append("UserId = ")
954                .append(getUserId())
955              .append("\n");
956         str.append("ModuleId = ")
957                .append(getModuleId())
958              .append("\n");
959         str.append("IssueTypeId = ")
960                .append(getIssueTypeId())
961              .append("\n");
962         str.append("Name = ")
963                .append(getName())
964              .append("\n");
965         str.append("Description = ")
966                .append(getDescription())
967              .append("\n");
968         str.append("QueryString = ")
969                .append(getQueryString())
970              .append("\n");
971         str.append("ScopeId = ")
972                .append(getScopeId())
973              .append("\n");
974         str.append("Deleted = ")
975                .append(getDeleted())
976              .append("\n");
977         str.append("CreatedDate = ")
978                .append(getCreatedDate())
979              .append("\n");
980         return(str.toString());
981     }
982 }
983
Popular Tags