KickJava   Java API By Example, From Geeks To Geeks.

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


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

33 public abstract class BaseRQueryUser extends BaseObject
34     implements org.apache.fulcrum.intake.Retrievable
35 {
36     /** The Peer class */
37     private static final RQueryUserPeer peer =
38         new RQueryUserPeer();
39
40         
41     /** The value for the queryId field */
42     private Long JavaDoc queryId;
43       
44     /** The value for the userId field */
45     private Integer JavaDoc userId;
46                                                                 
47     /** The value for the isSubscribed field */
48     private boolean isSubscribed = false;
49       
50     /** The value for the subscriptionFrequency field */
51     private Integer JavaDoc subscriptionFrequency;
52                                                                 
53     /** The value for the isdefault field */
54     private boolean isdefault = false;
55   
56     
57     /**
58      * Get the QueryId
59      *
60      * @return Long
61      */

62     public Long JavaDoc getQueryId()
63     {
64         return queryId;
65     }
66
67                               
68     /**
69      * Set the value of QueryId
70      *
71      * @param v new value
72      */

73     public void setQueryId(Long JavaDoc v) throws TorqueException
74     {
75     
76                   if (!ObjectUtils.equals(this.queryId, v))
77               {
78             this.queryId = v;
79             setModified(true);
80         }
81     
82                                   
83                 if (aQuery != null && !ObjectUtils.equals(aQuery.getQueryId(), v))
84                 {
85             aQuery = null;
86         }
87       
88               }
89   
90     /**
91      * Get the UserId
92      *
93      * @return Integer
94      */

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

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

128     public boolean getIsSubscribed()
129     {
130         return isSubscribed;
131     }
132
133                         
134     /**
135      * Set the value of IsSubscribed
136      *
137      * @param v new value
138      */

139     public void setIsSubscribed(boolean v)
140     {
141     
142                   if (this.isSubscribed != v)
143               {
144             this.isSubscribed = v;
145             setModified(true);
146         }
147     
148           
149               }
150   
151     /**
152      * Get the SubscriptionFrequency
153      *
154      * @return Integer
155      */

156     public Integer JavaDoc getSubscriptionFrequency()
157     {
158         return subscriptionFrequency;
159     }
160
161                               
162     /**
163      * Set the value of SubscriptionFrequency
164      *
165      * @param v new value
166      */

167     public void setSubscriptionFrequency(Integer JavaDoc v) throws TorqueException
168     {
169     
170                   if (!ObjectUtils.equals(this.subscriptionFrequency, v))
171               {
172             this.subscriptionFrequency = v;
173             setModified(true);
174         }
175     
176                                   
177                 if (aFrequency != null && !ObjectUtils.equals(aFrequency.getFrequencyId(), v))
178                 {
179             aFrequency = null;
180         }
181       
182               }
183   
184     /**
185      * Get the Isdefault
186      *
187      * @return boolean
188      */

189     public boolean getIsdefault()
190     {
191         return isdefault;
192     }
193
194                         
195     /**
196      * Set the value of Isdefault
197      *
198      * @param v new value
199      */

200     public void setIsdefault(boolean v)
201     {
202     
203                   if (this.isdefault != v)
204               {
205             this.isdefault = v;
206             setModified(true);
207         }
208     
209           
210               }
211   
212       
213         
214                   
215         private Query aQuery;
216
217     /**
218      * Declares an association between this object and a Query object
219      *
220      * @param v Query
221      * @throws TorqueException
222      */

223     public void setQuery(Query v) throws TorqueException
224     {
225             if (v == null)
226         {
227                   setQueryId((Long JavaDoc) null);
228               }
229         else
230         {
231             setQueryId(v.getQueryId());
232         }
233             aQuery = v;
234     }
235
236                         
237     /**
238      * Get the associated Query object
239      *
240      * @return the associated Query object
241      * @throws TorqueException
242      */

243     public Query getQuery() throws TorqueException
244     {
245         if ( !ObjectUtils.equals(getQueryId(), null) )
246         {
247                 return QueryManager.getInstance(SimpleKey.keyFor(getQueryId()));
248             }
249         return aQuery;
250     }
251
252     /**
253      * Provides convenient way to set a relationship based on a
254      * ObjectKey, for example
255      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
256      *
257          */

258     public void setQueryKey(ObjectKey key) throws TorqueException
259     {
260     
261                     setQueryId(new Long JavaDoc(((NumberKey) key).longValue()));
262               }
263   
264             
265                   
266         private ScarabUser aScarabUser;
267
268     /**
269      * Declares an association between this object and a ScarabUser object
270      *
271      * @param v ScarabUser
272      * @throws TorqueException
273      */

274     public void setScarabUser(ScarabUser v) throws TorqueException
275     {
276             if (v == null)
277         {
278                   setUserId((Integer JavaDoc) null);
279               }
280         else
281         {
282             setUserId(v.getUserId());
283         }
284             aScarabUser = v;
285     }
286
287                         
288     /**
289      * Get the associated ScarabUser object
290      *
291      * @return the associated ScarabUser object
292      * @throws TorqueException
293      */

294     public ScarabUser getScarabUser() throws TorqueException
295     {
296         if ( !ObjectUtils.equals(getUserId(), null) )
297         {
298                 return ScarabUserManager.getInstance(SimpleKey.keyFor(getUserId()));
299             }
300         return aScarabUser;
301     }
302
303     /**
304      * Provides convenient way to set a relationship based on a
305      * ObjectKey, for example
306      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
307      *
308          */

309     public void setScarabUserKey(ObjectKey key) throws TorqueException
310     {
311     
312                     setUserId(new Integer JavaDoc(((NumberKey) key).intValue()));
313               }
314   
315         
316                   
317         private Frequency aFrequency;
318
319     /**
320      * Declares an association between this object and a Frequency object
321      *
322      * @param v Frequency
323      * @throws TorqueException
324      */

325     public void setFrequency(Frequency v) throws TorqueException
326     {
327             if (v == null)
328         {
329                   setSubscriptionFrequency((Integer JavaDoc) null);
330               }
331         else
332         {
333             setSubscriptionFrequency(v.getFrequencyId());
334         }
335             aFrequency = v;
336     }
337
338                         
339     /**
340      * Get the associated Frequency object
341      *
342      * @return the associated Frequency object
343      * @throws TorqueException
344      */

345     public Frequency getFrequency() throws TorqueException
346     {
347         if ( !ObjectUtils.equals(getSubscriptionFrequency(), null) )
348         {
349                 return FrequencyManager.getInstance(SimpleKey.keyFor(getSubscriptionFrequency()));
350             }
351         return aFrequency;
352     }
353
354     /**
355      * Provides convenient way to set a relationship based on a
356      * ObjectKey, for example
357      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
358      *
359          */

360     public void setFrequencyKey(ObjectKey key) throws TorqueException
361     {
362     
363                     setSubscriptionFrequency(new Integer JavaDoc(((NumberKey) key).intValue()));
364               }
365      
366                 
367     private static List JavaDoc fieldNames = null;
368
369     /**
370      * Generate a list of field names.
371      *
372      * @return a list of field names
373      */

374     public static synchronized List JavaDoc getFieldNames()
375     {
376         if (fieldNames == null)
377         {
378             fieldNames = new ArrayList JavaDoc();
379               fieldNames.add("QueryId");
380               fieldNames.add("UserId");
381               fieldNames.add("IsSubscribed");
382               fieldNames.add("SubscriptionFrequency");
383               fieldNames.add("Isdefault");
384               fieldNames = Collections.unmodifiableList(fieldNames);
385         }
386         return fieldNames;
387     }
388
389     /**
390      * Retrieves a field from the object by name passed in as a String.
391      *
392      * @param name field name
393      * @return value
394      */

395     public Object JavaDoc getByName(String JavaDoc name)
396     {
397           if (name.equals("QueryId"))
398         {
399                 return getQueryId();
400             }
401           if (name.equals("UserId"))
402         {
403                 return getUserId();
404             }
405           if (name.equals("IsSubscribed"))
406         {
407                 return Boolean.valueOf(getIsSubscribed());
408             }
409           if (name.equals("SubscriptionFrequency"))
410         {
411                 return getSubscriptionFrequency();
412             }
413           if (name.equals("Isdefault"))
414         {
415                 return Boolean.valueOf(getIsdefault());
416             }
417           return null;
418     }
419     
420     /**
421      * Retrieves a field from the object by name passed in
422      * as a String. The String must be one of the static
423      * Strings defined in this Class' Peer.
424      *
425      * @param name peer name
426      * @return value
427      */

428     public Object JavaDoc getByPeerName(String JavaDoc name)
429     {
430           if (name.equals(RQueryUserPeer.QUERY_ID))
431         {
432                 return getQueryId();
433             }
434           if (name.equals(RQueryUserPeer.USER_ID))
435         {
436                 return getUserId();
437             }
438           if (name.equals(RQueryUserPeer.IS_SUBSCRIBED))
439         {
440                 return Boolean.valueOf(getIsSubscribed());
441             }
442           if (name.equals(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID))
443         {
444                 return getSubscriptionFrequency();
445             }
446           if (name.equals(RQueryUserPeer.ISDEFAULT))
447         {
448                 return Boolean.valueOf(getIsdefault());
449             }
450           return null;
451     }
452
453     /**
454      * Retrieves a field from the object by Position as specified
455      * in the xml schema. Zero-based.
456      *
457      * @param pos position in xml schema
458      * @return value
459      */

460     public Object JavaDoc getByPosition(int pos)
461     {
462             if (pos == 0)
463         {
464                 return getQueryId();
465             }
466               if (pos == 1)
467         {
468                 return getUserId();
469             }
470               if (pos == 2)
471         {
472                 return Boolean.valueOf(getIsSubscribed());
473             }
474               if (pos == 3)
475         {
476                 return getSubscriptionFrequency();
477             }
478               if (pos == 4)
479         {
480                 return Boolean.valueOf(getIsdefault());
481             }
482               return null;
483     }
484      
485     /**
486      * Stores the object in the database. If the object is new,
487      * it inserts it; otherwise an update is performed.
488      *
489      * @throws Exception
490      */

491     public void save() throws Exception JavaDoc
492     {
493           save(RQueryUserPeer.getMapBuilder()
494                 .getDatabaseMap().getName());
495       }
496
497     /**
498      * Stores the object in the database. If the object is new,
499      * it inserts it; otherwise an update is performed.
500        * Note: this code is here because the method body is
501      * auto-generated conditionally and therefore needs to be
502      * in this file instead of in the super class, BaseObject.
503        *
504      * @param dbName
505      * @throws TorqueException
506      */

507     public void save(String JavaDoc dbName) throws TorqueException
508     {
509         Connection JavaDoc con = null;
510           try
511         {
512             con = Transaction.begin(dbName);
513             save(con);
514             Transaction.commit(con);
515         }
516         catch(TorqueException e)
517         {
518             Transaction.safeRollback(con);
519             throw e;
520         }
521       }
522
523       /** flag to prevent endless save loop, if this object is referenced
524         by another object which falls in this transaction. */

525     private boolean alreadyInSave = false;
526       /**
527      * Stores the object in the database. If the object is new,
528      * it inserts it; otherwise an update is performed. This method
529      * is meant to be used as part of a transaction, otherwise use
530      * the save() method and the connection details will be handled
531      * internally
532      *
533      * @param con
534      * @throws TorqueException
535      */

536     public void save(Connection JavaDoc con) throws TorqueException
537     {
538           if (!alreadyInSave)
539         {
540             alreadyInSave = true;
541
542
543   
544             // If this object has been modified, then save it to the database.
545
if (isModified())
546             {
547                 if (isNew())
548                 {
549                     RQueryUserPeer.doInsert((RQueryUser)this, con);
550                     setNew(false);
551                 }
552                 else
553                 {
554                     RQueryUserPeer.doUpdate((RQueryUser)this, con);
555                 }
556
557                       if (isCacheOnSave())
558                 {
559                     RQueryUserManager.putInstance(this);
560                 }
561               }
562
563                       alreadyInSave = false;
564         }
565       }
566
567     /**
568      * Specify whether to cache the object after saving to the db.
569      * This method returns false
570      */

571     protected boolean isCacheOnSave()
572     {
573         return true;
574     }
575
576                                               
577   
578     private final SimpleKey[] pks = new SimpleKey[2];
579     private final ComboKey comboPK = new ComboKey(pks);
580
581     /**
582      * Set the PrimaryKey with an ObjectKey
583      *
584      * @param key
585      */

586     public void setPrimaryKey(ObjectKey key) throws TorqueException
587     {
588         SimpleKey[] keys = (SimpleKey[]) key.getValue();
589         SimpleKey tmpKey = null;
590                       setQueryId(new Long JavaDoc(((NumberKey)keys[0]).longValue()));
591                         setUserId(new Integer JavaDoc(((NumberKey)keys[1]).intValue()));
592               }
593
594     /**
595      * Set the PrimaryKey using SimpleKeys.
596      *
597          * @param queryId Long
598          * @param userId Integer
599          */

600     public void setPrimaryKey( Long JavaDoc queryId, Integer JavaDoc userId)
601         throws TorqueException
602     {
603             setQueryId(queryId);
604             setUserId(userId);
605         }
606
607     /**
608      * Set the PrimaryKey using a String.
609      */

610     public void setPrimaryKey(String JavaDoc key) throws TorqueException
611     {
612         setPrimaryKey(new ComboKey(key));
613     }
614   
615     /**
616      * returns an id that differentiates this object from others
617      * of its class.
618      */

619     public ObjectKey getPrimaryKey()
620     {
621               pks[0] = SimpleKey.keyFor(getQueryId());
622                   pks[1] = SimpleKey.keyFor(getUserId());
623                   return comboPK;
624       }
625  
626     /**
627      * get an id that differentiates this object from others
628      * of its class.
629      */

630     public String JavaDoc getQueryKey()
631     {
632         if (getPrimaryKey() == null)
633         {
634             return "";
635         }
636         else
637         {
638             return getPrimaryKey().toString();
639         }
640     }
641
642     /**
643      * set an id that differentiates this object from others
644      * of its class.
645      */

646     public void setQueryKey(String JavaDoc key)
647         throws TorqueException
648     {
649         setPrimaryKey(key);
650     }
651
652     /**
653      * Makes a copy of this object.
654      * It creates a new object filling in the simple attributes.
655        * It then fills all the association collections and sets the
656      * related objects to isNew=true.
657        */

658       public RQueryUser copy() throws TorqueException
659     {
660         RQueryUser copyObj = new RQueryUser();
661             copyObj.setQueryId(queryId);
662           copyObj.setUserId(userId);
663           copyObj.setIsSubscribed(isSubscribed);
664           copyObj.setSubscriptionFrequency(subscriptionFrequency);
665           copyObj.setIsdefault(isdefault);
666   
667                       copyObj.setQueryId((Long JavaDoc)null);
668                                 copyObj.setUserId((Integer JavaDoc)null);
669                               
670                 return copyObj;
671     }
672
673     /**
674      * returns a peer instance associated with this om. Since Peer classes
675      * are not to have any instance attributes, this method returns the
676      * same instance for all member of this class. The method could therefore
677      * be static, but this would prevent one from overriding the behavior.
678      */

679     public RQueryUserPeer getPeer()
680     {
681         return peer;
682     }
683
684     public String JavaDoc toString()
685     {
686         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
687         str.append("RQueryUser:\n");
688         str.append("QueryId = ")
689                .append(getQueryId())
690              .append("\n");
691         str.append("UserId = ")
692                .append(getUserId())
693              .append("\n");
694         str.append("IsSubscribed = ")
695                .append(getIsSubscribed())
696              .append("\n");
697         str.append("SubscriptionFrequency = ")
698                .append(getSubscriptionFrequency())
699              .append("\n");
700         str.append("Isdefault = ")
701                .append(getIsdefault())
702              .append("\n");
703         return(str.toString());
704     }
705 }
706
Popular Tags