KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > campware > cream > om > BaseNotification


1 package org.campware.cream.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.turbine.om.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  * This class was autogenerated by Torque on:
29  *
30  * [Wed May 04 09:10:56 CEST 2005]
31  *
32  * You should not use this class directly. It should not even be
33  * extended all references should be to Notification
34  */

35 public abstract class BaseNotification extends BaseObject
36     implements org.apache.turbine.om.Retrievable
37 {
38     /** The Peer class */
39     private static final NotificationPeer peer =
40         new NotificationPeer();
41
42         
43     /** The value for the notificationId field */
44     private int notificationId;
45                                           
46     /** The value for the notificationType field */
47     private int notificationType = 10;
48                                           
49     /** The value for the languageId field */
50     private int languageId = 1000;
51                                           
52     /** The value for the emailFormat field */
53     private int emailFormat = 10;
54       
55     /** The value for the subject field */
56     private String JavaDoc subject;
57       
58     /** The value for the body field */
59     private String JavaDoc body;
60   
61     
62     /**
63      * Get the NotificationId
64      *
65      * @return int
66      */

67     public int getNotificationId()
68     {
69         return notificationId;
70     }
71
72                         
73     /**
74      * Set the value of NotificationId
75      *
76      * @param v new value
77      */

78     public void setNotificationId(int v)
79     {
80     
81                   if (this.notificationId != v)
82               {
83             this.notificationId = v;
84             setModified(true);
85         }
86     
87           
88               }
89   
90     /**
91      * Get the NotificationType
92      *
93      * @return int
94      */

95     public int getNotificationType()
96     {
97         return notificationType;
98     }
99
100                         
101     /**
102      * Set the value of NotificationType
103      *
104      * @param v new value
105      */

106     public void setNotificationType(int v)
107     {
108     
109                   if (this.notificationType != v)
110               {
111             this.notificationType = v;
112             setModified(true);
113         }
114     
115           
116               }
117   
118     /**
119      * Get the LanguageId
120      *
121      * @return int
122      */

123     public int getLanguageId()
124     {
125         return languageId;
126     }
127
128                               
129     /**
130      * Set the value of LanguageId
131      *
132      * @param v new value
133      */

134     public void setLanguageId(int v) throws TorqueException
135     {
136     
137                   if (this.languageId != v)
138               {
139             this.languageId = v;
140             setModified(true);
141         }
142     
143                           
144                 if (aLanguage != null && !(aLanguage.getLanguageId() == v))
145                 {
146             aLanguage = null;
147         }
148       
149               }
150   
151     /**
152      * Get the EmailFormat
153      *
154      * @return int
155      */

156     public int getEmailFormat()
157     {
158         return emailFormat;
159     }
160
161                         
162     /**
163      * Set the value of EmailFormat
164      *
165      * @param v new value
166      */

167     public void setEmailFormat(int v)
168     {
169     
170                   if (this.emailFormat != v)
171               {
172             this.emailFormat = v;
173             setModified(true);
174         }
175     
176           
177               }
178   
179     /**
180      * Get the Subject
181      *
182      * @return String
183      */

184     public String JavaDoc getSubject()
185     {
186         return subject;
187     }
188
189                         
190     /**
191      * Set the value of Subject
192      *
193      * @param v new value
194      */

195     public void setSubject(String JavaDoc v)
196     {
197     
198                   if (!ObjectUtils.equals(this.subject, v))
199               {
200             this.subject = v;
201             setModified(true);
202         }
203     
204           
205               }
206   
207     /**
208      * Get the Body
209      *
210      * @return String
211      */

212     public String JavaDoc getBody()
213     {
214         return body;
215     }
216
217                         
218     /**
219      * Set the value of Body
220      *
221      * @param v new value
222      */

223     public void setBody(String JavaDoc v)
224     {
225     
226                   if (!ObjectUtils.equals(this.body, v))
227               {
228             this.body = v;
229             setModified(true);
230         }
231     
232           
233               }
234   
235       
236     
237                   
238     
239         private Language aLanguage;
240
241     /**
242      * Declares an association between this object and a Language object
243      *
244      * @param v Language
245      * @throws TorqueException
246      */

247     public void setLanguage(Language v) throws TorqueException
248     {
249             if (v == null)
250         {
251                           setLanguageId( 1000);
252               }
253         else
254         {
255             setLanguageId(v.getLanguageId());
256         }
257             aLanguage = v;
258     }
259
260                                             
261     /**
262      * Get the associated Language object
263      *
264      * @return the associated Language object
265      * @throws TorqueException
266      */

267     public Language getLanguage() throws TorqueException
268     {
269         if (aLanguage == null && (this.languageId != 0))
270         {
271                           aLanguage = LanguagePeer.retrieveByPK(SimpleKey.keyFor(this.languageId));
272               
273             /* The following can be used instead of the line above to
274                guarantee the related object contains a reference
275                to this object, but this level of coupling
276                may be undesirable in many circumstances.
277                As it can lead to a db query with many results that may
278                never be used.
279                Language obj = LanguagePeer.retrieveByPK(this.languageId);
280                obj.addNotifications(this);
281             */

282         }
283         return aLanguage;
284     }
285
286     /**
287      * Provides convenient way to set a relationship based on a
288      * ObjectKey, for example
289      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
290      *
291          */

292     public void setLanguageKey(ObjectKey key) throws TorqueException
293     {
294       
295                         setLanguageId(((NumberKey) key).intValue());
296                   }
297        
298                 
299     private static List JavaDoc fieldNames = null;
300
301     /**
302      * Generate a list of field names.
303      *
304      * @return a list of field names
305      */

306     public static synchronized List JavaDoc getFieldNames()
307     {
308         if (fieldNames == null)
309         {
310             fieldNames = new ArrayList JavaDoc();
311               fieldNames.add("NotificationId");
312               fieldNames.add("NotificationType");
313               fieldNames.add("LanguageId");
314               fieldNames.add("EmailFormat");
315               fieldNames.add("Subject");
316               fieldNames.add("Body");
317               fieldNames = Collections.unmodifiableList(fieldNames);
318         }
319         return fieldNames;
320     }
321
322     /**
323      * Retrieves a field from the object by name passed in as a String.
324      *
325      * @param name field name
326      * @return value
327      */

328     public Object JavaDoc getByName(String JavaDoc name)
329     {
330           if (name.equals("NotificationId"))
331         {
332                 return new Integer JavaDoc(getNotificationId());
333             }
334           if (name.equals("NotificationType"))
335         {
336                 return new Integer JavaDoc(getNotificationType());
337             }
338           if (name.equals("LanguageId"))
339         {
340                 return new Integer JavaDoc(getLanguageId());
341             }
342           if (name.equals("EmailFormat"))
343         {
344                 return new Integer JavaDoc(getEmailFormat());
345             }
346           if (name.equals("Subject"))
347         {
348                 return getSubject();
349             }
350           if (name.equals("Body"))
351         {
352                 return getBody();
353             }
354           return null;
355     }
356     
357     /**
358      * Retrieves a field from the object by name passed in
359      * as a String. The String must be one of the static
360      * Strings defined in this Class' Peer.
361      *
362      * @param name peer name
363      * @return value
364      */

365     public Object JavaDoc getByPeerName(String JavaDoc name)
366     {
367           if (name.equals(NotificationPeer.NOTIFICATION_ID))
368         {
369                 return new Integer JavaDoc(getNotificationId());
370             }
371           if (name.equals(NotificationPeer.NOTIFICATION_TYPE))
372         {
373                 return new Integer JavaDoc(getNotificationType());
374             }
375           if (name.equals(NotificationPeer.LANGUAGE_ID))
376         {
377                 return new Integer JavaDoc(getLanguageId());
378             }
379           if (name.equals(NotificationPeer.EMAIL_FORMAT))
380         {
381                 return new Integer JavaDoc(getEmailFormat());
382             }
383           if (name.equals(NotificationPeer.SUBJECT))
384         {
385                 return getSubject();
386             }
387           if (name.equals(NotificationPeer.BODY))
388         {
389                 return getBody();
390             }
391           return null;
392     }
393
394     /**
395      * Retrieves a field from the object by Position as specified
396      * in the xml schema. Zero-based.
397      *
398      * @param pos position in xml schema
399      * @return value
400      */

401     public Object JavaDoc getByPosition(int pos)
402     {
403             if (pos == 0)
404         {
405                 return new Integer JavaDoc(getNotificationId());
406             }
407               if (pos == 1)
408         {
409                 return new Integer JavaDoc(getNotificationType());
410             }
411               if (pos == 2)
412         {
413                 return new Integer JavaDoc(getLanguageId());
414             }
415               if (pos == 3)
416         {
417                 return new Integer JavaDoc(getEmailFormat());
418             }
419               if (pos == 4)
420         {
421                 return getSubject();
422             }
423               if (pos == 5)
424         {
425                 return getBody();
426             }
427               return null;
428     }
429      
430     /**
431      * Stores the object in the database. If the object is new,
432      * it inserts it; otherwise an update is performed.
433      *
434      * @throws Exception
435      */

436     public void save() throws Exception JavaDoc
437     {
438           save(NotificationPeer.getMapBuilder()
439                 .getDatabaseMap().getName());
440       }
441
442     /**
443      * Stores the object in the database. If the object is new,
444      * it inserts it; otherwise an update is performed.
445        * Note: this code is here because the method body is
446      * auto-generated conditionally and therefore needs to be
447      * in this file instead of in the super class, BaseObject.
448        *
449      * @param dbName
450      * @throws TorqueException
451      */

452     public void save(String JavaDoc dbName) throws TorqueException
453     {
454         Connection JavaDoc con = null;
455           try
456         {
457             con = Transaction.begin(dbName);
458             save(con);
459             Transaction.commit(con);
460         }
461         catch(TorqueException e)
462         {
463             Transaction.safeRollback(con);
464             throw e;
465         }
466       }
467
468       /** flag to prevent endless save loop, if this object is referenced
469         by another object which falls in this transaction. */

470     private boolean alreadyInSave = false;
471       /**
472      * Stores the object in the database. If the object is new,
473      * it inserts it; otherwise an update is performed. This method
474      * is meant to be used as part of a transaction, otherwise use
475      * the save() method and the connection details will be handled
476      * internally
477      *
478      * @param con
479      * @throws TorqueException
480      */

481     public void save(Connection JavaDoc con) throws TorqueException
482     {
483           if (!alreadyInSave)
484         {
485             alreadyInSave = true;
486
487
488   
489             // If this object has been modified, then save it to the database.
490
if (isModified())
491             {
492                 if (isNew())
493                 {
494                     NotificationPeer.doInsert((Notification) this, con);
495                     setNew(false);
496                 }
497                 else
498                 {
499                     NotificationPeer.doUpdate((Notification) this, con);
500                 }
501             }
502
503                       alreadyInSave = false;
504         }
505       }
506
507                   
508       /**
509      * Set the PrimaryKey using ObjectKey.
510      *
511      * @param key notificationId ObjectKey
512      */

513     public void setPrimaryKey(ObjectKey key)
514         
515     {
516             setNotificationId(((NumberKey) key).intValue());
517         }
518
519     /**
520      * Set the PrimaryKey using a String.
521      *
522      * @param key
523      */

524     public void setPrimaryKey(String JavaDoc key)
525     {
526             setNotificationId(Integer.parseInt(key));
527         }
528
529   
530     /**
531      * returns an id that differentiates this object from others
532      * of its class.
533      */

534     public ObjectKey getPrimaryKey()
535     {
536           return SimpleKey.keyFor(getNotificationId());
537       }
538  
539     /**
540      * get an id that differentiates this object from others
541      * of its class.
542      */

543     public String JavaDoc getQueryKey()
544     {
545         if (getPrimaryKey() == null)
546         {
547             return "";
548         }
549         else
550         {
551             return getPrimaryKey().toString();
552         }
553     }
554
555     /**
556      * set an id that differentiates this object from others
557      * of its class.
558      */

559     public void setQueryKey(String JavaDoc key)
560         throws TorqueException
561     {
562         setPrimaryKey(key);
563     }
564
565     /**
566      * Makes a copy of this object.
567      * It creates a new object filling in the simple attributes.
568        * It then fills all the association collections and sets the
569      * related objects to isNew=true.
570        */

571       public Notification copy() throws TorqueException
572     {
573         return copyInto(new Notification());
574     }
575   
576     protected Notification copyInto(Notification copyObj) throws TorqueException
577     {
578           copyObj.setNotificationId(notificationId);
579           copyObj.setNotificationType(notificationType);
580           copyObj.setLanguageId(languageId);
581           copyObj.setEmailFormat(emailFormat);
582           copyObj.setSubject(subject);
583           copyObj.setBody(body);
584   
585                             copyObj.setNotificationId( 0);
586                                           
587                 return copyObj;
588     }
589
590     /**
591      * returns a peer instance associated with this om. Since Peer classes
592      * are not to have any instance attributes, this method returns the
593      * same instance for all member of this class. The method could therefore
594      * be static, but this would prevent one from overriding the behavior.
595      */

596     public NotificationPeer getPeer()
597     {
598         return peer;
599     }
600
601     public String JavaDoc toString()
602     {
603         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
604         str.append("Notification:\n");
605         str.append("NotificationId = ")
606                .append(getNotificationId())
607              .append("\n");
608         str.append("NotificationType = ")
609                .append(getNotificationType())
610              .append("\n");
611         str.append("LanguageId = ")
612                .append(getLanguageId())
613              .append("\n");
614         str.append("EmailFormat = ")
615                .append(getEmailFormat())
616              .append("\n");
617         str.append("Subject = ")
618                .append(getSubject())
619              .append("\n");
620         str.append("Body = ")
621                .append(getBody())
622              .append("\n");
623         return(str.toString());
624     }
625 }
626
Popular Tags