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.Date;
8 import java.util.List;
9
10 import org.apache.commons.lang.ObjectUtils;
11 import org.apache.torque.TorqueException;
12 import org.apache.torque.om.NumberKey;
13 import org.apache.torque.om.ObjectKey;
14 import org.apache.torque.om.SimpleKey;
15 import org.apache.torque.util.Criteria;
16 import org.apache.torque.util.Transaction;
17
18
19
20 /***
21 * You should not use this class directly. It should not even be
22 * extended all references should be to Post
23 */
24 public abstract class BasePost extends net.sourceforge.blogentis.om.BaseConfigurable
25 implements org.apache.turbine.om.Retrievable
26 {
27 /*** The Peer class */
28 private static final PostPeer peer =
29 new PostPeer();
30
31
32 /*** The value for the postId field */
33 private int postId;
34
35 /*** The value for the blogId field */
36 private int blogId;
37
38 /*** The value for the postType field */
39 private int postType = 0;
40
41 /*** The value for the title field */
42 private String title;
43
44 /*** The value for the uriFragment field */
45 private String uriFragment;
46
47 /*** The value for the shortDescription field */
48 private String shortDescription;
49
50 /*** The value for the fullText field */
51 private String fullText;
52
53 /*** The value for the postedTime field */
54 private Date postedTime;
55
56 /*** The value for the authorId field */
57 private String authorId;
58
59 /*** The value for the objectData field */
60 private byte[] objectData;
61
62
63 /***
64 * Get the PostId
65 *
66 * @return int
67 */
68 public int getPostId()
69 {
70 return postId;
71 }
72
73
74 /***
75 * Set the value of PostId
76 *
77 * @param v new value
78 */
79 public void setPostId(int v) throws TorqueException
80 {
81
82 if (this.postId != v)
83 {
84 this.postId = v;
85 setModified(true);
86 }
87
88
89
90
91 if (collPostSections != null)
92 {
93 for (int i = 0; i < collPostSections.size(); i++)
94 {
95 ((PostSection) collPostSections.get(i))
96 .setPostId(v);
97 }
98 }
99
100
101 if (collComments != null)
102 {
103 for (int i = 0; i < collComments.size(); i++)
104 {
105 ((Comment) collComments.get(i))
106 .setPostId(v);
107 }
108 }
109 }
110
111 /***
112 * Get the BlogId
113 *
114 * @return int
115 */
116 public int getBlogId()
117 {
118 return blogId;
119 }
120
121
122 /***
123 * Set the value of BlogId
124 *
125 * @param v new value
126 */
127 public void setBlogId(int v) throws TorqueException
128 {
129
130 if (this.blogId != v)
131 {
132 this.blogId = v;
133 setModified(true);
134 }
135
136
137 if (aStoredBlog != null && !(aStoredBlog.getBlogId() == v))
138 {
139 aStoredBlog = null;
140 }
141
142 }
143
144 /***
145 * Get the PostType
146 *
147 * @return int
148 */
149 public int getPostType()
150 {
151 return postType;
152 }
153
154
155 /***
156 * Set the value of PostType
157 *
158 * @param v new value
159 */
160 public void setPostType(int v)
161 {
162
163 if (this.postType != v)
164 {
165 this.postType = v;
166 setModified(true);
167 }
168
169
170 }
171
172 /***
173 * Get the Title
174 *
175 * @return String
176 */
177 public String getTitle()
178 {
179 return title;
180 }
181
182
183 /***
184 * Set the value of Title
185 *
186 * @param v new value
187 */
188 public void setTitle(String v)
189 {
190
191 if (!ObjectUtils.equals(this.title, v))
192 {
193 this.title = v;
194 setModified(true);
195 }
196
197
198 }
199
200 /***
201 * Get the UriFragment
202 *
203 * @return String
204 */
205 public String getUriFragment()
206 {
207 return uriFragment;
208 }
209
210
211 /***
212 * Set the value of UriFragment
213 *
214 * @param v new value
215 */
216 public void setUriFragment(String v)
217 {
218
219 if (!ObjectUtils.equals(this.uriFragment, v))
220 {
221 this.uriFragment = v;
222 setModified(true);
223 }
224
225
226 }
227
228 /***
229 * Get the ShortDescription
230 *
231 * @return String
232 */
233 public String getShortDescription()
234 {
235 return shortDescription;
236 }
237
238
239 /***
240 * Set the value of ShortDescription
241 *
242 * @param v new value
243 */
244 public void setShortDescription(String v)
245 {
246
247 if (!ObjectUtils.equals(this.shortDescription, v))
248 {
249 this.shortDescription = v;
250 setModified(true);
251 }
252
253
254 }
255
256 /***
257 * Get the FullText
258 *
259 * @return String
260 */
261 public String getFullText()
262 {
263 return fullText;
264 }
265
266
267 /***
268 * Set the value of FullText
269 *
270 * @param v new value
271 */
272 public void setFullText(String v)
273 {
274
275 if (!ObjectUtils.equals(this.fullText, v))
276 {
277 this.fullText = v;
278 setModified(true);
279 }
280
281
282 }
283
284 /***
285 * Get the PostedTime
286 *
287 * @return Date
288 */
289 public Date getPostedTime()
290 {
291 return postedTime;
292 }
293
294
295 /***
296 * Set the value of PostedTime
297 *
298 * @param v new value
299 */
300 public void setPostedTime(Date v)
301 {
302
303 if (!ObjectUtils.equals(this.postedTime, v))
304 {
305 this.postedTime = v;
306 setModified(true);
307 }
308
309
310 }
311
312 /***
313 * Get the AuthorId
314 *
315 * @return String
316 */
317 public String getAuthorId()
318 {
319 return authorId;
320 }
321
322
323 /***
324 * Set the value of AuthorId
325 *
326 * @param v new value
327 */
328 public void setAuthorId(String v)
329 {
330
331 if (!ObjectUtils.equals(this.authorId, v))
332 {
333 this.authorId = v;
334 setModified(true);
335 }
336
337
338 }
339
340 /***
341 * Get the ObjectData
342 *
343 * @return byte[]
344 */
345 public byte[] getObjectData()
346 {
347 return objectData;
348 }
349
350
351 /***
352 * Set the value of ObjectData
353 *
354 * @param v new value
355 */
356 public void setObjectData(byte[] v)
357 {
358
359 if (!ObjectUtils.equals(this.objectData, v))
360 {
361 this.objectData = v;
362 setModified(true);
363 }
364
365
366 }
367
368
369
370
371
372 private StoredBlog aStoredBlog;
373
374 /***
375 * Declares an association between this object and a StoredBlog object
376 *
377 * @param v StoredBlog
378 * @throws TorqueException
379 */
380 public void setStoredBlog(StoredBlog v) throws TorqueException
381 {
382 if (v == null)
383 {
384 setBlogId( 0);
385 }
386 else
387 {
388 setBlogId(v.getBlogId());
389 }
390 aStoredBlog = v;
391 }
392
393
394 /***
395 * Get the associated StoredBlog object
396 *
397 * @return the associated StoredBlog object
398 * @throws TorqueException
399 */
400 public StoredBlog getStoredBlog() throws TorqueException
401 {
402 if (aStoredBlog == null && (this.blogId > 0))
403 {
404 aStoredBlog = StoredBlogPeer.retrieveByPK(SimpleKey.keyFor(this.blogId));
405
406
407
408
409
410
411
412
413
414
415 }
416 return aStoredBlog;
417 }
418
419 /***
420 * Provides convenient way to set a relationship based on a
421 * ObjectKey. e.g.
422 * <code>bar.setFooKey(foo.getPrimaryKey())</code>
423 *
424 */
425 public void setStoredBlogKey(ObjectKey key) throws TorqueException
426 {
427
428 setBlogId(((NumberKey) key).intValue());
429 }
430
431
432
433 /***
434 * Collection to store aggregation of collPostSections
435 */
436 protected List collPostSections;
437
438 /***
439 * Temporary storage of collPostSections to save a possible db hit in
440 * the event objects are add to the collection, but the
441 * complete collection is never requested.
442 */
443 protected void initPostSections()
444 {
445 if (collPostSections == null)
446 {
447 collPostSections = new ArrayList();
448 }
449 }
450
451 /***
452 * Method called to associate a PostSection object to this object
453 * through the PostSection foreign key attribute
454 *
455 * @param l PostSection
456 * @throws TorqueException
457 */
458 public void addPostSection(PostSection l) throws TorqueException
459 {
460 getPostSections().add(l);
461 l.setPost((Post) this);
462 }
463
464 /***
465 * The criteria used to select the current contents of collPostSections
466 */
467 private Criteria lastPostSectionsCriteria = null;
468
469 /***
470 * If this collection has already been initialized, returns
471 * the collection. Otherwise returns the results of
472 * getPostSections(new Criteria())
473 *
474 * @throws TorqueException
475 */
476 public List getPostSections() throws TorqueException
477 {
478 if (collPostSections == null)
479 {
480 collPostSections = getPostSections(new Criteria(10));
481 }
482 return collPostSections;
483 }
484
485 /***
486 * If this collection has already been initialized with
487 * an identical criteria, it returns the collection.
488 * Otherwise if this Post has previously
489 * been saved, it will retrieve related PostSections from storage.
490 * If this Post is new, it will return
491 * an empty collection or the current collection, the criteria
492 * is ignored on a new object.
493 *
494 * @throws TorqueException
495 */
496 public List getPostSections(Criteria criteria) throws TorqueException
497 {
498 if (collPostSections == null)
499 {
500 if (isNew())
501 {
502 collPostSections = new ArrayList();
503 }
504 else
505 {
506 criteria.add(PostSectionPeer.POST_ID, getPostId() );
507 collPostSections = PostSectionPeer.doSelect(criteria);
508 }
509 }
510 else
511 {
512
513 if (!isNew())
514 {
515
516
517
518 criteria.add(PostSectionPeer.POST_ID, getPostId());
519 if (!lastPostSectionsCriteria.equals(criteria))
520 {
521 collPostSections = PostSectionPeer.doSelect(criteria);
522 }
523 }
524 }
525 lastPostSectionsCriteria = criteria;
526
527 return collPostSections;
528 }
529
530 /***
531 * If this collection has already been initialized, returns
532 * the collection. Otherwise returns the results of
533 * getPostSections(new Criteria(),Connection)
534 * This method takes in the Connection also as input so that
535 * referenced objects can also be obtained using a Connection
536 * that is taken as input
537 */
538 public List getPostSections(Connection con) throws TorqueException
539 {
540 if (collPostSections == null)
541 {
542 collPostSections = getPostSections(new Criteria(10), con);
543 }
544 return collPostSections;
545 }
546
547 /***
548 * If this collection has already been initialized with
549 * an identical criteria, it returns the collection.
550 * Otherwise if this Post has previously
551 * been saved, it will retrieve related PostSections from storage.
552 * If this Post is new, it will return
553 * an empty collection or the current collection, the criteria
554 * is ignored on a new object.
555 * This method takes in the Connection also as input so that
556 * referenced objects can also be obtained using a Connection
557 * that is taken as input
558 */
559 public List getPostSections(Criteria criteria, Connection con)
560 throws TorqueException
561 {
562 if (collPostSections == null)
563 {
564 if (isNew())
565 {
566 collPostSections = new ArrayList();
567 }
568 else
569 {
570 criteria.add(PostSectionPeer.POST_ID, getPostId());
571 collPostSections = PostSectionPeer.doSelect(criteria, con);
572 }
573 }
574 else
575 {
576
577 if (!isNew())
578 {
579
580
581
582 criteria.add(PostSectionPeer.POST_ID, getPostId());
583 if (!lastPostSectionsCriteria.equals(criteria))
584 {
585 collPostSections = PostSectionPeer.doSelect(criteria, con);
586 }
587 }
588 }
589 lastPostSectionsCriteria = criteria;
590
591 return collPostSections;
592 }
593
594
595
596
597
598
599
600
601
602
603
604 /***
605 * If this collection has already been initialized with
606 * an identical criteria, it returns the collection.
607 * Otherwise if this Post is new, it will return
608 * an empty collection; or if this Post has previously
609 * been saved, it will retrieve related PostSections from storage.
610 *
611 * This method is protected by default in order to keep the public
612 * api reasonable. You can provide public methods for those you
613 * actually need in Post.
614 */
615 protected List getPostSectionsJoinPost(Criteria criteria)
616 throws TorqueException
617 {
618 if (collPostSections == null)
619 {
620 if (isNew())
621 {
622 collPostSections = new ArrayList();
623 }
624 else
625 {
626 criteria.add(PostSectionPeer.POST_ID, getPostId());
627 collPostSections = PostSectionPeer.doSelectJoinPost(criteria);
628 }
629 }
630 else
631 {
632
633
634
635 boolean newCriteria = true;
636 criteria.add(PostSectionPeer.POST_ID, getPostId());
637 if (!lastPostSectionsCriteria.equals(criteria))
638 {
639 collPostSections = PostSectionPeer.doSelectJoinPost(criteria);
640 }
641 }
642 lastPostSectionsCriteria = criteria;
643
644 return collPostSections;
645 }
646
647
648
649
650
651
652
653
654
655 /***
656 * If this collection has already been initialized with
657 * an identical criteria, it returns the collection.
658 * Otherwise if this Post is new, it will return
659 * an empty collection; or if this Post has previously
660 * been saved, it will retrieve related PostSections from storage.
661 *
662 * This method is protected by default in order to keep the public
663 * api reasonable. You can provide public methods for those you
664 * actually need in Post.
665 */
666 protected List getPostSectionsJoinSection(Criteria criteria)
667 throws TorqueException
668 {
669 if (collPostSections == null)
670 {
671 if (isNew())
672 {
673 collPostSections = new ArrayList();
674 }
675 else
676 {
677 criteria.add(PostSectionPeer.POST_ID, getPostId());
678 collPostSections = PostSectionPeer.doSelectJoinSection(criteria);
679 }
680 }
681 else
682 {
683
684
685
686 boolean newCriteria = true;
687 criteria.add(PostSectionPeer.POST_ID, getPostId());
688 if (!lastPostSectionsCriteria.equals(criteria))
689 {
690 collPostSections = PostSectionPeer.doSelectJoinSection(criteria);
691 }
692 }
693 lastPostSectionsCriteria = criteria;
694
695 return collPostSections;
696 }
697
698
699
700
701
702 /***
703 * Collection to store aggregation of collComments
704 */
705 protected List collComments;
706
707 /***
708 * Temporary storage of collComments to save a possible db hit in
709 * the event objects are add to the collection, but the
710 * complete collection is never requested.
711 */
712 protected void initComments()
713 {
714 if (collComments == null)
715 {
716 collComments = new ArrayList();
717 }
718 }
719
720 /***
721 * Method called to associate a Comment object to this object
722 * through the Comment foreign key attribute
723 *
724 * @param l Comment
725 * @throws TorqueException
726 */
727 public void addComment(Comment l) throws TorqueException
728 {
729 getComments().add(l);
730 l.setPost((Post) this);
731 }
732
733 /***
734 * The criteria used to select the current contents of collComments
735 */
736 private Criteria lastCommentsCriteria = null;
737
738 /***
739 * If this collection has already been initialized, returns
740 * the collection. Otherwise returns the results of
741 * getComments(new Criteria())
742 *
743 * @throws TorqueException
744 */
745 public List getComments() throws TorqueException
746 {
747 if (collComments == null)
748 {
749 collComments = getComments(new Criteria(10));
750 }
751 return collComments;
752 }
753
754 /***
755 * If this collection has already been initialized with
756 * an identical criteria, it returns the collection.
757 * Otherwise if this Post has previously
758 * been saved, it will retrieve related Comments from storage.
759 * If this Post is new, it will return
760 * an empty collection or the current collection, the criteria
761 * is ignored on a new object.
762 *
763 * @throws TorqueException
764 */
765 public List getComments(Criteria criteria) throws TorqueException
766 {
767 if (collComments == null)
768 {
769 if (isNew())
770 {
771 collComments = new ArrayList();
772 }
773 else
774 {
775 criteria.add(CommentPeer.POST_ID, getPostId() );
776 collComments = CommentPeer.doSelect(criteria);
777 }
778 }
779 else
780 {
781
782 if (!isNew())
783 {
784
785
786
787 criteria.add(CommentPeer.POST_ID, getPostId());
788 if (!lastCommentsCriteria.equals(criteria))
789 {
790 collComments = CommentPeer.doSelect(criteria);
791 }
792 }
793 }
794 lastCommentsCriteria = criteria;
795
796 return collComments;
797 }
798
799 /***
800 * If this collection has already been initialized, returns
801 * the collection. Otherwise returns the results of
802 * getComments(new Criteria(),Connection)
803 * This method takes in the Connection also as input so that
804 * referenced objects can also be obtained using a Connection
805 * that is taken as input
806 */
807 public List getComments(Connection con) throws TorqueException
808 {
809 if (collComments == null)
810 {
811 collComments = getComments(new Criteria(10), con);
812 }
813 return collComments;
814 }
815
816 /***
817 * If this collection has already been initialized with
818 * an identical criteria, it returns the collection.
819 * Otherwise if this Post has previously
820 * been saved, it will retrieve related Comments from storage.
821 * If this Post is new, it will return
822 * an empty collection or the current collection, the criteria
823 * is ignored on a new object.
824 * This method takes in the Connection also as input so that
825 * referenced objects can also be obtained using a Connection
826 * that is taken as input
827 */
828 public List getComments(Criteria criteria, Connection con)
829 throws TorqueException
830 {
831 if (collComments == null)
832 {
833 if (isNew())
834 {
835 collComments = new ArrayList();
836 }
837 else
838 {
839 criteria.add(CommentPeer.POST_ID, getPostId());
840 collComments = CommentPeer.doSelect(criteria, con);
841 }
842 }
843 else
844 {
845
846 if (!isNew())
847 {
848
849
850
851 criteria.add(CommentPeer.POST_ID, getPostId());
852 if (!lastCommentsCriteria.equals(criteria))
853 {
854 collComments = CommentPeer.doSelect(criteria, con);
855 }
856 }
857 }
858 lastCommentsCriteria = criteria;
859
860 return collComments;
861 }
862
863
864
865
866
867
868
869
870
871
872
873 /***
874 * If this collection has already been initialized with
875 * an identical criteria, it returns the collection.
876 * Otherwise if this Post is new, it will return
877 * an empty collection; or if this Post has previously
878 * been saved, it will retrieve related Comments from storage.
879 *
880 * This method is protected by default in order to keep the public
881 * api reasonable. You can provide public methods for those you
882 * actually need in Post.
883 */
884 protected List getCommentsJoinPost(Criteria criteria)
885 throws TorqueException
886 {
887 if (collComments == null)
888 {
889 if (isNew())
890 {
891 collComments = new ArrayList();
892 }
893 else
894 {
895 criteria.add(CommentPeer.POST_ID, getPostId());
896 collComments = CommentPeer.doSelectJoinPost(criteria);
897 }
898 }
899 else
900 {
901
902
903
904 boolean newCriteria = true;
905 criteria.add(CommentPeer.POST_ID, getPostId());
906 if (!lastCommentsCriteria.equals(criteria))
907 {
908 collComments = CommentPeer.doSelectJoinPost(criteria);
909 }
910 }
911 lastCommentsCriteria = criteria;
912
913 return collComments;
914 }
915
916
917
918
919 private static List fieldNames = null;
920
921 /***
922 * Generate a list of field names.
923 *
924 * @return a list of field names
925 */
926 public static synchronized List getFieldNames()
927 {
928 if (fieldNames == null)
929 {
930 fieldNames = new ArrayList();
931 fieldNames.add("PostId");
932 fieldNames.add("BlogId");
933 fieldNames.add("PostType");
934 fieldNames.add("Title");
935 fieldNames.add("UriFragment");
936 fieldNames.add("ShortDescription");
937 fieldNames.add("FullText");
938 fieldNames.add("PostedTime");
939 fieldNames.add("AuthorId");
940 fieldNames.add("ObjectData");
941 fieldNames = Collections.unmodifiableList(fieldNames);
942 }
943 return fieldNames;
944 }
945
946 /***
947 * Retrieves a field from the object by name passed in as a String.
948 *
949 * @param name field name
950 * @return value
951 */
952 public Object getByName(String name)
953 {
954 if (name.equals("PostId"))
955 {
956 return new Integer(getPostId());
957 }
958 if (name.equals("BlogId"))
959 {
960 return new Integer(getBlogId());
961 }
962 if (name.equals("PostType"))
963 {
964 return new Integer(getPostType());
965 }
966 if (name.equals("Title"))
967 {
968 return getTitle();
969 }
970 if (name.equals("UriFragment"))
971 {
972 return getUriFragment();
973 }
974 if (name.equals("ShortDescription"))
975 {
976 return getShortDescription();
977 }
978 if (name.equals("FullText"))
979 {
980 return getFullText();
981 }
982 if (name.equals("PostedTime"))
983 {
984 return getPostedTime();
985 }
986 if (name.equals("AuthorId"))
987 {
988 return getAuthorId();
989 }
990 if (name.equals("ObjectData"))
991 {
992 return getObjectData();
993 }
994 return null;
995 }
996
997 /***
998 * Retrieves a field from the object by name passed in
999 * as a String. The String must be one of the static
1000 * Strings defined in this Class' Peer.
1001 *
1002 * @param name peer name
1003 * @return value
1004 */
1005 public Object getByPeerName(String name)
1006 {
1007 if (name.equals(PostPeer.POST_ID))
1008 {
1009 return new Integer(getPostId());
1010 }
1011 if (name.equals(PostPeer.BLOG_ID))
1012 {
1013 return new Integer(getBlogId());
1014 }
1015 if (name.equals(PostPeer.POST_TYPE))
1016 {
1017 return new Integer(getPostType());
1018 }
1019 if (name.equals(PostPeer.TITLE))
1020 {
1021 return getTitle();
1022 }
1023 if (name.equals(PostPeer.URI_FRAGMENT))
1024 {
1025 return getUriFragment();
1026 }
1027 if (name.equals(PostPeer.SHORT_DESCRIPTION))
1028 {
1029 return getShortDescription();
1030 }
1031 if (name.equals(PostPeer.FULL_TEXT))
1032 {
1033 return getFullText();
1034 }
1035 if (name.equals(PostPeer.POSTED_TIME))
1036 {
1037 return getPostedTime();
1038 }
1039 if (name.equals(PostPeer.AUTHOR_ID))
1040 {
1041 return getAuthorId();
1042 }
1043 if (name.equals(PostPeer.OBJECT_DATA))
1044 {
1045 return getObjectData();
1046 }
1047 return null;
1048 }
1049
1050 /***
1051 * Retrieves a field from the object by Position as specified
1052 * in the xml schema. Zero-based.
1053 *
1054 * @param pos position in xml schema
1055 * @return value
1056 */
1057 public Object getByPosition(int pos)
1058 {
1059 if (pos == 0)
1060 {
1061 return new Integer(getPostId());
1062 }
1063 if (pos == 1)
1064 {
1065 return new Integer(getBlogId());
1066 }
1067 if (pos == 2)
1068 {
1069 return new Integer(getPostType());
1070 }
1071 if (pos == 3)
1072 {
1073 return getTitle();
1074 }
1075 if (pos == 4)
1076 {
1077 return getUriFragment();
1078 }
1079 if (pos == 5)
1080 {
1081 return getShortDescription();
1082 }
1083 if (pos == 6)
1084 {
1085 return getFullText();
1086 }
1087 if (pos == 7)
1088 {
1089 return getPostedTime();
1090 }
1091 if (pos == 8)
1092 {
1093 return getAuthorId();
1094 }
1095 if (pos == 9)
1096 {
1097 return getObjectData();
1098 }
1099 return null;
1100 }
1101
1102 /***
1103 * Stores the object in the database. If the object is new,
1104 * it inserts it; otherwise an update is performed.
1105 *
1106 * @throws Exception
1107 */
1108 public void save() throws Exception
1109 {
1110 save(PostPeer.getMapBuilder()
1111 .getDatabaseMap().getName());
1112 }
1113
1114 /***
1115 * Stores the object in the database. If the object is new,
1116 * it inserts it; otherwise an update is performed.
1117 * Note: this code is here because the method body is
1118 * auto-generated conditionally and therefore needs to be
1119 * in this file instead of in the super class, BaseObject.
1120 *
1121 * @param dbName
1122 * @throws TorqueException
1123 */
1124 public void save(String dbName) throws TorqueException
1125 {
1126 Connection con = null;
1127 try
1128 {
1129 con = Transaction.begin(dbName);
1130 save(con);
1131 Transaction.commit(con);
1132 }
1133 catch(TorqueException e)
1134 {
1135 Transaction.safeRollback(con);
1136 throw e;
1137 }
1138 }
1139
1140 /*** flag to prevent endless save loop, if this object is referenced
1141 by another object which falls in this transaction. */
1142 private boolean alreadyInSave = false;
1143 /***
1144 * Stores the object in the database. If the object is new,
1145 * it inserts it; otherwise an update is performed. This method
1146 * is meant to be used as part of a transaction, otherwise use
1147 * the save() method and the connection details will be handled
1148 * internally
1149 *
1150 * @param con
1151 * @throws TorqueException
1152 */
1153 public void save(Connection con) throws TorqueException
1154 {
1155 if (!alreadyInSave)
1156 {
1157 alreadyInSave = true;
1158
1159
1160
1161
1162 if (isModified())
1163 {
1164 if (isNew())
1165 {
1166 PostPeer.doInsert((Post) this, con);
1167 setNew(false);
1168 }
1169 else
1170 {
1171 PostPeer.doUpdate((Post) this, con);
1172 }
1173 }
1174
1175
1176
1177 if (collPostSections != null)
1178 {
1179 for (int i = 0; i < collPostSections.size(); i++)
1180 {
1181 ((PostSection) collPostSections.get(i)).save(con);
1182 }
1183 }
1184
1185
1186 if (collComments != null)
1187 {
1188 for (int i = 0; i < collComments.size(); i++)
1189 {
1190 ((Comment) collComments.get(i)).save(con);
1191 }
1192 }
1193 alreadyInSave = false;
1194 }
1195 }
1196
1197
1198 /***
1199 * Set the PrimaryKey using ObjectKey.
1200 *
1201 * @param postId ObjectKey
1202 */
1203 public void setPrimaryKey(ObjectKey key)
1204 throws TorqueException
1205 {
1206 setPostId(((NumberKey) key).intValue());
1207 }
1208
1209 /***
1210 * Set the PrimaryKey using a String.
1211 *
1212 * @param key
1213 */
1214 public void setPrimaryKey(String key) throws TorqueException
1215 {
1216 setPostId(Integer.parseInt(key));
1217 }
1218
1219
1220 /***
1221 * returns an id that differentiates this object from others
1222 * of its class.
1223 */
1224 public ObjectKey getPrimaryKey()
1225 {
1226 return SimpleKey.keyFor(getPostId());
1227 }
1228
1229 /***
1230 * get an id that differentiates this object from others
1231 * of its class.
1232 */
1233 public String getQueryKey()
1234 {
1235 if (getPrimaryKey() == null)
1236 {
1237 return "";
1238 }
1239 else
1240 {
1241 return getPrimaryKey().toString();
1242 }
1243 }
1244
1245 /***
1246 * set an id that differentiates this object from others
1247 * of its class.
1248 */
1249 public void setQueryKey(String key)
1250 throws TorqueException
1251 {
1252 setPrimaryKey(key);
1253 }
1254
1255 /***
1256 * Makes a copy of this object.
1257 * It creates a new object filling in the simple attributes.
1258 * It then fills all the association collections and sets the
1259 * related objects to isNew=true.
1260 */
1261 public Post copy() throws TorqueException
1262 {
1263 return copyInto(new Post());
1264 }
1265
1266 protected Post copyInto(Post copyObj) throws TorqueException
1267 {
1268 copyObj.setPostId(postId);
1269 copyObj.setBlogId(blogId);
1270 copyObj.setPostType(postType);
1271 copyObj.setTitle(title);
1272 copyObj.setUriFragment(uriFragment);
1273 copyObj.setShortDescription(shortDescription);
1274 copyObj.setFullText(fullText);
1275 copyObj.setPostedTime(postedTime);
1276 copyObj.setAuthorId(authorId);
1277 copyObj.setObjectData(objectData);
1278
1279 copyObj.setPostId( 0);
1280
1281
1282
1283 List v = getPostSections();
1284 for (int i = 0; i < v.size(); i++)
1285 {
1286 PostSection obj = (PostSection) v.get(i);
1287 copyObj.addPostSection(obj.copy());
1288 }
1289
1290
1291 v = getComments();
1292 for (int i = 0; i < v.size(); i++)
1293 {
1294 Comment obj = (Comment) v.get(i);
1295 copyObj.addComment(obj.copy());
1296 }
1297 return copyObj;
1298 }
1299
1300 /***
1301 * returns a peer instance associated with this om. Since Peer classes
1302 * are not to have any instance attributes, this method returns the
1303 * same instance for all member of this class. The method could therefore
1304 * be static, but this would prevent one from overriding the behavior.
1305 */
1306 public PostPeer getPeer()
1307 {
1308 return peer;
1309 }
1310
1311 public String toString()
1312 {
1313 StringBuffer str = new StringBuffer();
1314 str.append("Post:\n");
1315 str.append("PostId = ")
1316 .append(getPostId())
1317 .append("\n");
1318 str.append("BlogId = ")
1319 .append(getBlogId())
1320 .append("\n");
1321 str.append("PostType = ")
1322 .append(getPostType())
1323 .append("\n");
1324 str.append("Title = ")
1325 .append(getTitle())
1326 .append("\n");
1327 str.append("UriFragment = ")
1328 .append(getUriFragment())
1329 .append("\n");
1330 str.append("ShortDescription = ")
1331 .append(getShortDescription())
1332 .append("\n");
1333 str.append("FullText = ")
1334 .append(getFullText())
1335 .append("\n");
1336 str.append("PostedTime = ")
1337 .append(getPostedTime())
1338 .append("\n");
1339 str.append("AuthorId = ")
1340 .append(getAuthorId())
1341 .append("\n");
1342 str.append("ObjectData = ")
1343 .append(getObjectData())
1344 .append("\n");
1345 return(str.toString());
1346 }
1347 }