KickJava   Java API By Example, From Geeks To Geeks.

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


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 MITListItem
32  */

33 public abstract class BaseMITListItem extends BaseObject
34     implements org.apache.fulcrum.intake.Retrievable
35 {
36     /** The Peer class */
37     private static final MITListItemPeer peer =
38         new MITListItemPeer();
39
40         
41     /** The value for the itemId field */
42     private Long JavaDoc itemId;
43       
44     /** The value for the moduleId field */
45     private Integer JavaDoc moduleId;
46       
47     /** The value for the issueTypeId field */
48     private Integer JavaDoc issueTypeId;
49       
50     /** The value for the listId field */
51     private Long JavaDoc listId;
52   
53     
54     /**
55      * Get the ItemId
56      *
57      * @return Long
58      */

59     public Long JavaDoc getItemId()
60     {
61         return itemId;
62     }
63
64                         
65     /**
66      * Set the value of ItemId
67      *
68      * @param v new value
69      */

70     public void setItemId(Long JavaDoc v)
71     {
72     
73                   if (!ObjectUtils.equals(this.itemId, v))
74               {
75             this.itemId = v;
76             setModified(true);
77         }
78     
79           
80               }
81   
82     /**
83      * Get the ModuleId
84      *
85      * @return Integer
86      */

87     public Integer JavaDoc getModuleId()
88     {
89         return moduleId;
90     }
91
92                               
93     /**
94      * Set the value of ModuleId
95      *
96      * @param v new value
97      */

98     public void setModuleId(Integer JavaDoc v) throws TorqueException
99     {
100     
101                   if (!ObjectUtils.equals(this.moduleId, v))
102               {
103             this.moduleId = v;
104             setModified(true);
105         }
106     
107                                           
108                 if (aModule != null && !ObjectUtils.equals(aModule.getModuleId(), v))
109                 {
110             aModule = null;
111         }
112       
113               }
114   
115     /**
116      * Get the IssueTypeId
117      *
118      * @return Integer
119      */

120     public Integer JavaDoc getIssueTypeId()
121     {
122         return issueTypeId;
123     }
124
125                               
126     /**
127      * Set the value of IssueTypeId
128      *
129      * @param v new value
130      */

131     public void setIssueTypeId(Integer JavaDoc v) throws TorqueException
132     {
133     
134                   if (!ObjectUtils.equals(this.issueTypeId, v))
135               {
136             this.issueTypeId = v;
137             setModified(true);
138         }
139     
140                                   
141                 if (aIssueType != null && !ObjectUtils.equals(aIssueType.getIssueTypeId(), v))
142                 {
143             aIssueType = null;
144         }
145       
146               }
147   
148     /**
149      * Get the ListId
150      *
151      * @return Long
152      */

153     public Long JavaDoc getListId()
154     {
155         return listId;
156     }
157
158                               
159     /**
160      * Set the value of ListId
161      *
162      * @param v new value
163      */

164     public void setListId(Long JavaDoc v) throws TorqueException
165     {
166     
167                   if (!ObjectUtils.equals(this.listId, v))
168               {
169             this.listId = v;
170             setModified(true);
171         }
172     
173                                   
174                 if (aMITList != null && !ObjectUtils.equals(aMITList.getListId(), v))
175                 {
176             aMITList = null;
177         }
178       
179               }
180   
181       
182         
183                   
184         private MITList aMITList;
185
186     /**
187      * Declares an association between this object and a MITList object
188      *
189      * @param v MITList
190      * @throws TorqueException
191      */

192     public void setMITList(MITList v) throws TorqueException
193     {
194             if (v == null)
195         {
196                   setListId((Long JavaDoc) null);
197               }
198         else
199         {
200             setListId(v.getListId());
201         }
202             aMITList = v;
203     }
204
205                         
206     /**
207      * Get the associated MITList object
208      *
209      * @return the associated MITList object
210      * @throws TorqueException
211      */

212     public MITList getMITList() throws TorqueException
213     {
214         if ( !ObjectUtils.equals(getListId(), null) )
215         {
216                 return MITListManager.getInstance(SimpleKey.keyFor(getListId()));
217             }
218         return aMITList;
219     }
220
221     /**
222      * Provides convenient way to set a relationship based on a
223      * ObjectKey, for example
224      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
225      *
226          */

227     public void setMITListKey(ObjectKey key) throws TorqueException
228     {
229     
230                     setListId(new Long JavaDoc(((NumberKey) key).longValue()));
231               }
232   
233             
234                   
235         private Module aModule;
236
237     /**
238      * Declares an association between this object and a Module object
239      *
240      * @param v Module
241      * @throws TorqueException
242      */

243     public void setModule(Module v) throws TorqueException
244     {
245             if (v == null)
246         {
247                   setModuleId((Integer JavaDoc) null);
248               }
249         else
250         {
251             setModuleId(v.getModuleId());
252         }
253             aModule = v;
254     }
255
256                         
257     /**
258      * Get the associated Module object
259      *
260      * @return the associated Module object
261      * @throws TorqueException
262      */

263     public Module getModule() throws TorqueException
264     {
265         if ( !ObjectUtils.equals(getModuleId(), null) )
266         {
267                 return ModuleManager.getInstance(SimpleKey.keyFor(getModuleId()));
268             }
269         return aModule;
270     }
271
272     /**
273      * Provides convenient way to set a relationship based on a
274      * ObjectKey, for example
275      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
276      *
277          */

278     public void setModuleKey(ObjectKey key) throws TorqueException
279     {
280     
281                     setModuleId(new Integer JavaDoc(((NumberKey) key).intValue()));
282               }
283   
284         
285                   
286         private IssueType aIssueType;
287
288     /**
289      * Declares an association between this object and a IssueType object
290      *
291      * @param v IssueType
292      * @throws TorqueException
293      */

294     public void setIssueType(IssueType v) throws TorqueException
295     {
296             if (v == null)
297         {
298                   setIssueTypeId((Integer JavaDoc) null);
299               }
300         else
301         {
302             setIssueTypeId(v.getIssueTypeId());
303         }
304             aIssueType = v;
305     }
306
307                         
308     /**
309      * Get the associated IssueType object
310      *
311      * @return the associated IssueType object
312      * @throws TorqueException
313      */

314     public IssueType getIssueType() throws TorqueException
315     {
316         if ( !ObjectUtils.equals(getIssueTypeId(), null) )
317         {
318                 return IssueTypeManager.getInstance(SimpleKey.keyFor(getIssueTypeId()));
319             }
320         return aIssueType;
321     }
322
323     /**
324      * Provides convenient way to set a relationship based on a
325      * ObjectKey, for example
326      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
327      *
328          */

329     public void setIssueTypeKey(ObjectKey key) throws TorqueException
330     {
331     
332                     setIssueTypeId(new Integer JavaDoc(((NumberKey) key).intValue()));
333               }
334      
335                 
336     private static List JavaDoc fieldNames = null;
337
338     /**
339      * Generate a list of field names.
340      *
341      * @return a list of field names
342      */

343     public static synchronized List JavaDoc getFieldNames()
344     {
345         if (fieldNames == null)
346         {
347             fieldNames = new ArrayList JavaDoc();
348               fieldNames.add("ItemId");
349               fieldNames.add("ModuleId");
350               fieldNames.add("IssueTypeId");
351               fieldNames.add("ListId");
352               fieldNames = Collections.unmodifiableList(fieldNames);
353         }
354         return fieldNames;
355     }
356
357     /**
358      * Retrieves a field from the object by name passed in as a String.
359      *
360      * @param name field name
361      * @return value
362      */

363     public Object JavaDoc getByName(String JavaDoc name)
364     {
365           if (name.equals("ItemId"))
366         {
367                 return getItemId();
368             }
369           if (name.equals("ModuleId"))
370         {
371                 return getModuleId();
372             }
373           if (name.equals("IssueTypeId"))
374         {
375                 return getIssueTypeId();
376             }
377           if (name.equals("ListId"))
378         {
379                 return getListId();
380             }
381           return null;
382     }
383     
384     /**
385      * Retrieves a field from the object by name passed in
386      * as a String. The String must be one of the static
387      * Strings defined in this Class' Peer.
388      *
389      * @param name peer name
390      * @return value
391      */

392     public Object JavaDoc getByPeerName(String JavaDoc name)
393     {
394           if (name.equals(MITListItemPeer.ITEM_ID))
395         {
396                 return getItemId();
397             }
398           if (name.equals(MITListItemPeer.MODULE_ID))
399         {
400                 return getModuleId();
401             }
402           if (name.equals(MITListItemPeer.ISSUE_TYPE_ID))
403         {
404                 return getIssueTypeId();
405             }
406           if (name.equals(MITListItemPeer.LIST_ID))
407         {
408                 return getListId();
409             }
410           return null;
411     }
412
413     /**
414      * Retrieves a field from the object by Position as specified
415      * in the xml schema. Zero-based.
416      *
417      * @param pos position in xml schema
418      * @return value
419      */

420     public Object JavaDoc getByPosition(int pos)
421     {
422             if (pos == 0)
423         {
424                 return getItemId();
425             }
426               if (pos == 1)
427         {
428                 return getModuleId();
429             }
430               if (pos == 2)
431         {
432                 return getIssueTypeId();
433             }
434               if (pos == 3)
435         {
436                 return getListId();
437             }
438               return null;
439     }
440      
441     /**
442      * Stores the object in the database. If the object is new,
443      * it inserts it; otherwise an update is performed.
444      *
445      * @throws Exception
446      */

447     public void save() throws Exception JavaDoc
448     {
449           save(MITListItemPeer.getMapBuilder()
450                 .getDatabaseMap().getName());
451       }
452
453     /**
454      * Stores the object in the database. If the object is new,
455      * it inserts it; otherwise an update is performed.
456        * Note: this code is here because the method body is
457      * auto-generated conditionally and therefore needs to be
458      * in this file instead of in the super class, BaseObject.
459        *
460      * @param dbName
461      * @throws TorqueException
462      */

463     public void save(String JavaDoc dbName) throws TorqueException
464     {
465         Connection JavaDoc con = null;
466           try
467         {
468             con = Transaction.begin(dbName);
469             save(con);
470             Transaction.commit(con);
471         }
472         catch(TorqueException e)
473         {
474             Transaction.safeRollback(con);
475             throw e;
476         }
477       }
478
479       /** flag to prevent endless save loop, if this object is referenced
480         by another object which falls in this transaction. */

481     private boolean alreadyInSave = false;
482       /**
483      * Stores the object in the database. If the object is new,
484      * it inserts it; otherwise an update is performed. This method
485      * is meant to be used as part of a transaction, otherwise use
486      * the save() method and the connection details will be handled
487      * internally
488      *
489      * @param con
490      * @throws TorqueException
491      */

492     public void save(Connection JavaDoc con) throws TorqueException
493     {
494           if (!alreadyInSave)
495         {
496             alreadyInSave = true;
497
498
499   
500             // If this object has been modified, then save it to the database.
501
if (isModified())
502             {
503                 if (isNew())
504                 {
505                     MITListItemPeer.doInsert((MITListItem)this, con);
506                     setNew(false);
507                 }
508                 else
509                 {
510                     MITListItemPeer.doUpdate((MITListItem)this, con);
511                 }
512
513                       if (isCacheOnSave())
514                 {
515                     MITListItemManager.putInstance(this);
516                 }
517               }
518
519                       alreadyInSave = false;
520         }
521       }
522
523     /**
524      * Specify whether to cache the object after saving to the db.
525      * This method returns false
526      */

527     protected boolean isCacheOnSave()
528     {
529         return true;
530     }
531
532                   
533       /**
534      * Set the PrimaryKey using ObjectKey.
535      *
536      * @param itemId ObjectKey
537      */

538     public void setPrimaryKey(ObjectKey itemId)
539          {
540             setItemId(new Long JavaDoc(((NumberKey)itemId).longValue()));
541         }
542
543     /**
544      * Set the PrimaryKey using a String.
545      *
546      * @param key
547      */

548     public void setPrimaryKey(String JavaDoc key)
549     {
550             setItemId(new Long JavaDoc(key));
551         }
552
553   
554     /**
555      * returns an id that differentiates this object from others
556      * of its class.
557      */

558     public ObjectKey getPrimaryKey()
559     {
560           return SimpleKey.keyFor(getItemId());
561       }
562  
563     /**
564      * get an id that differentiates this object from others
565      * of its class.
566      */

567     public String JavaDoc getQueryKey()
568     {
569         if (getPrimaryKey() == null)
570         {
571             return "";
572         }
573         else
574         {
575             return getPrimaryKey().toString();
576         }
577     }
578
579     /**
580      * set an id that differentiates this object from others
581      * of its class.
582      */

583     public void setQueryKey(String JavaDoc key)
584         throws TorqueException
585     {
586         setPrimaryKey(key);
587     }
588
589     /**
590      * Makes a copy of this object.
591      * It creates a new object filling in the simple attributes.
592        * It then fills all the association collections and sets the
593      * related objects to isNew=true.
594        */

595       public MITListItem copy() throws TorqueException
596     {
597         MITListItem copyObj = new MITListItem();
598             copyObj.setItemId(itemId);
599           copyObj.setModuleId(moduleId);
600           copyObj.setIssueTypeId(issueTypeId);
601           copyObj.setListId(listId);
602   
603                       copyObj.setItemId((Long JavaDoc)null);
604                               
605                 return copyObj;
606     }
607
608     /**
609      * returns a peer instance associated with this om. Since Peer classes
610      * are not to have any instance attributes, this method returns the
611      * same instance for all member of this class. The method could therefore
612      * be static, but this would prevent one from overriding the behavior.
613      */

614     public MITListItemPeer getPeer()
615     {
616         return peer;
617     }
618
619     public String JavaDoc toString()
620     {
621         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
622         str.append("MITListItem:\n");
623         str.append("ItemId = ")
624                .append(getItemId())
625              .append("\n");
626         str.append("ModuleId = ")
627                .append(getModuleId())
628              .append("\n");
629         str.append("IssueTypeId = ")
630                .append(getIssueTypeId())
631              .append("\n");
632         str.append("ListId = ")
633                .append(getListId())
634              .append("\n");
635         return(str.toString());
636     }
637 }
638
Popular Tags