KickJava   Java API By Example, From Geeks To Geeks.

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


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

31 public abstract class BaseUserPreference extends BaseObject
32     implements org.apache.fulcrum.intake.Retrievable
33 {
34     /** The Peer class */
35     private static final UserPreferencePeer peer =
36         new UserPreferencePeer();
37
38         
39     /** The value for the userId field */
40     private Integer JavaDoc userId;
41       
42     /** The value for the passwordExpire field */
43     private Date JavaDoc passwordExpire;
44       
45     /** The value for the enterIssueRedirect field */
46     private int enterIssueRedirect;
47       
48     /** The value for the homePage field */
49     private String JavaDoc homePage;
50       
51     /** The value for the locale field */
52     private String JavaDoc locale;
53   
54     
55     /**
56      * Get the UserId
57      *
58      * @return Integer
59      */

60     public Integer JavaDoc getUserId()
61     {
62         return userId;
63     }
64
65                               
66     /**
67      * Set the value of UserId
68      *
69      * @param v new value
70      */

71     public void setUserId(Integer JavaDoc v) throws TorqueException
72     {
73     
74                   if (!ObjectUtils.equals(this.userId, v))
75               {
76             this.userId = v;
77             setModified(true);
78         }
79     
80                                           
81                 if (aScarabUser != null && !ObjectUtils.equals(aScarabUser.getUserId(), v))
82                 {
83             aScarabUser = null;
84         }
85       
86               }
87   
88     /**
89      * Get the PasswordExpire
90      *
91      * @return Date
92      */

93     public Date JavaDoc getPasswordExpire()
94     {
95         return passwordExpire;
96     }
97
98                         
99     /**
100      * Set the value of PasswordExpire
101      *
102      * @param v new value
103      */

104     public void setPasswordExpire(Date JavaDoc v)
105     {
106     
107                   if (!ObjectUtils.equals(this.passwordExpire, v))
108               {
109             this.passwordExpire = v;
110             setModified(true);
111         }
112     
113           
114               }
115   
116     /**
117      * Get the EnterIssueRedirect
118      *
119      * @return int
120      */

121     public int getEnterIssueRedirect()
122     {
123         return enterIssueRedirect;
124     }
125
126                         
127     /**
128      * Set the value of EnterIssueRedirect
129      *
130      * @param v new value
131      */

132     public void setEnterIssueRedirect(int v)
133     {
134     
135                   if (this.enterIssueRedirect != v)
136               {
137             this.enterIssueRedirect = v;
138             setModified(true);
139         }
140     
141           
142               }
143   
144     /**
145      * Get the HomePage
146      *
147      * @return String
148      */

149     public String JavaDoc getHomePage()
150     {
151         return homePage;
152     }
153
154                         
155     /**
156      * Set the value of HomePage
157      *
158      * @param v new value
159      */

160     public void setHomePage(String JavaDoc v)
161     {
162     
163                   if (!ObjectUtils.equals(this.homePage, v))
164               {
165             this.homePage = v;
166             setModified(true);
167         }
168     
169           
170               }
171   
172     /**
173      * Get the Locale
174      *
175      * @return String
176      */

177     public String JavaDoc getLocale()
178     {
179         return locale;
180     }
181
182                         
183     /**
184      * Set the value of Locale
185      *
186      * @param v new value
187      */

188     public void setLocale(String JavaDoc v)
189     {
190     
191                   if (!ObjectUtils.equals(this.locale, v))
192               {
193             this.locale = v;
194             setModified(true);
195         }
196     
197           
198               }
199   
200       
201             
202                   
203         private ScarabUser aScarabUser;
204
205     /**
206      * Declares an association between this object and a ScarabUser object
207      *
208      * @param v ScarabUser
209      * @throws TorqueException
210      */

211     public void setScarabUser(ScarabUser v) throws TorqueException
212     {
213             if (v == null)
214         {
215                   setUserId((Integer JavaDoc) null);
216               }
217         else
218         {
219             setUserId(v.getUserId());
220         }
221             aScarabUser = v;
222     }
223
224                         
225     /**
226      * Get the associated ScarabUser object
227      *
228      * @return the associated ScarabUser object
229      * @throws TorqueException
230      */

231     public ScarabUser getScarabUser() throws TorqueException
232     {
233         if ( !ObjectUtils.equals(getUserId(), null) )
234         {
235                 return ScarabUserManager.getInstance(SimpleKey.keyFor(getUserId()));
236             }
237         return aScarabUser;
238     }
239
240     /**
241      * Provides convenient way to set a relationship based on a
242      * ObjectKey, for example
243      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
244      *
245          */

246     public void setScarabUserKey(ObjectKey key) throws TorqueException
247     {
248     
249                     setUserId(new Integer JavaDoc(((NumberKey) key).intValue()));
250               }
251      
252                 
253     private static List JavaDoc fieldNames = null;
254
255     /**
256      * Generate a list of field names.
257      *
258      * @return a list of field names
259      */

260     public static synchronized List JavaDoc getFieldNames()
261     {
262         if (fieldNames == null)
263         {
264             fieldNames = new ArrayList JavaDoc();
265               fieldNames.add("UserId");
266               fieldNames.add("PasswordExpire");
267               fieldNames.add("EnterIssueRedirect");
268               fieldNames.add("HomePage");
269               fieldNames.add("Locale");
270               fieldNames = Collections.unmodifiableList(fieldNames);
271         }
272         return fieldNames;
273     }
274
275     /**
276      * Retrieves a field from the object by name passed in as a String.
277      *
278      * @param name field name
279      * @return value
280      */

281     public Object JavaDoc getByName(String JavaDoc name)
282     {
283           if (name.equals("UserId"))
284         {
285                 return getUserId();
286             }
287           if (name.equals("PasswordExpire"))
288         {
289                 return getPasswordExpire();
290             }
291           if (name.equals("EnterIssueRedirect"))
292         {
293                 return new Integer JavaDoc(getEnterIssueRedirect());
294             }
295           if (name.equals("HomePage"))
296         {
297                 return getHomePage();
298             }
299           if (name.equals("Locale"))
300         {
301                 return getLocale();
302             }
303           return null;
304     }
305     
306     /**
307      * Retrieves a field from the object by name passed in
308      * as a String. The String must be one of the static
309      * Strings defined in this Class' Peer.
310      *
311      * @param name peer name
312      * @return value
313      */

314     public Object JavaDoc getByPeerName(String JavaDoc name)
315     {
316           if (name.equals(UserPreferencePeer.USER_ID))
317         {
318                 return getUserId();
319             }
320           if (name.equals(UserPreferencePeer.PASSWORD_EXPIRE))
321         {
322                 return getPasswordExpire();
323             }
324           if (name.equals(UserPreferencePeer.ENTER_ISSUE_REDIRECT))
325         {
326                 return new Integer JavaDoc(getEnterIssueRedirect());
327             }
328           if (name.equals(UserPreferencePeer.HOME_PAGE))
329         {
330                 return getHomePage();
331             }
332           if (name.equals(UserPreferencePeer.LOCALE))
333         {
334                 return getLocale();
335             }
336           return null;
337     }
338
339     /**
340      * Retrieves a field from the object by Position as specified
341      * in the xml schema. Zero-based.
342      *
343      * @param pos position in xml schema
344      * @return value
345      */

346     public Object JavaDoc getByPosition(int pos)
347     {
348             if (pos == 0)
349         {
350                 return getUserId();
351             }
352               if (pos == 1)
353         {
354                 return getPasswordExpire();
355             }
356               if (pos == 2)
357         {
358                 return new Integer JavaDoc(getEnterIssueRedirect());
359             }
360               if (pos == 3)
361         {
362                 return getHomePage();
363             }
364               if (pos == 4)
365         {
366                 return getLocale();
367             }
368               return null;
369     }
370      
371     /**
372      * Stores the object in the database. If the object is new,
373      * it inserts it; otherwise an update is performed.
374      *
375      * @throws Exception
376      */

377     public void save() throws Exception JavaDoc
378     {
379           save(UserPreferencePeer.getMapBuilder()
380                 .getDatabaseMap().getName());
381       }
382
383     /**
384      * Stores the object in the database. If the object is new,
385      * it inserts it; otherwise an update is performed.
386        * Note: this code is here because the method body is
387      * auto-generated conditionally and therefore needs to be
388      * in this file instead of in the super class, BaseObject.
389        *
390      * @param dbName
391      * @throws TorqueException
392      */

393     public void save(String JavaDoc dbName) throws TorqueException
394     {
395         Connection JavaDoc con = null;
396           try
397         {
398             con = Transaction.begin(dbName);
399             save(con);
400             Transaction.commit(con);
401         }
402         catch(TorqueException e)
403         {
404             Transaction.safeRollback(con);
405             throw e;
406         }
407       }
408
409       /** flag to prevent endless save loop, if this object is referenced
410         by another object which falls in this transaction. */

411     private boolean alreadyInSave = false;
412       /**
413      * Stores the object in the database. If the object is new,
414      * it inserts it; otherwise an update is performed. This method
415      * is meant to be used as part of a transaction, otherwise use
416      * the save() method and the connection details will be handled
417      * internally
418      *
419      * @param con
420      * @throws TorqueException
421      */

422     public void save(Connection JavaDoc con) throws TorqueException
423     {
424           if (!alreadyInSave)
425         {
426             alreadyInSave = true;
427
428
429   
430             // If this object has been modified, then save it to the database.
431
if (isModified())
432             {
433                 if (isNew())
434                 {
435                     UserPreferencePeer.doInsert((UserPreference)this, con);
436                     setNew(false);
437                 }
438                 else
439                 {
440                     UserPreferencePeer.doUpdate((UserPreference)this, con);
441                 }
442
443                       if (isCacheOnSave())
444                 {
445                     UserPreferenceManager.putInstance(this);
446                 }
447               }
448
449                       alreadyInSave = false;
450         }
451       }
452
453     /**
454      * Specify whether to cache the object after saving to the db.
455      * This method returns false
456      */

457     protected boolean isCacheOnSave()
458     {
459         return true;
460     }
461
462                         
463       /**
464      * Set the PrimaryKey using ObjectKey.
465      *
466      * @param userId ObjectKey
467      */

468     public void setPrimaryKey(ObjectKey userId)
469         throws TorqueException {
470             setUserId(new Integer JavaDoc(((NumberKey)userId).intValue()));
471         }
472
473     /**
474      * Set the PrimaryKey using a String.
475      *
476      * @param key
477      */

478     public void setPrimaryKey(String JavaDoc key) throws TorqueException
479     {
480             setUserId(new Integer JavaDoc(key));
481         }
482
483   
484     /**
485      * returns an id that differentiates this object from others
486      * of its class.
487      */

488     public ObjectKey getPrimaryKey()
489     {
490           return SimpleKey.keyFor(getUserId());
491       }
492  
493     /**
494      * get an id that differentiates this object from others
495      * of its class.
496      */

497     public String JavaDoc getQueryKey()
498     {
499         if (getPrimaryKey() == null)
500         {
501             return "";
502         }
503         else
504         {
505             return getPrimaryKey().toString();
506         }
507     }
508
509     /**
510      * set an id that differentiates this object from others
511      * of its class.
512      */

513     public void setQueryKey(String JavaDoc key)
514         throws TorqueException
515     {
516         setPrimaryKey(key);
517     }
518
519     /**
520      * Makes a copy of this object.
521      * It creates a new object filling in the simple attributes.
522        * It then fills all the association collections and sets the
523      * related objects to isNew=true.
524        */

525       public UserPreference copy() throws TorqueException
526     {
527         UserPreference copyObj = new UserPreference();
528             copyObj.setUserId(userId);
529           copyObj.setPasswordExpire(passwordExpire);
530           copyObj.setEnterIssueRedirect(enterIssueRedirect);
531           copyObj.setHomePage(homePage);
532           copyObj.setLocale(locale);
533   
534                       copyObj.setUserId((Integer JavaDoc)null);
535                                     
536                 return copyObj;
537     }
538
539     /**
540      * returns a peer instance associated with this om. Since Peer classes
541      * are not to have any instance attributes, this method returns the
542      * same instance for all member of this class. The method could therefore
543      * be static, but this would prevent one from overriding the behavior.
544      */

545     public UserPreferencePeer getPeer()
546     {
547         return peer;
548     }
549
550     public String JavaDoc toString()
551     {
552         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
553         str.append("UserPreference:\n");
554         str.append("UserId = ")
555                .append(getUserId())
556              .append("\n");
557         str.append("PasswordExpire = ")
558                .append(getPasswordExpire())
559              .append("\n");
560         str.append("EnterIssueRedirect = ")
561                .append(getEnterIssueRedirect())
562              .append("\n");
563         str.append("HomePage = ")
564                .append(getHomePage())
565              .append("\n");
566         str.append("Locale = ")
567                .append(getLocale())
568              .append("\n");
569         return(str.toString());
570     }
571 }
572
Popular Tags