KickJava   Java API By Example, From Geeks To Geeks.

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


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

30 public abstract class BaseAttachmentType extends BaseObject
31     implements org.apache.fulcrum.intake.Retrievable
32 {
33     /** The Peer class */
34     private static final AttachmentTypePeer peer =
35         new AttachmentTypePeer();
36
37         
38     /** The value for the attachmentTypeId field */
39     private Integer JavaDoc attachmentTypeId;
40       
41     /** The value for the name field */
42     private String JavaDoc name;
43                                                                 
44     /** The value for the searchable field */
45     private boolean searchable = false;
46   
47     
48     /**
49      * Get the AttachmentTypeId
50      *
51      * @return Integer
52      */

53     public Integer JavaDoc getAttachmentTypeId()
54     {
55         return attachmentTypeId;
56     }
57
58                                               
59     /**
60      * Set the value of AttachmentTypeId
61      *
62      * @param v new value
63      */

64     public void setAttachmentTypeId(Integer JavaDoc v) throws TorqueException
65     {
66     
67                   if (!ObjectUtils.equals(this.attachmentTypeId, v))
68               {
69             this.attachmentTypeId = v;
70             setModified(true);
71         }
72     
73           
74                                   
75         // update associated Attachment
76
if (collAttachments != null)
77         {
78             for (int i = 0; i < collAttachments.size(); i++)
79             {
80                 ((Attachment) collAttachments.get(i))
81                         .setTypeId(v);
82             }
83         }
84                       }
85   
86     /**
87      * Get the Name
88      *
89      * @return String
90      */

91     public String JavaDoc getName()
92     {
93         return name;
94     }
95
96                         
97     /**
98      * Set the value of Name
99      *
100      * @param v new value
101      */

102     public void setName(String JavaDoc v)
103     {
104     
105                   if (!ObjectUtils.equals(this.name, v))
106               {
107             this.name = v;
108             setModified(true);
109         }
110     
111           
112               }
113   
114     /**
115      * Get the Searchable
116      *
117      * @return boolean
118      */

119     public boolean getSearchable()
120     {
121         return searchable;
122     }
123
124                         
125     /**
126      * Set the value of Searchable
127      *
128      * @param v new value
129      */

130     public void setSearchable(boolean v)
131     {
132     
133                   if (this.searchable != v)
134               {
135             this.searchable = v;
136             setModified(true);
137         }
138     
139           
140               }
141   
142          
143                                 
144             
145     /**
146      * Collection to store aggregation of collAttachments
147      */

148     protected List JavaDoc collAttachments;
149
150     /**
151      * Temporary storage of collAttachments to save a possible db hit in
152      * the event objects are add to the collection, but the
153      * complete collection is never requested.
154      */

155     protected void initAttachments()
156     {
157         if (collAttachments == null)
158         {
159             collAttachments = new ArrayList JavaDoc();
160         }
161     }
162
163             
164     /**
165      * Method called to associate a Attachment object to this object
166      * through the Attachment foreign key attribute
167      *
168      * @param l Attachment
169      * @throws TorqueException
170      */

171     public void addAttachment(Attachment l) throws TorqueException
172     {
173         getAttachments().add(l);
174         l.setAttachmentType((AttachmentType)this);
175     }
176
177     /**
178      * The criteria used to select the current contents of collAttachments
179      */

180     private Criteria lastAttachmentsCriteria = null;
181
182     /**
183      * If this collection has already been initialized, returns
184      * the collection. Otherwise returns the results of
185      * getAttachments(new Criteria())
186      *
187      * @throws TorqueException
188      */

189     public List JavaDoc getAttachments() throws TorqueException
190     {
191         if (collAttachments == null)
192         {
193             collAttachments = getAttachments(new Criteria(10));
194         }
195         return collAttachments;
196     }
197
198     /**
199      * If this collection has already been initialized with
200      * an identical criteria, it returns the collection.
201      * Otherwise if this AttachmentType has previously
202      * been saved, it will retrieve related Attachments from storage.
203      * If this AttachmentType is new, it will return
204      * an empty collection or the current collection, the criteria
205      * is ignored on a new object.
206      *
207      * @throws TorqueException
208      */

209     public List JavaDoc getAttachments(Criteria criteria) throws TorqueException
210     {
211         if (collAttachments == null)
212         {
213             if (isNew())
214             {
215                collAttachments = new ArrayList JavaDoc();
216             }
217             else
218             {
219                       criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() );
220                       collAttachments = AttachmentPeer.doSelect(criteria);
221             }
222         }
223         else
224         {
225             // criteria has no effect for a new object
226
if (!isNew())
227             {
228                 // the following code is to determine if a new query is
229
// called for. If the criteria is the same as the last
230
// one, just return the collection.
231
criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() );
232                       if (!lastAttachmentsCriteria.equals(criteria))
233                 {
234                     collAttachments = AttachmentPeer.doSelect(criteria);
235                 }
236             }
237         }
238         lastAttachmentsCriteria = criteria;
239
240         return collAttachments;
241     }
242
243     /**
244      * If this collection has already been initialized, returns
245      * the collection. Otherwise returns the results of
246      * getAttachments(new Criteria(),Connection)
247      * This method takes in the Connection also as input so that
248      * referenced objects can also be obtained using a Connection
249      * that is taken as input
250      */

251     public List JavaDoc getAttachments(Connection JavaDoc con) throws TorqueException
252     {
253         if (collAttachments == null)
254         {
255             collAttachments = getAttachments(new Criteria(10),con);
256         }
257         return collAttachments;
258     }
259
260     /**
261      * If this collection has already been initialized with
262      * an identical criteria, it returns the collection.
263      * Otherwise if this AttachmentType has previously
264      * been saved, it will retrieve related Attachments from storage.
265      * If this AttachmentType is new, it will return
266      * an empty collection or the current collection, the criteria
267      * is ignored on a new object.
268      * This method takes in the Connection also as input so that
269      * referenced objects can also be obtained using a Connection
270      * that is taken as input
271      */

272     public List JavaDoc getAttachments(Criteria criteria,Connection JavaDoc con) throws TorqueException
273     {
274         if (collAttachments == null)
275         {
276             if (isNew())
277             {
278                collAttachments = new ArrayList JavaDoc();
279             }
280             else
281             {
282                        criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() );
283                        collAttachments = AttachmentPeer.doSelect(criteria,con);
284              }
285          }
286          else
287          {
288              // criteria has no effect for a new object
289
if (!isNew())
290              {
291                  // the following code is to determine if a new query is
292
// called for. If the criteria is the same as the last
293
// one, just return the collection.
294
criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() );
295                      if (!lastAttachmentsCriteria.equals(criteria))
296                  {
297                      collAttachments = AttachmentPeer.doSelect(criteria,con);
298                  }
299              }
300          }
301          lastAttachmentsCriteria = criteria;
302
303          return collAttachments;
304      }
305
306                                     
307               
308                     
309                     
310                                 
311                                                               
312                                         
313                     
314                     
315           
316     /**
317      * If this collection has already been initialized with
318      * an identical criteria, it returns the collection.
319      * Otherwise if this AttachmentType is new, it will return
320      * an empty collection; or if this AttachmentType has previously
321      * been saved, it will retrieve related Attachments from storage.
322      *
323      * This method is protected by default in order to keep the public
324      * api reasonable. You can provide public methods for those you
325      * actually need in AttachmentType.
326      */

327     protected List JavaDoc getAttachmentsJoinIssue(Criteria criteria)
328         throws TorqueException
329     {
330         if (collAttachments == null)
331         {
332             if (isNew())
333             {
334                collAttachments = new ArrayList JavaDoc();
335             }
336             else
337             {
338                             criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() );
339                             collAttachments = AttachmentPeer.doSelectJoinIssue(criteria);
340             }
341         }
342         else
343         {
344             // the following code is to determine if a new query is
345
// called for. If the criteria is the same as the last
346
// one, just return the collection.
347

348                             criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() );
349                         if (!lastAttachmentsCriteria.equals(criteria))
350             {
351                 collAttachments = AttachmentPeer.doSelectJoinIssue(criteria);
352             }
353         }
354         lastAttachmentsCriteria = criteria;
355
356         return collAttachments;
357     }
358                   
359                     
360                               
361                                 
362                                                               
363                                         
364                     
365                     
366           
367     /**
368      * If this collection has already been initialized with
369      * an identical criteria, it returns the collection.
370      * Otherwise if this AttachmentType is new, it will return
371      * an empty collection; or if this AttachmentType has previously
372      * been saved, it will retrieve related Attachments from storage.
373      *
374      * This method is protected by default in order to keep the public
375      * api reasonable. You can provide public methods for those you
376      * actually need in AttachmentType.
377      */

378     protected List JavaDoc getAttachmentsJoinAttachmentType(Criteria criteria)
379         throws TorqueException
380     {
381         if (collAttachments == null)
382         {
383             if (isNew())
384             {
385                collAttachments = new ArrayList JavaDoc();
386             }
387             else
388             {
389                             criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() );
390                             collAttachments = AttachmentPeer.doSelectJoinAttachmentType(criteria);
391             }
392         }
393         else
394         {
395             // the following code is to determine if a new query is
396
// called for. If the criteria is the same as the last
397
// one, just return the collection.
398

399                             criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() );
400                         if (!lastAttachmentsCriteria.equals(criteria))
401             {
402                 collAttachments = AttachmentPeer.doSelectJoinAttachmentType(criteria);
403             }
404         }
405         lastAttachmentsCriteria = criteria;
406
407         return collAttachments;
408     }
409                   
410                     
411                     
412                                             
413                                                                           
414                                         
415                     
416                     
417           
418     /**
419      * If this collection has already been initialized with
420      * an identical criteria, it returns the collection.
421      * Otherwise if this AttachmentType is new, it will return
422      * an empty collection; or if this AttachmentType has previously
423      * been saved, it will retrieve related Attachments from storage.
424      *
425      * This method is protected by default in order to keep the public
426      * api reasonable. You can provide public methods for those you
427      * actually need in AttachmentType.
428      */

429     protected List JavaDoc getAttachmentsJoinScarabUserImplRelatedByCreatedBy(Criteria criteria)
430         throws TorqueException
431     {
432         if (collAttachments == null)
433         {
434             if (isNew())
435             {
436                collAttachments = new ArrayList JavaDoc();
437             }
438             else
439             {
440                             criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() );
441                             collAttachments = AttachmentPeer.doSelectJoinScarabUserImplRelatedByCreatedBy(criteria);
442             }
443         }
444         else
445         {
446             // the following code is to determine if a new query is
447
// called for. If the criteria is the same as the last
448
// one, just return the collection.
449

450                             criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() );
451                         if (!lastAttachmentsCriteria.equals(criteria))
452             {
453                 collAttachments = AttachmentPeer.doSelectJoinScarabUserImplRelatedByCreatedBy(criteria);
454             }
455         }
456         lastAttachmentsCriteria = criteria;
457
458         return collAttachments;
459     }
460                   
461                     
462                     
463                                             
464                                                                           
465                                         
466                     
467                     
468           
469     /**
470      * If this collection has already been initialized with
471      * an identical criteria, it returns the collection.
472      * Otherwise if this AttachmentType is new, it will return
473      * an empty collection; or if this AttachmentType has previously
474      * been saved, it will retrieve related Attachments from storage.
475      *
476      * This method is protected by default in order to keep the public
477      * api reasonable. You can provide public methods for those you
478      * actually need in AttachmentType.
479      */

480     protected List JavaDoc getAttachmentsJoinScarabUserImplRelatedByModifiedBy(Criteria criteria)
481         throws TorqueException
482     {
483         if (collAttachments == null)
484         {
485             if (isNew())
486             {
487                collAttachments = new ArrayList JavaDoc();
488             }
489             else
490             {
491                             criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() );
492                             collAttachments = AttachmentPeer.doSelectJoinScarabUserImplRelatedByModifiedBy(criteria);
493             }
494         }
495         else
496         {
497             // the following code is to determine if a new query is
498
// called for. If the criteria is the same as the last
499
// one, just return the collection.
500

501                             criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() );
502                         if (!lastAttachmentsCriteria.equals(criteria))
503             {
504                 collAttachments = AttachmentPeer.doSelectJoinScarabUserImplRelatedByModifiedBy(criteria);
505             }
506         }
507         lastAttachmentsCriteria = criteria;
508
509         return collAttachments;
510     }
511                             
512
513
514           
515     private static List JavaDoc fieldNames = null;
516
517     /**
518      * Generate a list of field names.
519      *
520      * @return a list of field names
521      */

522     public static synchronized List JavaDoc getFieldNames()
523     {
524         if (fieldNames == null)
525         {
526             fieldNames = new ArrayList JavaDoc();
527               fieldNames.add("AttachmentTypeId");
528               fieldNames.add("Name");
529               fieldNames.add("Searchable");
530               fieldNames = Collections.unmodifiableList(fieldNames);
531         }
532         return fieldNames;
533     }
534
535     /**
536      * Retrieves a field from the object by name passed in as a String.
537      *
538      * @param name field name
539      * @return value
540      */

541     public Object JavaDoc getByName(String JavaDoc name)
542     {
543           if (name.equals("AttachmentTypeId"))
544         {
545                 return getAttachmentTypeId();
546             }
547           if (name.equals("Name"))
548         {
549                 return getName();
550             }
551           if (name.equals("Searchable"))
552         {
553                 return Boolean.valueOf(getSearchable());
554             }
555           return null;
556     }
557     
558     /**
559      * Retrieves a field from the object by name passed in
560      * as a String. The String must be one of the static
561      * Strings defined in this Class' Peer.
562      *
563      * @param name peer name
564      * @return value
565      */

566     public Object JavaDoc getByPeerName(String JavaDoc name)
567     {
568           if (name.equals(AttachmentTypePeer.ATTACHMENT_TYPE_ID))
569         {
570                 return getAttachmentTypeId();
571             }
572           if (name.equals(AttachmentTypePeer.ATTACHMENT_TYPE_NAME))
573         {
574                 return getName();
575             }
576           if (name.equals(AttachmentTypePeer.SEARCHABLE))
577         {
578                 return Boolean.valueOf(getSearchable());
579             }
580           return null;
581     }
582
583     /**
584      * Retrieves a field from the object by Position as specified
585      * in the xml schema. Zero-based.
586      *
587      * @param pos position in xml schema
588      * @return value
589      */

590     public Object JavaDoc getByPosition(int pos)
591     {
592             if (pos == 0)
593         {
594                 return getAttachmentTypeId();
595             }
596               if (pos == 1)
597         {
598                 return getName();
599             }
600               if (pos == 2)
601         {
602                 return Boolean.valueOf(getSearchable());
603             }
604               return null;
605     }
606      
607     /**
608      * Stores the object in the database. If the object is new,
609      * it inserts it; otherwise an update is performed.
610      *
611      * @throws Exception
612      */

613     public void save() throws Exception JavaDoc
614     {
615           save(AttachmentTypePeer.getMapBuilder()
616                 .getDatabaseMap().getName());
617       }
618
619     /**
620      * Stores the object in the database. If the object is new,
621      * it inserts it; otherwise an update is performed.
622        * Note: this code is here because the method body is
623      * auto-generated conditionally and therefore needs to be
624      * in this file instead of in the super class, BaseObject.
625        *
626      * @param dbName
627      * @throws TorqueException
628      */

629     public void save(String JavaDoc dbName) throws TorqueException
630     {
631         Connection JavaDoc con = null;
632           try
633         {
634             con = Transaction.begin(dbName);
635             save(con);
636             Transaction.commit(con);
637         }
638         catch(TorqueException e)
639         {
640             Transaction.safeRollback(con);
641             throw e;
642         }
643       }
644
645       /** flag to prevent endless save loop, if this object is referenced
646         by another object which falls in this transaction. */

647     private boolean alreadyInSave = false;
648       /**
649      * Stores the object in the database. If the object is new,
650      * it inserts it; otherwise an update is performed. This method
651      * is meant to be used as part of a transaction, otherwise use
652      * the save() method and the connection details will be handled
653      * internally
654      *
655      * @param con
656      * @throws TorqueException
657      */

658     public void save(Connection JavaDoc con) throws TorqueException
659     {
660           if (!alreadyInSave)
661         {
662             alreadyInSave = true;
663
664
665   
666             // If this object has been modified, then save it to the database.
667
if (isModified())
668             {
669                 if (isNew())
670                 {
671                     AttachmentTypePeer.doInsert((AttachmentType)this, con);
672                     setNew(false);
673                 }
674                 else
675                 {
676                     AttachmentTypePeer.doUpdate((AttachmentType)this, con);
677                 }
678
679                       if (isCacheOnSave())
680                 {
681                     AttachmentTypeManager.putInstance(this);
682                 }
683               }
684
685                                       
686                             if (collAttachments != null)
687             {
688                 for (int i = 0; i < collAttachments.size(); i++)
689                 {
690                     ((Attachment)collAttachments.get(i)).save(con);
691                 }
692             }
693                           alreadyInSave = false;
694         }
695       }
696
697     /**
698      * Specify whether to cache the object after saving to the db.
699      * This method returns false
700      */

701     protected boolean isCacheOnSave()
702     {
703         return true;
704     }
705
706                         
707       /**
708      * Set the PrimaryKey using ObjectKey.
709      *
710      * @param attachmentTypeId ObjectKey
711      */

712     public void setPrimaryKey(ObjectKey attachmentTypeId)
713         throws TorqueException {
714             setAttachmentTypeId(new Integer JavaDoc(((NumberKey)attachmentTypeId).intValue()));
715         }
716
717     /**
718      * Set the PrimaryKey using a String.
719      *
720      * @param key
721      */

722     public void setPrimaryKey(String JavaDoc key) throws TorqueException
723     {
724             setAttachmentTypeId(new Integer JavaDoc(key));
725         }
726
727   
728     /**
729      * returns an id that differentiates this object from others
730      * of its class.
731      */

732     public ObjectKey getPrimaryKey()
733     {
734           return SimpleKey.keyFor(getAttachmentTypeId());
735       }
736  
737     /**
738      * get an id that differentiates this object from others
739      * of its class.
740      */

741     public String JavaDoc getQueryKey()
742     {
743         if (getPrimaryKey() == null)
744         {
745             return "";
746         }
747         else
748         {
749             return getPrimaryKey().toString();
750         }
751     }
752
753     /**
754      * set an id that differentiates this object from others
755      * of its class.
756      */

757     public void setQueryKey(String JavaDoc key)
758         throws TorqueException
759     {
760         setPrimaryKey(key);
761     }
762
763     /**
764      * Makes a copy of this object.
765      * It creates a new object filling in the simple attributes.
766        * It then fills all the association collections and sets the
767      * related objects to isNew=true.
768        */

769       public AttachmentType copy() throws TorqueException
770     {
771         AttachmentType copyObj = new AttachmentType();
772             copyObj.setAttachmentTypeId(attachmentTypeId);
773           copyObj.setName(name);
774           copyObj.setSearchable(searchable);
775   
776                       copyObj.setAttachmentTypeId((Integer JavaDoc)null);
777                         
778                                       
779                 
780         List JavaDoc v = getAttachments();
781         for (int i = 0; i < v.size(); i++)
782         {
783             Attachment obj = (Attachment) v.get(i);
784             copyObj.addAttachment(obj.copy());
785         }
786                             return copyObj;
787     }
788
789     /**
790      * returns a peer instance associated with this om. Since Peer classes
791      * are not to have any instance attributes, this method returns the
792      * same instance for all member of this class. The method could therefore
793      * be static, but this would prevent one from overriding the behavior.
794      */

795     public AttachmentTypePeer getPeer()
796     {
797         return peer;
798     }
799
800     public String JavaDoc toString()
801     {
802         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
803         str.append("AttachmentType:\n");
804         str.append("AttachmentTypeId = ")
805                .append(getAttachmentTypeId())
806              .append("\n");
807         str.append("Name = ")
808                .append(getName())
809              .append("\n");
810         str.append("Searchable = ")
811                .append(getSearchable())
812              .append("\n");
813         return(str.toString());
814     }
815 }
816
Popular Tags