KickJava   Java API By Example, From Geeks To Geeks.

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


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

36 public abstract class BaseQuery extends BaseObject
37     implements org.apache.fulcrum.intake.Retrievable
38 {
39     /** The Peer class */
40     private static final QueryPeer peer =
41         new QueryPeer();
42
43         
44     /** The value for the queryId field */
45     private Long JavaDoc queryId;
46       
47     /** The value for the userId field */
48     private Integer JavaDoc userId;
49       
50     /** The value for the name field */
51     private String JavaDoc name;
52       
53     /** The value for the description field */
54     private String JavaDoc description;
55       
56     /** The value for the value field */
57     private String JavaDoc value;
58       
59     /** The value for the scopeId field */
60     private Integer JavaDoc scopeId;
61       
62     /** The value for the issueTypeId field */
63     private Integer JavaDoc issueTypeId;
64       
65     /** The value for the moduleId field */
66     private Integer JavaDoc moduleId;
67       
68     /** The value for the listId field */
69     private Long JavaDoc listId;
70                                                                 
71     /** The value for the deleted field */
72     private boolean deleted = false;
73                                                                 
74     /** The value for the approved field */
75     private boolean approved = false;
76       
77     /** The value for the createdDate field */
78     private Date JavaDoc createdDate;
79       
80     /** The value for the subscriptionFrequencyId field */
81     private Integer JavaDoc subscriptionFrequencyId;
82                                                                 
83     /** The value for the homePage field */
84     private boolean homePage = false;
85                                           
86     /** The value for the order field */
87     private int order = 0;
88   
89     
90     /**
91      * Get the QueryId
92      *
93      * @return Long
94      */

95     public Long JavaDoc getQueryId()
96     {
97         return queryId;
98     }
99
100                                               
101     /**
102      * Set the value of QueryId
103      *
104      * @param v new value
105      */

106     public void setQueryId(Long JavaDoc v) throws TorqueException
107     {
108     
109                   if (!ObjectUtils.equals(this.queryId, v))
110               {
111             this.queryId = v;
112             setModified(true);
113         }
114     
115           
116                                   
117         // update associated RQueryUser
118
if (collRQueryUsers != null)
119         {
120             for (int i = 0; i < collRQueryUsers.size(); i++)
121             {
122                 ((RQueryUser) collRQueryUsers.get(i))
123                         .setQueryId(v);
124             }
125         }
126                       }
127   
128     /**
129      * Get the UserId
130      *
131      * @return Integer
132      */

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

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

166     public String JavaDoc getName()
167     {
168         return name;
169     }
170
171                         
172     /**
173      * Set the value of Name
174      *
175      * @param v new value
176      */

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

194     public String JavaDoc getDescription()
195     {
196         return description;
197     }
198
199                         
200     /**
201      * Set the value of Description
202      *
203      * @param v new value
204      */

205     public void setDescription(String JavaDoc v)
206     {
207     
208                   if (!ObjectUtils.equals(this.description, v))
209               {
210             this.description = v;
211             setModified(true);
212         }
213     
214           
215               }
216   
217     /**
218      * Get the Value
219      *
220      * @return String
221      */

222     public String JavaDoc getValue()
223     {
224         return value;
225     }
226
227                         
228     /**
229      * Set the value of Value
230      *
231      * @param v new value
232      */

233     public void setValue(String JavaDoc v)
234     {
235     
236                   if (!ObjectUtils.equals(this.value, v))
237               {
238             this.value = v;
239             setModified(true);
240         }
241     
242           
243               }
244   
245     /**
246      * Get the ScopeId
247      *
248      * @return Integer
249      */

250     public Integer JavaDoc getScopeId()
251     {
252         return scopeId;
253     }
254
255                               
256     /**
257      * Set the value of ScopeId
258      *
259      * @param v new value
260      */

261     public void setScopeId(Integer JavaDoc v) throws TorqueException
262     {
263     
264                   if (!ObjectUtils.equals(this.scopeId, v))
265               {
266             this.scopeId = v;
267             setModified(true);
268         }
269     
270                                   
271                 if (aScope != null && !ObjectUtils.equals(aScope.getScopeId(), v))
272                 {
273             aScope = null;
274         }
275       
276               }
277   
278     /**
279      * Get the IssueTypeId
280      *
281      * @return Integer
282      */

283     public Integer JavaDoc getIssueTypeId()
284     {
285         return issueTypeId;
286     }
287
288                               
289     /**
290      * Set the value of IssueTypeId
291      *
292      * @param v new value
293      */

294     public void setIssueTypeId(Integer JavaDoc v) throws TorqueException
295     {
296     
297                   if (!ObjectUtils.equals(this.issueTypeId, v))
298               {
299             this.issueTypeId = v;
300             setModified(true);
301         }
302     
303                                   
304                 if (aIssueType != null && !ObjectUtils.equals(aIssueType.getIssueTypeId(), v))
305                 {
306             aIssueType = null;
307         }
308       
309               }
310   
311     /**
312      * Get the ModuleId
313      *
314      * @return Integer
315      */

316     public Integer JavaDoc getModuleId()
317     {
318         return moduleId;
319     }
320
321                               
322     /**
323      * Set the value of ModuleId
324      *
325      * @param v new value
326      */

327     public void setModuleId(Integer JavaDoc v) throws TorqueException
328     {
329     
330                   if (!ObjectUtils.equals(this.moduleId, v))
331               {
332             this.moduleId = v;
333             setModified(true);
334         }
335     
336                                           
337                 if (aModule != null && !ObjectUtils.equals(aModule.getModuleId(), v))
338                 {
339             aModule = null;
340         }
341       
342               }
343   
344     /**
345      * Get the ListId
346      *
347      * @return Long
348      */

349     public Long JavaDoc getListId()
350     {
351         return listId;
352     }
353
354                               
355     /**
356      * Set the value of ListId
357      *
358      * @param v new value
359      */

360     public void setListId(Long JavaDoc v) throws TorqueException
361     {
362     
363                   if (!ObjectUtils.equals(this.listId, v))
364               {
365             this.listId = v;
366             setModified(true);
367         }
368     
369                                   
370                 if (aMITList != null && !ObjectUtils.equals(aMITList.getListId(), v))
371                 {
372             aMITList = null;
373         }
374       
375               }
376   
377     /**
378      * Get the Deleted
379      *
380      * @return boolean
381      */

382     public boolean getDeleted()
383     {
384         return deleted;
385     }
386
387                         
388     /**
389      * Set the value of Deleted
390      *
391      * @param v new value
392      */

393     public void setDeleted(boolean v)
394     {
395     
396                   if (this.deleted != v)
397               {
398             this.deleted = v;
399             setModified(true);
400         }
401     
402           
403               }
404   
405     /**
406      * Get the Approved
407      *
408      * @return boolean
409      */

410     public boolean getApproved()
411     {
412         return approved;
413     }
414
415                         
416     /**
417      * Set the value of Approved
418      *
419      * @param v new value
420      */

421     public void setApproved(boolean v)
422     {
423     
424                   if (this.approved != v)
425               {
426             this.approved = v;
427             setModified(true);
428         }
429     
430           
431               }
432   
433     /**
434      * Get the CreatedDate
435      *
436      * @return Date
437      */

438     public Date JavaDoc getCreatedDate()
439     {
440         return createdDate;
441     }
442
443                         
444     /**
445      * Set the value of CreatedDate
446      *
447      * @param v new value
448      */

449     public void setCreatedDate(Date JavaDoc v)
450     {
451     
452                   if (!ObjectUtils.equals(this.createdDate, v))
453               {
454             this.createdDate = v;
455             setModified(true);
456         }
457     
458           
459               }
460   
461     /**
462      * Get the SubscriptionFrequencyId
463      *
464      * @return Integer
465      */

466     public Integer JavaDoc getSubscriptionFrequencyId()
467     {
468         return subscriptionFrequencyId;
469     }
470
471                               
472     /**
473      * Set the value of SubscriptionFrequencyId
474      *
475      * @param v new value
476      */

477     public void setSubscriptionFrequencyId(Integer JavaDoc v) throws TorqueException
478     {
479     
480                   if (!ObjectUtils.equals(this.subscriptionFrequencyId, v))
481               {
482             this.subscriptionFrequencyId = v;
483             setModified(true);
484         }
485     
486                                   
487                 if (aFrequency != null && !ObjectUtils.equals(aFrequency.getFrequencyId(), v))
488                 {
489             aFrequency = null;
490         }
491       
492               }
493   
494     /**
495      * Get the HomePage
496      *
497      * @return boolean
498      */

499     public boolean getHomePage()
500     {
501         return homePage;
502     }
503
504                         
505     /**
506      * Set the value of HomePage
507      *
508      * @param v new value
509      */

510     public void setHomePage(boolean v)
511     {
512     
513                   if (this.homePage != v)
514               {
515             this.homePage = v;
516             setModified(true);
517         }
518     
519           
520               }
521   
522     /**
523      * Get the Order
524      *
525      * @return int
526      */

527     public int getOrder()
528     {
529         return order;
530     }
531
532                         
533     /**
534      * Set the value of Order
535      *
536      * @param v new value
537      */

538     public void setOrder(int v)
539     {
540     
541                   if (this.order != v)
542               {
543             this.order = v;
544             setModified(true);
545         }
546     
547           
548               }
549   
550       
551             
552                   
553         private ScarabUser aScarabUser;
554
555     /**
556      * Declares an association between this object and a ScarabUser object
557      *
558      * @param v ScarabUser
559      * @throws TorqueException
560      */

561     public void setScarabUser(ScarabUser v) throws TorqueException
562     {
563             if (v == null)
564         {
565                   setUserId((Integer JavaDoc) null);
566               }
567         else
568         {
569             setUserId(v.getUserId());
570         }
571             aScarabUser = v;
572     }
573
574                         
575     /**
576      * Get the associated ScarabUser object
577      *
578      * @return the associated ScarabUser object
579      * @throws TorqueException
580      */

581     public ScarabUser getScarabUser() throws TorqueException
582     {
583         if ( !ObjectUtils.equals(getUserId(), null) )
584         {
585                 return ScarabUserManager.getInstance(SimpleKey.keyFor(getUserId()));
586             }
587         return aScarabUser;
588     }
589
590     /**
591      * Provides convenient way to set a relationship based on a
592      * ObjectKey, for example
593      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
594      *
595          */

596     public void setScarabUserKey(ObjectKey key) throws TorqueException
597     {
598     
599                     setUserId(new Integer JavaDoc(((NumberKey) key).intValue()));
600               }
601   
602         
603                   
604         private Scope aScope;
605
606     /**
607      * Declares an association between this object and a Scope object
608      *
609      * @param v Scope
610      * @throws TorqueException
611      */

612     public void setScope(Scope v) throws TorqueException
613     {
614             if (v == null)
615         {
616                   setScopeId((Integer JavaDoc) null);
617               }
618         else
619         {
620             setScopeId(v.getScopeId());
621         }
622             aScope = v;
623     }
624
625                         
626     /**
627      * Get the associated Scope object
628      *
629      * @return the associated Scope object
630      * @throws TorqueException
631      */

632     public Scope getScope() throws TorqueException
633     {
634         if ( !ObjectUtils.equals(getScopeId(), null) )
635         {
636                 return ScopeManager.getInstance(SimpleKey.keyFor(getScopeId()));
637             }
638         return aScope;
639     }
640
641     /**
642      * Provides convenient way to set a relationship based on a
643      * ObjectKey, for example
644      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
645      *
646          */

647     public void setScopeKey(ObjectKey key) throws TorqueException
648     {
649     
650                     setScopeId(new Integer JavaDoc(((NumberKey) key).intValue()));
651               }
652   
653             
654                   
655         private Module aModule;
656
657     /**
658      * Declares an association between this object and a Module object
659      *
660      * @param v Module
661      * @throws TorqueException
662      */

663     public void setModule(Module v) throws TorqueException
664     {
665             if (v == null)
666         {
667                   setModuleId((Integer JavaDoc) null);
668               }
669         else
670         {
671             setModuleId(v.getModuleId());
672         }
673             aModule = v;
674     }
675
676                         
677     /**
678      * Get the associated Module object
679      *
680      * @return the associated Module object
681      * @throws TorqueException
682      */

683     public Module getModule() throws TorqueException
684     {
685         if ( !ObjectUtils.equals(getModuleId(), null) )
686         {
687                 return ModuleManager.getInstance(SimpleKey.keyFor(getModuleId()));
688             }
689         return aModule;
690     }
691
692     /**
693      * Provides convenient way to set a relationship based on a
694      * ObjectKey, for example
695      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
696      *
697          */

698     public void setModuleKey(ObjectKey key) throws TorqueException
699     {
700     
701                     setModuleId(new Integer JavaDoc(((NumberKey) key).intValue()));
702               }
703   
704         
705                   
706         private IssueType aIssueType;
707
708     /**
709      * Declares an association between this object and a IssueType object
710      *
711      * @param v IssueType
712      * @throws TorqueException
713      */

714     public void setIssueType(IssueType v) throws TorqueException
715     {
716             if (v == null)
717         {
718                   setIssueTypeId((Integer JavaDoc) null);
719               }
720         else
721         {
722             setIssueTypeId(v.getIssueTypeId());
723         }
724             aIssueType = v;
725     }
726
727                         
728     /**
729      * Get the associated IssueType object
730      *
731      * @return the associated IssueType object
732      * @throws TorqueException
733      */

734     public IssueType getIssueType() throws TorqueException
735     {
736         if ( !ObjectUtils.equals(getIssueTypeId(), null) )
737         {
738                 return IssueTypeManager.getInstance(SimpleKey.keyFor(getIssueTypeId()));
739             }
740         return aIssueType;
741     }
742
743     /**
744      * Provides convenient way to set a relationship based on a
745      * ObjectKey, for example
746      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
747      *
748          */

749     public void setIssueTypeKey(ObjectKey key) throws TorqueException
750     {
751     
752                     setIssueTypeId(new Integer JavaDoc(((NumberKey) key).intValue()));
753               }
754   
755         
756                   
757         private MITList aMITList;
758
759     /**
760      * Declares an association between this object and a MITList object
761      *
762      * @param v MITList
763      * @throws TorqueException
764      */

765     public void setMITList(MITList v) throws TorqueException
766     {
767             if (v == null)
768         {
769                   setListId((Long JavaDoc) null);
770               }
771         else
772         {
773             setListId(v.getListId());
774         }
775             aMITList = v;
776     }
777
778                         
779     /**
780      * Get the associated MITList object
781      *
782      * @return the associated MITList object
783      * @throws TorqueException
784      */

785     public MITList getMITList() throws TorqueException
786     {
787         if ( !ObjectUtils.equals(getListId(), null) )
788         {
789                 return MITListManager.getInstance(SimpleKey.keyFor(getListId()));
790             }
791         return aMITList;
792     }
793
794     /**
795      * Provides convenient way to set a relationship based on a
796      * ObjectKey, for example
797      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
798      *
799          */

800     public void setMITListKey(ObjectKey key) throws TorqueException
801     {
802     
803                     setListId(new Long JavaDoc(((NumberKey) key).longValue()));
804               }
805   
806         
807                   
808         private Frequency aFrequency;
809
810     /**
811      * Declares an association between this object and a Frequency object
812      *
813      * @param v Frequency
814      * @throws TorqueException
815      */

816     public void setFrequency(Frequency v) throws TorqueException
817     {
818             if (v == null)
819         {
820                   setSubscriptionFrequencyId((Integer JavaDoc) null);
821               }
822         else
823         {
824             setSubscriptionFrequencyId(v.getFrequencyId());
825         }
826             aFrequency = v;
827     }
828
829                         
830     /**
831      * Get the associated Frequency object
832      *
833      * @return the associated Frequency object
834      * @throws TorqueException
835      */

836     public Frequency getFrequency() throws TorqueException
837     {
838         if ( !ObjectUtils.equals(getSubscriptionFrequencyId(), null) )
839         {
840                 return FrequencyManager.getInstance(SimpleKey.keyFor(getSubscriptionFrequencyId()));
841             }
842         return aFrequency;
843     }
844
845     /**
846      * Provides convenient way to set a relationship based on a
847      * ObjectKey, for example
848      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
849      *
850          */

851     public void setFrequencyKey(ObjectKey key) throws TorqueException
852     {
853     
854                     setSubscriptionFrequencyId(new Integer JavaDoc(((NumberKey) key).intValue()));
855               }
856      
857                                 
858             
859     /**
860      * Collection to store aggregation of collRQueryUsers
861      */

862     protected List JavaDoc collRQueryUsers;
863
864     /**
865      * Temporary storage of collRQueryUsers to save a possible db hit in
866      * the event objects are add to the collection, but the
867      * complete collection is never requested.
868      */

869     protected void initRQueryUsers()
870     {
871         if (collRQueryUsers == null)
872         {
873             collRQueryUsers = new ArrayList JavaDoc();
874         }
875     }
876
877             
878     /**
879      * Method called to associate a RQueryUser object to this object
880      * through the RQueryUser foreign key attribute
881      *
882      * @param l RQueryUser
883      * @throws TorqueException
884      */

885     public void addRQueryUser(RQueryUser l) throws TorqueException
886     {
887         getRQueryUsers().add(l);
888         l.setQuery((Query)this);
889     }
890
891     /**
892      * The criteria used to select the current contents of collRQueryUsers
893      */

894     private Criteria lastRQueryUsersCriteria = null;
895
896     /**
897      * If this collection has already been initialized, returns
898      * the collection. Otherwise returns the results of
899      * getRQueryUsers(new Criteria())
900      *
901      * @throws TorqueException
902      */

903     public List JavaDoc getRQueryUsers() throws TorqueException
904     {
905         if (collRQueryUsers == null)
906         {
907             collRQueryUsers = getRQueryUsers(new Criteria(10));
908         }
909         return collRQueryUsers;
910     }
911
912     /**
913      * If this collection has already been initialized with
914      * an identical criteria, it returns the collection.
915      * Otherwise if this Query has previously
916      * been saved, it will retrieve related RQueryUsers from storage.
917      * If this Query is new, it will return
918      * an empty collection or the current collection, the criteria
919      * is ignored on a new object.
920      *
921      * @throws TorqueException
922      */

923     public List JavaDoc getRQueryUsers(Criteria criteria) throws TorqueException
924     {
925         if (collRQueryUsers == null)
926         {
927             if (isNew())
928             {
929                collRQueryUsers = new ArrayList JavaDoc();
930             }
931             else
932             {
933                       criteria.add(RQueryUserPeer.QUERY_ID, getQueryId() );
934                       collRQueryUsers = RQueryUserPeer.doSelect(criteria);
935             }
936         }
937         else
938         {
939             // criteria has no effect for a new object
940
if (!isNew())
941             {
942                 // the following code is to determine if a new query is
943
// called for. If the criteria is the same as the last
944
// one, just return the collection.
945
criteria.add(RQueryUserPeer.QUERY_ID, getQueryId() );
946                       if (!lastRQueryUsersCriteria.equals(criteria))
947                 {
948                     collRQueryUsers = RQueryUserPeer.doSelect(criteria);
949                 }
950             }
951         }
952         lastRQueryUsersCriteria = criteria;
953
954         return collRQueryUsers;
955     }
956
957     /**
958      * If this collection has already been initialized, returns
959      * the collection. Otherwise returns the results of
960      * getRQueryUsers(new Criteria(),Connection)
961      * This method takes in the Connection also as input so that
962      * referenced objects can also be obtained using a Connection
963      * that is taken as input
964      */

965     public List JavaDoc getRQueryUsers(Connection JavaDoc con) throws TorqueException
966     {
967         if (collRQueryUsers == null)
968         {
969             collRQueryUsers = getRQueryUsers(new Criteria(10),con);
970         }
971         return collRQueryUsers;
972     }
973
974     /**
975      * If this collection has already been initialized with
976      * an identical criteria, it returns the collection.
977      * Otherwise if this Query has previously
978      * been saved, it will retrieve related RQueryUsers from storage.
979      * If this Query is new, it will return
980      * an empty collection or the current collection, the criteria
981      * is ignored on a new object.
982      * This method takes in the Connection also as input so that
983      * referenced objects can also be obtained using a Connection
984      * that is taken as input
985      */

986     public List JavaDoc getRQueryUsers(Criteria criteria,Connection JavaDoc con) throws TorqueException
987     {
988         if (collRQueryUsers == null)
989         {
990             if (isNew())
991             {
992                collRQueryUsers = new ArrayList JavaDoc();
993             }
994             else
995             {
996                        criteria.add(RQueryUserPeer.QUERY_ID, getQueryId() );
997                        collRQueryUsers = RQueryUserPeer.doSelect(criteria,con);
998              }
999          }
1000         else
1001         {
1002             // criteria has no effect for a new object
1003
if (!isNew())
1004             {
1005                 // the following code is to determine if a new query is
1006
// called for. If the criteria is the same as the last
1007
// one, just return the collection.
1008
criteria.add(RQueryUserPeer.QUERY_ID, getQueryId() );
1009                     if (!lastRQueryUsersCriteria.equals(criteria))
1010                 {
1011                     collRQueryUsers = RQueryUserPeer.doSelect(criteria,con);
1012                 }
1013             }
1014         }
1015         lastRQueryUsersCriteria = criteria;
1016
1017         return collRQueryUsers;
1018     }
1019
1020                              
1021              
1022                    
1023                              
1024                                
1025                                                              
1026                                        
1027                    
1028                    
1029          
1030    /**
1031     * If this collection has already been initialized with
1032     * an identical criteria, it returns the collection.
1033     * Otherwise if this Query is new, it will return
1034     * an empty collection; or if this Query has previously
1035     * been saved, it will retrieve related RQueryUsers from storage.
1036     *
1037     * This method is protected by default in order to keep the public
1038     * api reasonable. You can provide public methods for those you
1039     * actually need in Query.
1040     */

1041    protected List JavaDoc getRQueryUsersJoinQuery(Criteria criteria)
1042        throws TorqueException
1043    {
1044        if (collRQueryUsers == null)
1045        {
1046            if (isNew())
1047            {
1048               collRQueryUsers = new ArrayList JavaDoc();
1049            }
1050            else
1051            {
1052                            criteria.add(RQueryUserPeer.QUERY_ID, getQueryId() );
1053                            collRQueryUsers = RQueryUserPeer.doSelectJoinQuery(criteria);
1054            }
1055        }
1056        else
1057        {
1058            // the following code is to determine if a new query is
1059
// called for. If the criteria is the same as the last
1060
// one, just return the collection.
1061

1062                            criteria.add(RQueryUserPeer.QUERY_ID, getQueryId() );
1063                        if (!lastRQueryUsersCriteria.equals(criteria))
1064            {
1065                collRQueryUsers = RQueryUserPeer.doSelectJoinQuery(criteria);
1066            }
1067        }
1068        lastRQueryUsersCriteria = criteria;
1069
1070        return collRQueryUsers;
1071    }
1072                  
1073                    
1074                    
1075                                
1076                                                              
1077                                        
1078                    
1079                    
1080          
1081    /**
1082     * If this collection has already been initialized with
1083     * an identical criteria, it returns the collection.
1084     * Otherwise if this Query is new, it will return
1085     * an empty collection; or if this Query has previously
1086     * been saved, it will retrieve related RQueryUsers from storage.
1087     *
1088     * This method is protected by default in order to keep the public
1089     * api reasonable. You can provide public methods for those you
1090     * actually need in Query.
1091     */

1092    protected List JavaDoc getRQueryUsersJoinScarabUserImpl(Criteria criteria)
1093        throws TorqueException
1094    {
1095        if (collRQueryUsers == null)
1096        {
1097            if (isNew())
1098            {
1099               collRQueryUsers = new ArrayList JavaDoc();
1100            }
1101            else
1102            {
1103                            criteria.add(RQueryUserPeer.QUERY_ID, getQueryId() );
1104                            collRQueryUsers = RQueryUserPeer.doSelectJoinScarabUserImpl(criteria);
1105            }
1106        }
1107        else
1108        {
1109            // the following code is to determine if a new query is
1110
// called for. If the criteria is the same as the last
1111
// one, just return the collection.
1112

1113                            criteria.add(RQueryUserPeer.QUERY_ID, getQueryId() );
1114                        if (!lastRQueryUsersCriteria.equals(criteria))
1115            {
1116                collRQueryUsers = RQueryUserPeer.doSelectJoinScarabUserImpl(criteria);
1117            }
1118        }
1119        lastRQueryUsersCriteria = criteria;
1120
1121        return collRQueryUsers;
1122    }
1123                  
1124                    
1125                    
1126                                
1127                                                              
1128                                        
1129                    
1130                    
1131          
1132    /**
1133     * If this collection has already been initialized with
1134     * an identical criteria, it returns the collection.
1135     * Otherwise if this Query is new, it will return
1136     * an empty collection; or if this Query has previously
1137     * been saved, it will retrieve related RQueryUsers from storage.
1138     *
1139     * This method is protected by default in order to keep the public
1140     * api reasonable. You can provide public methods for those you
1141     * actually need in Query.
1142     */

1143    protected List JavaDoc getRQueryUsersJoinFrequency(Criteria criteria)
1144        throws TorqueException
1145    {
1146        if (collRQueryUsers == null)
1147        {
1148            if (isNew())
1149            {
1150               collRQueryUsers = new ArrayList JavaDoc();
1151            }
1152            else
1153            {
1154                            criteria.add(RQueryUserPeer.QUERY_ID, getQueryId() );
1155                            collRQueryUsers = RQueryUserPeer.doSelectJoinFrequency(criteria);
1156            }
1157        }
1158        else
1159        {
1160            // the following code is to determine if a new query is
1161
// called for. If the criteria is the same as the last
1162
// one, just return the collection.
1163

1164                            criteria.add(RQueryUserPeer.QUERY_ID, getQueryId() );
1165                        if (!lastRQueryUsersCriteria.equals(criteria))
1166            {
1167                collRQueryUsers = RQueryUserPeer.doSelectJoinFrequency(criteria);
1168            }
1169        }
1170        lastRQueryUsersCriteria = criteria;
1171
1172        return collRQueryUsers;
1173    }
1174                            
1175
1176
1177          
1178    private static List JavaDoc fieldNames = null;
1179
1180    /**
1181     * Generate a list of field names.
1182     *
1183     * @return a list of field names
1184     */

1185    public static synchronized List JavaDoc getFieldNames()
1186    {
1187        if (fieldNames == null)
1188        {
1189            fieldNames = new ArrayList JavaDoc();
1190              fieldNames.add("QueryId");
1191              fieldNames.add("UserId");
1192              fieldNames.add("Name");
1193              fieldNames.add("Description");
1194              fieldNames.add("Value");
1195              fieldNames.add("ScopeId");
1196              fieldNames.add("IssueTypeId");
1197              fieldNames.add("ModuleId");
1198              fieldNames.add("ListId");
1199              fieldNames.add("Deleted");
1200              fieldNames.add("Approved");
1201              fieldNames.add("CreatedDate");
1202              fieldNames.add("SubscriptionFrequencyId");
1203              fieldNames.add("HomePage");
1204              fieldNames.add("Order");
1205              fieldNames = Collections.unmodifiableList(fieldNames);
1206        }
1207        return fieldNames;
1208    }
1209
1210    /**
1211     * Retrieves a field from the object by name passed in as a String.
1212     *
1213     * @param name field name
1214     * @return value
1215     */

1216    public Object JavaDoc getByName(String JavaDoc name)
1217    {
1218          if (name.equals("QueryId"))
1219        {
1220                return getQueryId();
1221            }
1222          if (name.equals("UserId"))
1223        {
1224                return getUserId();
1225            }
1226          if (name.equals("Name"))
1227        {
1228                return getName();
1229            }
1230          if (name.equals("Description"))
1231        {
1232                return getDescription();
1233            }
1234          if (name.equals("Value"))
1235        {
1236                return getValue();
1237            }
1238          if (name.equals("ScopeId"))
1239        {
1240                return getScopeId();
1241            }
1242          if (name.equals("IssueTypeId"))
1243        {
1244                return getIssueTypeId();
1245            }
1246          if (name.equals("ModuleId"))
1247        {
1248                return getModuleId();
1249            }
1250          if (name.equals("ListId"))
1251        {
1252                return getListId();
1253            }
1254          if (name.equals("Deleted"))
1255        {
1256                return Boolean.valueOf(getDeleted());
1257            }
1258          if (name.equals("Approved"))
1259        {
1260                return Boolean.valueOf(getApproved());
1261            }
1262          if (name.equals("CreatedDate"))
1263        {
1264                return getCreatedDate();
1265            }
1266          if (name.equals("SubscriptionFrequencyId"))
1267        {
1268                return getSubscriptionFrequencyId();
1269            }
1270          if (name.equals("HomePage"))
1271        {
1272                return Boolean.valueOf(getHomePage());
1273            }
1274          if (name.equals("Order"))
1275        {
1276                return new Integer JavaDoc(getOrder());
1277            }
1278          return null;
1279    }
1280    
1281    /**
1282     * Retrieves a field from the object by name passed in
1283     * as a String. The String must be one of the static
1284     * Strings defined in this Class' Peer.
1285     *
1286     * @param name peer name
1287     * @return value
1288     */

1289    public Object JavaDoc getByPeerName(String JavaDoc name)
1290    {
1291          if (name.equals(QueryPeer.QUERY_ID))
1292        {
1293                return getQueryId();
1294            }
1295          if (name.equals(QueryPeer.USER_ID))
1296        {
1297                return getUserId();
1298            }
1299          if (name.equals(QueryPeer.NAME))
1300        {
1301                return getName();
1302            }
1303          if (name.equals(QueryPeer.DESCRIPTION))
1304        {
1305                return getDescription();
1306            }
1307          if (name.equals(QueryPeer.VALUE))
1308        {
1309                return getValue();
1310            }
1311          if (name.equals(QueryPeer.SCOPE_ID))
1312        {
1313                return getScopeId();
1314            }
1315          if (name.equals(QueryPeer.ISSUE_TYPE_ID))
1316        {
1317                return getIssueTypeId();
1318            }
1319          if (name.equals(QueryPeer.MODULE_ID))
1320        {
1321                return getModuleId();
1322            }
1323          if (name.equals(QueryPeer.LIST_ID))
1324        {
1325                return getListId();
1326            }
1327          if (name.equals(QueryPeer.DELETED))
1328        {
1329                return Boolean.valueOf(getDeleted());
1330            }
1331          if (name.equals(QueryPeer.APPROVED))
1332        {
1333                return Boolean.valueOf(getApproved());
1334            }
1335          if (name.equals(QueryPeer.CREATED_DATE))
1336        {
1337                return getCreatedDate();
1338            }
1339          if (name.equals(QueryPeer.SUBSCRIPTION_FREQUENCY_ID))
1340        {
1341                return getSubscriptionFrequencyId();
1342            }
1343          if (name.equals(QueryPeer.HOME_PAGE))
1344        {
1345                return Boolean.valueOf(getHomePage());
1346            }
1347          if (name.equals(QueryPeer.PREFERRED_ORDER))
1348        {
1349                return new Integer JavaDoc(getOrder());
1350            }
1351          return null;
1352    }
1353
1354    /**
1355     * Retrieves a field from the object by Position as specified
1356     * in the xml schema. Zero-based.
1357     *
1358     * @param pos position in xml schema
1359     * @return value
1360     */

1361    public Object JavaDoc getByPosition(int pos)
1362    {
1363            if (pos == 0)
1364        {
1365                return getQueryId();
1366            }
1367              if (pos == 1)
1368        {
1369                return getUserId();
1370            }
1371              if (pos == 2)
1372        {
1373                return getName();
1374            }
1375              if (pos == 3)
1376        {
1377                return getDescription();
1378            }
1379              if (pos == 4)
1380        {
1381                return getValue();
1382            }
1383              if (pos == 5)
1384        {
1385                return getScopeId();
1386            }
1387              if (pos == 6)
1388        {
1389                return getIssueTypeId();
1390            }
1391              if (pos == 7)
1392        {
1393                return getModuleId();
1394            }
1395              if (pos == 8)
1396        {
1397                return getListId();
1398            }
1399              if (pos == 9)
1400        {
1401                return Boolean.valueOf(getDeleted());
1402            }
1403              if (pos == 10)
1404        {
1405                return Boolean.valueOf(getApproved());
1406            }
1407              if (pos == 11)
1408        {
1409                return getCreatedDate();
1410            }
1411              if (pos == 12)
1412        {
1413                return getSubscriptionFrequencyId();
1414            }
1415              if (pos == 13)
1416        {
1417                return Boolean.valueOf(getHomePage());
1418            }
1419              if (pos == 14)
1420        {
1421                return new Integer JavaDoc(getOrder());
1422            }
1423              return null;
1424    }
1425     
1426    /**
1427     * Stores the object in the database. If the object is new,
1428     * it inserts it; otherwise an update is performed.
1429     *
1430     * @throws Exception
1431     */

1432    public void save() throws Exception JavaDoc
1433    {
1434          save(QueryPeer.getMapBuilder()
1435                .getDatabaseMap().getName());
1436      }
1437
1438    /**
1439     * Stores the object in the database. If the object is new,
1440     * it inserts it; otherwise an update is performed.
1441       * Note: this code is here because the method body is
1442     * auto-generated conditionally and therefore needs to be
1443     * in this file instead of in the super class, BaseObject.
1444       *
1445     * @param dbName
1446     * @throws TorqueException
1447     */

1448    public void save(String JavaDoc dbName) throws TorqueException
1449    {
1450        Connection JavaDoc con = null;
1451          try
1452        {
1453            con = Transaction.begin(dbName);
1454            save(con);
1455            Transaction.commit(con);
1456        }
1457        catch(TorqueException e)
1458        {
1459            Transaction.safeRollback(con);
1460            throw e;
1461        }
1462      }
1463
1464      /** flag to prevent endless save loop, if this object is referenced
1465        by another object which falls in this transaction. */

1466    private boolean alreadyInSave = false;
1467      /**
1468     * Stores the object in the database. If the object is new,
1469     * it inserts it; otherwise an update is performed. This method
1470     * is meant to be used as part of a transaction, otherwise use
1471     * the save() method and the connection details will be handled
1472     * internally
1473     *
1474     * @param con
1475     * @throws TorqueException
1476     */

1477    public void save(Connection JavaDoc con) throws TorqueException
1478    {
1479          if (!alreadyInSave)
1480        {
1481            alreadyInSave = true;
1482
1483
1484  
1485            // If this object has been modified, then save it to the database.
1486
if (isModified())
1487            {
1488                if (isNew())
1489                {
1490                    QueryPeer.doInsert((Query)this, con);
1491                    setNew(false);
1492                }
1493                else
1494                {
1495                    QueryPeer.doUpdate((Query)this, con);
1496                }
1497
1498                      if (isCacheOnSave())
1499                {
1500                    QueryManager.putInstance(this);
1501                }
1502              }
1503
1504                                      
1505                            if (collRQueryUsers != null)
1506            {
1507                for (int i = 0; i < collRQueryUsers.size(); i++)
1508                {
1509                    ((RQueryUser)collRQueryUsers.get(i)).save(con);
1510                }
1511            }
1512                          alreadyInSave = false;
1513        }
1514      }
1515
1516    /**
1517     * Specify whether to cache the object after saving to the db.
1518     * This method returns false
1519     */

1520    protected boolean isCacheOnSave()
1521    {
1522        return true;
1523    }
1524
1525                        
1526      /**
1527     * Set the PrimaryKey using ObjectKey.
1528     *
1529     * @param queryId ObjectKey
1530     */

1531    public void setPrimaryKey(ObjectKey queryId)
1532        throws TorqueException {
1533            setQueryId(new Long JavaDoc(((NumberKey)queryId).longValue()));
1534        }
1535
1536    /**
1537     * Set the PrimaryKey using a String.
1538     *
1539     * @param key
1540     */

1541    public void setPrimaryKey(String JavaDoc key) throws TorqueException
1542    {
1543            setQueryId(new Long JavaDoc(key));
1544        }
1545
1546  
1547    /**
1548     * returns an id that differentiates this object from others
1549     * of its class.
1550     */

1551    public ObjectKey getPrimaryKey()
1552    {
1553          return SimpleKey.keyFor(getQueryId());
1554      }
1555 
1556    /**
1557     * get an id that differentiates this object from others
1558     * of its class.
1559     */

1560    public String JavaDoc getQueryKey()
1561    {
1562        if (getPrimaryKey() == null)
1563        {
1564            return "";
1565        }
1566        else
1567        {
1568            return getPrimaryKey().toString();
1569        }
1570    }
1571
1572    /**
1573     * set an id that differentiates this object from others
1574     * of its class.
1575     */

1576    public void setQueryKey(String JavaDoc key)
1577        throws TorqueException
1578    {
1579        setPrimaryKey(key);
1580    }
1581
1582    /**
1583     * Makes a copy of this object.
1584     * It creates a new object filling in the simple attributes.
1585       * It then fills all the association collections and sets the
1586     * related objects to isNew=true.
1587       */

1588      public Query copy() throws TorqueException
1589    {
1590        Query copyObj = new Query();
1591            copyObj.setQueryId(queryId);
1592          copyObj.setUserId(userId);
1593          copyObj.setName(name);
1594          copyObj.setDescription(description);
1595          copyObj.setValue(value);
1596          copyObj.setScopeId(scopeId);
1597          copyObj.setIssueTypeId(issueTypeId);
1598          copyObj.setModuleId(moduleId);
1599          copyObj.setListId(listId);
1600          copyObj.setDeleted(deleted);
1601          copyObj.setApproved(approved);
1602          copyObj.setCreatedDate(createdDate);
1603          copyObj.setSubscriptionFrequencyId(subscriptionFrequencyId);
1604          copyObj.setHomePage(homePage);
1605          copyObj.setOrder(order);
1606  
1607                      copyObj.setQueryId((Long JavaDoc)null);
1608                                                                                                
1609                                      
1610                
1611        List JavaDoc v = getRQueryUsers();
1612        for (int i = 0; i < v.size(); i++)
1613        {
1614            RQueryUser obj = (RQueryUser) v.get(i);
1615            copyObj.addRQueryUser(obj.copy());
1616        }
1617                            return copyObj;
1618    }
1619
1620    /**
1621     * returns a peer instance associated with this om. Since Peer classes
1622     * are not to have any instance attributes, this method returns the
1623     * same instance for all member of this class. The method could therefore
1624     * be static, but this would prevent one from overriding the behavior.
1625     */

1626    public QueryPeer getPeer()
1627    {
1628        return peer;
1629    }
1630
1631    public String JavaDoc toString()
1632    {
1633        StringBuffer JavaDoc str = new StringBuffer JavaDoc();
1634        str.append("Query:\n");
1635        str.append("QueryId = ")
1636               .append(getQueryId())
1637             .append("\n");
1638        str.append("UserId = ")
1639               .append(getUserId())
1640             .append("\n");
1641        str.append("Name = ")
1642               .append(getName())
1643             .append("\n");
1644        str.append("Description = ")
1645               .append(getDescription())
1646             .append("\n");
1647        str.append("Value = ")
1648               .append(getValue())
1649             .append("\n");
1650        str.append("ScopeId = ")
1651               .append(getScopeId())
1652             .append("\n");
1653        str.append("IssueTypeId = ")
1654               .append(getIssueTypeId())
1655             .append("\n");
1656        str.append("ModuleId = ")
1657               .append(getModuleId())
1658             .append("\n");
1659        str.append("ListId = ")
1660               .append(getListId())
1661             .append("\n");
1662        str.append("Deleted = ")
1663               .append(getDeleted())
1664             .append("\n");
1665        str.append("Approved = ")
1666               .append(getApproved())
1667             .append("\n");
1668        str.append("CreatedDate = ")
1669               .append(getCreatedDate())
1670             .append("\n");
1671        str.append("SubscriptionFrequencyId = ")
1672               .append(getSubscriptionFrequencyId())
1673             .append("\n");
1674        str.append("HomePage = ")
1675               .append(getHomePage())
1676             .append("\n");
1677        str.append("Order = ")
1678               .append(getOrder())
1679             .append("\n");
1680        return(str.toString());
1681    }
1682}
1683
Popular Tags