View Javadoc

1   package net.sourceforge.blogentis.om;
2   
3   
4   import java.sql.Connection;
5   import java.util.ArrayList;
6   import java.util.Collections;
7   import java.util.List;
8   
9   import org.apache.commons.lang.ObjectUtils;
10  import org.apache.torque.TorqueException;
11  import org.apache.torque.om.NumberKey;
12  import org.apache.torque.om.ObjectKey;
13  import org.apache.torque.om.SimpleKey;
14  import org.apache.torque.util.Criteria;
15  import org.apache.torque.util.Transaction;
16  
17    
18    
19  /***
20   * You should not use this class directly.  It should not even be
21   * extended all references should be to Section
22   */
23  public abstract class BaseSection extends net.sourceforge.blogentis.om.BaseConfigurable
24      implements org.apache.turbine.om.Retrievable
25  {
26      /*** The Peer class */
27      private static final SectionPeer peer =
28          new SectionPeer();
29  
30          
31      /*** The value for the sectionId field */
32      private int sectionId;
33        
34      /*** The value for the blogId field */
35      private int blogId;
36        
37      /*** The value for the name field */
38      private String name;
39        
40      /*** The value for the title field */
41      private String title;
42        
43      /*** The value for the description field */
44      private String description;
45        
46      /*** The value for the objectData field */
47      private byte[] objectData;
48    
49      
50      /***
51       * Get the SectionId
52       *
53       * @return int
54       */
55      public int getSectionId()
56      {
57          return sectionId;
58      }
59  
60                                                
61      /***
62       * Set the value of SectionId
63       *
64       * @param v new value
65       */
66      public void setSectionId(int v) throws TorqueException
67      {
68      
69                    if (this.sectionId != v)
70                {
71              this.sectionId = v;
72              setModified(true);
73          }
74      
75            
76                                    
77                    // update associated PostSection
78          if (collPostSections != null)
79          {
80              for (int i = 0; i < collPostSections.size(); i++)
81              {
82                  ((PostSection) collPostSections.get(i))
83                      .setSectionId(v);
84              }
85          }
86                                  }
87    
88      /***
89       * Get the BlogId
90       *
91       * @return int
92       */
93      public int getBlogId()
94      {
95          return blogId;
96      }
97  
98                                
99      /***
100      * Set the value of BlogId
101      *
102      * @param v new value
103      */
104     public void setBlogId(int v) throws TorqueException
105     {
106     
107                   if (this.blogId != v)
108               {
109             this.blogId = v;
110             setModified(true);
111         }
112     
113                           
114                 if (aStoredBlog != null && !(aStoredBlog.getBlogId() == v))
115                 {
116             aStoredBlog = null;
117         }
118       
119               }
120   
121     /***
122      * Get the Name
123      *
124      * @return String
125      */
126     public String getName()
127     {
128         return name;
129     }
130 
131                         
132     /***
133      * Set the value of Name
134      *
135      * @param v new value
136      */
137     public void setName(String v) 
138     {
139     
140                   if (!ObjectUtils.equals(this.name, v))
141               {
142             this.name = v;
143             setModified(true);
144         }
145     
146           
147               }
148   
149     /***
150      * Get the Title
151      *
152      * @return String
153      */
154     public String getTitle()
155     {
156         return title;
157     }
158 
159                         
160     /***
161      * Set the value of Title
162      *
163      * @param v new value
164      */
165     public void setTitle(String v) 
166     {
167     
168                   if (!ObjectUtils.equals(this.title, v))
169               {
170             this.title = v;
171             setModified(true);
172         }
173     
174           
175               }
176   
177     /***
178      * Get the Description
179      *
180      * @return String
181      */
182     public String getDescription()
183     {
184         return description;
185     }
186 
187                         
188     /***
189      * Set the value of Description
190      *
191      * @param v new value
192      */
193     public void setDescription(String v) 
194     {
195     
196                   if (!ObjectUtils.equals(this.description, v))
197               {
198             this.description = v;
199             setModified(true);
200         }
201     
202           
203               }
204   
205     /***
206      * Get the ObjectData
207      *
208      * @return byte[]
209      */
210     public byte[] getObjectData()
211     {
212         return objectData;
213     }
214 
215                         
216     /***
217      * Set the value of ObjectData
218      *
219      * @param v new value
220      */
221     public void setObjectData(byte[] v) 
222     {
223     
224                   if (!ObjectUtils.equals(this.objectData, v))
225               {
226             this.objectData = v;
227             setModified(true);
228         }
229     
230           
231               }
232   
233       
234     
235                   
236     
237         private StoredBlog aStoredBlog;
238 
239     /***
240      * Declares an association between this object and a StoredBlog object
241      *
242      * @param v StoredBlog
243      * @throws TorqueException
244      */
245     public void setStoredBlog(StoredBlog v) throws TorqueException
246     {
247             if (v == null)
248         {
249                           setBlogId( 0);
250               }
251         else
252         {
253             setBlogId(v.getBlogId());
254         }
255             aStoredBlog = v;
256     }
257 
258                                             
259     /***
260      * Get the associated StoredBlog object
261      *
262      * @return the associated StoredBlog object
263      * @throws TorqueException
264      */
265     public StoredBlog getStoredBlog() throws TorqueException
266     {
267         if (aStoredBlog == null && (this.blogId > 0))
268         {
269                           aStoredBlog = StoredBlogPeer.retrieveByPK(SimpleKey.keyFor(this.blogId));
270               
271             /* The following can be used instead of the line above to
272                guarantee the related object contains a reference
273                to this object, but this level of coupling
274                may be undesirable in many circumstances.
275                As it can lead to a db query with many results that may
276                never be used.
277                StoredBlog obj = StoredBlogPeer.retrieveByPK(this.blogId);
278                obj.addSections(this);
279             */
280         }
281         return aStoredBlog;
282     }
283 
284     /***
285      * Provides convenient way to set a relationship based on a
286      * ObjectKey.  e.g.
287      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
288      *
289          */
290     public void setStoredBlogKey(ObjectKey key) throws TorqueException
291     {
292       
293                         setBlogId(((NumberKey) key).intValue());
294                   }
295        
296                                 
297             
298           /***
299      * Collection to store aggregation of collPostSections
300      */
301     protected List collPostSections;
302 
303     /***
304      * Temporary storage of collPostSections to save a possible db hit in
305      * the event objects are add to the collection, but the
306      * complete collection is never requested.
307      */
308     protected void initPostSections()
309     {
310         if (collPostSections == null)
311         {
312             collPostSections = new ArrayList();
313         }
314     }
315 
316     /***
317      * Method called to associate a PostSection object to this object
318      * through the PostSection foreign key attribute
319      *
320      * @param l PostSection
321      * @throws TorqueException
322      */
323     public void addPostSection(PostSection l) throws TorqueException
324     {
325         getPostSections().add(l);
326         l.setSection((Section) this);
327     }
328 
329     /***
330      * The criteria used to select the current contents of collPostSections
331      */
332     private Criteria lastPostSectionsCriteria = null;
333       
334     /***
335      * If this collection has already been initialized, returns
336      * the collection. Otherwise returns the results of
337      * getPostSections(new Criteria())
338      *
339      * @throws TorqueException
340      */
341     public List getPostSections() throws TorqueException
342     {
343               if (collPostSections == null)
344         {
345             collPostSections = getPostSections(new Criteria(10));
346         }
347         return collPostSections;
348           }
349 
350     /***
351      * If this collection has already been initialized with
352      * an identical criteria, it returns the collection.
353      * Otherwise if this Section has previously
354      * been saved, it will retrieve related PostSections from storage.
355      * If this Section is new, it will return
356      * an empty collection or the current collection, the criteria
357      * is ignored on a new object.
358      *
359      * @throws TorqueException
360      */
361     public List getPostSections(Criteria criteria) throws TorqueException
362     {
363               if (collPostSections == null)
364         {
365             if (isNew())
366             {
367                collPostSections = new ArrayList();
368             }
369             else
370             {
371                         criteria.add(PostSectionPeer.SECTION_ID, getSectionId() );
372                         collPostSections = PostSectionPeer.doSelect(criteria);
373             }
374         }
375         else
376         {
377             // criteria has no effect for a new object
378             if (!isNew())
379             {
380                 // the following code is to determine if a new query is
381                 // called for.  If the criteria is the same as the last
382                 // one, just return the collection.
383                             criteria.add(PostSectionPeer.SECTION_ID, getSectionId());
384                             if (!lastPostSectionsCriteria.equals(criteria))
385                 {
386                     collPostSections = PostSectionPeer.doSelect(criteria);
387                 }
388             }
389         }
390         lastPostSectionsCriteria = criteria;
391 
392         return collPostSections;
393           }
394 
395     /***
396      * If this collection has already been initialized, returns
397      * the collection. Otherwise returns the results of
398      * getPostSections(new Criteria(),Connection)
399      * This method takes in the Connection also as input so that
400      * referenced objects can also be obtained using a Connection
401      * that is taken as input
402      */
403     public List getPostSections(Connection con) throws TorqueException
404     {
405               if (collPostSections == null)
406         {
407             collPostSections = getPostSections(new Criteria(10), con);
408         }
409         return collPostSections;
410           }
411 
412     /***
413      * If this collection has already been initialized with
414      * an identical criteria, it returns the collection.
415      * Otherwise if this Section has previously
416      * been saved, it will retrieve related PostSections from storage.
417      * If this Section is new, it will return
418      * an empty collection or the current collection, the criteria
419      * is ignored on a new object.
420      * This method takes in the Connection also as input so that
421      * referenced objects can also be obtained using a Connection
422      * that is taken as input
423      */
424     public List getPostSections(Criteria criteria, Connection con)
425             throws TorqueException
426     {
427               if (collPostSections == null)
428         {
429             if (isNew())
430             {
431                collPostSections = new ArrayList();
432             }
433             else
434             {
435                          criteria.add(PostSectionPeer.SECTION_ID, getSectionId());
436                          collPostSections = PostSectionPeer.doSelect(criteria, con);
437              }
438          }
439          else
440          {
441              // criteria has no effect for a new object
442              if (!isNew())
443              {
444                  // the following code is to determine if a new query is
445                  // called for.  If the criteria is the same as the last
446                  // one, just return the collection.
447                               criteria.add(PostSectionPeer.SECTION_ID, getSectionId());
448                              if (!lastPostSectionsCriteria.equals(criteria))
449                  {
450                      collPostSections = PostSectionPeer.doSelect(criteria, con);
451                  }
452              }
453          }
454          lastPostSectionsCriteria = criteria;
455 
456          return collPostSections;
457            }
458 
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 Section is new, it will return
473      * an empty collection; or if this Section has previously
474      * been saved, it will retrieve related PostSections 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 Section.
479      */
480     protected List getPostSectionsJoinPost(Criteria criteria)
481         throws TorqueException
482     {
483                     if (collPostSections == null)
484         {
485             if (isNew())
486             {
487                collPostSections = new ArrayList();
488             }
489             else
490             {
491                               criteria.add(PostSectionPeer.SECTION_ID, getSectionId());
492                               collPostSections = PostSectionPeer.doSelectJoinPost(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                         boolean newCriteria = true;
501                         criteria.add(PostSectionPeer.SECTION_ID, getSectionId());
502                                     if (!lastPostSectionsCriteria.equals(criteria))
503             {
504                 collPostSections = PostSectionPeer.doSelectJoinPost(criteria);
505             }
506         }
507         lastPostSectionsCriteria = criteria;
508 
509         return collPostSections;
510                 }
511                   
512                     
513                               
514                                 
515                                                               
516                                         
517                     
518                     
519           
520     /***
521      * If this collection has already been initialized with
522      * an identical criteria, it returns the collection.
523      * Otherwise if this Section is new, it will return
524      * an empty collection; or if this Section has previously
525      * been saved, it will retrieve related PostSections from storage.
526      *
527      * This method is protected by default in order to keep the public
528      * api reasonable.  You can provide public methods for those you
529      * actually need in Section.
530      */
531     protected List getPostSectionsJoinSection(Criteria criteria)
532         throws TorqueException
533     {
534                     if (collPostSections == null)
535         {
536             if (isNew())
537             {
538                collPostSections = new ArrayList();
539             }
540             else
541             {
542                               criteria.add(PostSectionPeer.SECTION_ID, getSectionId());
543                               collPostSections = PostSectionPeer.doSelectJoinSection(criteria);
544             }
545         }
546         else
547         {
548             // the following code is to determine if a new query is
549             // called for.  If the criteria is the same as the last
550             // one, just return the collection.
551                         boolean newCriteria = true;
552                         criteria.add(PostSectionPeer.SECTION_ID, getSectionId());
553                                     if (!lastPostSectionsCriteria.equals(criteria))
554             {
555                 collPostSections = PostSectionPeer.doSelectJoinSection(criteria);
556             }
557         }
558         lastPostSectionsCriteria = criteria;
559 
560         return collPostSections;
561                 }
562                             
563 
564 
565           
566     private static List fieldNames = null;
567 
568     /***
569      * Generate a list of field names.
570      *
571      * @return a list of field names
572      */
573     public static synchronized List getFieldNames()
574     {
575         if (fieldNames == null)
576         {
577             fieldNames = new ArrayList();
578               fieldNames.add("SectionId");
579               fieldNames.add("BlogId");
580               fieldNames.add("Name");
581               fieldNames.add("Title");
582               fieldNames.add("Description");
583               fieldNames.add("ObjectData");
584               fieldNames = Collections.unmodifiableList(fieldNames);
585         }
586         return fieldNames;
587     }
588 
589     /***
590      * Retrieves a field from the object by name passed in as a String.
591      *
592      * @param name field name
593      * @return value
594      */
595     public Object getByName(String name)
596     {
597           if (name.equals("SectionId"))
598         {
599                 return new Integer(getSectionId());
600             }
601           if (name.equals("BlogId"))
602         {
603                 return new Integer(getBlogId());
604             }
605           if (name.equals("Name"))
606         {
607                 return getName();
608             }
609           if (name.equals("Title"))
610         {
611                 return getTitle();
612             }
613           if (name.equals("Description"))
614         {
615                 return getDescription();
616             }
617           if (name.equals("ObjectData"))
618         {
619                 return getObjectData();
620             }
621           return null;
622     }
623     
624     /***
625      * Retrieves a field from the object by name passed in
626      * as a String.  The String must be one of the static
627      * Strings defined in this Class' Peer.
628      *
629      * @param name peer name
630      * @return value
631      */
632     public Object getByPeerName(String name)
633     {
634           if (name.equals(SectionPeer.SECTION_ID))
635         {
636                 return new Integer(getSectionId());
637             }
638           if (name.equals(SectionPeer.BLOG_ID))
639         {
640                 return new Integer(getBlogId());
641             }
642           if (name.equals(SectionPeer.NAME))
643         {
644                 return getName();
645             }
646           if (name.equals(SectionPeer.TITLE))
647         {
648                 return getTitle();
649             }
650           if (name.equals(SectionPeer.DESCRIPTION))
651         {
652                 return getDescription();
653             }
654           if (name.equals(SectionPeer.OBJECT_DATA))
655         {
656                 return getObjectData();
657             }
658           return null;
659     }
660 
661     /***
662      * Retrieves a field from the object by Position as specified
663      * in the xml schema.  Zero-based.
664      *
665      * @param pos position in xml schema
666      * @return value
667      */
668     public Object getByPosition(int pos)
669     {
670             if (pos == 0)
671         {
672                 return new Integer(getSectionId());
673             }
674               if (pos == 1)
675         {
676                 return new Integer(getBlogId());
677             }
678               if (pos == 2)
679         {
680                 return getName();
681             }
682               if (pos == 3)
683         {
684                 return getTitle();
685             }
686               if (pos == 4)
687         {
688                 return getDescription();
689             }
690               if (pos == 5)
691         {
692                 return getObjectData();
693             }
694               return null;
695     }
696      
697     /***
698      * Stores the object in the database.  If the object is new,
699      * it inserts it; otherwise an update is performed.
700      *
701      * @throws Exception
702      */
703     public void save() throws Exception
704     {
705           save(SectionPeer.getMapBuilder()
706                 .getDatabaseMap().getName());
707       }
708 
709     /***
710      * Stores the object in the database.  If the object is new,
711      * it inserts it; otherwise an update is performed.
712        * Note: this code is here because the method body is
713      * auto-generated conditionally and therefore needs to be
714      * in this file instead of in the super class, BaseObject.
715        *
716      * @param dbName
717      * @throws TorqueException
718      */
719     public void save(String dbName) throws TorqueException
720     {
721         Connection con = null;
722           try
723         {
724             con = Transaction.begin(dbName);
725             save(con);
726             Transaction.commit(con);
727         }
728         catch(TorqueException e)
729         {
730             Transaction.safeRollback(con);
731             throw e;
732         }
733       }
734 
735       /*** flag to prevent endless save loop, if this object is referenced
736         by another object which falls in this transaction. */
737     private boolean alreadyInSave = false;
738       /***
739      * Stores the object in the database.  If the object is new,
740      * it inserts it; otherwise an update is performed.  This method
741      * is meant to be used as part of a transaction, otherwise use
742      * the save() method and the connection details will be handled
743      * internally
744      *
745      * @param con
746      * @throws TorqueException
747      */
748     public void save(Connection con) throws TorqueException
749     {
750           if (!alreadyInSave)
751         {
752             alreadyInSave = true;
753 
754 
755   
756             // If this object has been modified, then save it to the database.
757             if (isModified())
758             {
759                 if (isNew())
760                 {
761                     SectionPeer.doInsert((Section) this, con);
762                     setNew(false);
763                 }
764                 else
765                 {
766                     SectionPeer.doUpdate((Section) this, con);
767                 }
768             }
769 
770                                       
771                 
772                     if (collPostSections != null)
773             {
774                 for (int i = 0; i < collPostSections.size(); i++)
775                 {
776                     ((PostSection) collPostSections.get(i)).save(con);
777                 }
778             }
779                                   alreadyInSave = false;
780         }
781       }
782 
783                         
784       /***
785      * Set the PrimaryKey using ObjectKey.
786      *
787      * @param  sectionId ObjectKey
788      */
789     public void setPrimaryKey(ObjectKey key)
790         throws TorqueException
791     {
792             setSectionId(((NumberKey) key).intValue());
793         }
794 
795     /***
796      * Set the PrimaryKey using a String.
797      *
798      * @param key
799      */
800     public void setPrimaryKey(String key) throws TorqueException
801     {
802             setSectionId(Integer.parseInt(key));
803         }
804 
805   
806     /***
807      * returns an id that differentiates this object from others
808      * of its class.
809      */
810     public ObjectKey getPrimaryKey()
811     {
812           return SimpleKey.keyFor(getSectionId());
813       }
814  
815     /***
816      * get an id that differentiates this object from others
817      * of its class.
818      */
819     public String getQueryKey()
820     {
821         if (getPrimaryKey() == null)
822         {
823             return "";
824         }
825         else
826         {
827             return getPrimaryKey().toString();
828         }
829     }
830 
831     /***
832      * set an id that differentiates this object from others
833      * of its class.
834      */
835     public void setQueryKey(String key)
836         throws TorqueException
837     {
838         setPrimaryKey(key);
839     }
840 
841     /***
842      * Makes a copy of this object.
843      * It creates a new object filling in the simple attributes.
844        * It then fills all the association collections and sets the
845      * related objects to isNew=true.
846        */
847       public Section copy() throws TorqueException
848     {
849         return copyInto(new Section());
850     }
851   
852     protected Section copyInto(Section copyObj) throws TorqueException
853     {
854           copyObj.setSectionId(sectionId);
855           copyObj.setBlogId(blogId);
856           copyObj.setName(name);
857           copyObj.setTitle(title);
858           copyObj.setDescription(description);
859           copyObj.setObjectData(objectData);
860   
861                             copyObj.setSectionId( 0);
862                                           
863                                       
864                             
865         List v = getPostSections();
866         for (int i = 0; i < v.size(); i++)
867         {
868             PostSection obj = (PostSection) v.get(i);
869             copyObj.addPostSection(obj.copy());
870         }
871                             return copyObj;
872     }
873 
874     /***
875      * returns a peer instance associated with this om.  Since Peer classes
876      * are not to have any instance attributes, this method returns the
877      * same instance for all member of this class. The method could therefore
878      * be static, but this would prevent one from overriding the behavior.
879      */
880     public SectionPeer getPeer()
881     {
882         return peer;
883     }
884 
885     public String toString()
886     {
887         StringBuffer str = new StringBuffer();
888         str.append("Section:\n");
889         str.append("SectionId = ")
890            .append(getSectionId())
891            .append("\n");
892         str.append("BlogId = ")
893            .append(getBlogId())
894            .append("\n");
895         str.append("Name = ")
896            .append(getName())
897            .append("\n");
898         str.append("Title = ")
899            .append(getTitle())
900            .append("\n");
901         str.append("Description = ")
902            .append(getDescription())
903            .append("\n");
904         str.append("ObjectData = ")
905            .append(getObjectData())
906            .append("\n");
907         return(str.toString());
908     }
909 }