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