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.BaseObject;
13 import org.apache.torque.om.NumberKey;
14 import org.apache.torque.om.ObjectKey;
15 import org.apache.torque.om.SimpleKey;
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 Comment
23 */
24 public abstract class BaseComment extends BaseObject
25 implements org.apache.turbine.om.Retrievable
26 {
27 /*** The Peer class */
28 private static final CommentPeer peer =
29 new CommentPeer();
30
31
32 /*** The value for the commentId field */
33 private int commentId;
34
35 /*** The value for the postId field */
36 private int postId;
37
38 /*** The value for the postedTime field */
39 private Date postedTime;
40
41 /*** The value for the name field */
42 private String name;
43
44 /*** The value for the url field */
45 private String url;
46
47 /*** The value for the email field */
48 private String email;
49
50 /*** The value for the title field */
51 private String title;
52
53 /*** The value for the text field */
54 private String text;
55
56
57 /***
58 * Get the CommentId
59 *
60 * @return int
61 */
62 public int getCommentId()
63 {
64 return commentId;
65 }
66
67
68 /***
69 * Set the value of CommentId
70 *
71 * @param v new value
72 */
73 public void setCommentId(int v)
74 {
75
76 if (this.commentId != v)
77 {
78 this.commentId = v;
79 setModified(true);
80 }
81
82
83 }
84
85 /***
86 * Get the PostId
87 *
88 * @return int
89 */
90 public int getPostId()
91 {
92 return postId;
93 }
94
95
96 /***
97 * Set the value of PostId
98 *
99 * @param v new value
100 */
101 public void setPostId(int v) throws TorqueException
102 {
103
104 if (this.postId != v)
105 {
106 this.postId = v;
107 setModified(true);
108 }
109
110
111 if (aPost != null && !(aPost.getPostId() == v))
112 {
113 aPost = null;
114 }
115
116 }
117
118 /***
119 * Get the PostedTime
120 *
121 * @return Date
122 */
123 public Date getPostedTime()
124 {
125 return postedTime;
126 }
127
128
129 /***
130 * Set the value of PostedTime
131 *
132 * @param v new value
133 */
134 public void setPostedTime(Date v)
135 {
136
137 if (!ObjectUtils.equals(this.postedTime, v))
138 {
139 this.postedTime = v;
140 setModified(true);
141 }
142
143
144 }
145
146 /***
147 * Get the Name
148 *
149 * @return String
150 */
151 public String getName()
152 {
153 return name;
154 }
155
156
157 /***
158 * Set the value of Name
159 *
160 * @param v new value
161 */
162 public void setName(String v)
163 {
164
165 if (!ObjectUtils.equals(this.name, v))
166 {
167 this.name = v;
168 setModified(true);
169 }
170
171
172 }
173
174 /***
175 * Get the Url
176 *
177 * @return String
178 */
179 public String getUrl()
180 {
181 return url;
182 }
183
184
185 /***
186 * Set the value of Url
187 *
188 * @param v new value
189 */
190 public void setUrl(String v)
191 {
192
193 if (!ObjectUtils.equals(this.url, v))
194 {
195 this.url = v;
196 setModified(true);
197 }
198
199
200 }
201
202 /***
203 * Get the Email
204 *
205 * @return String
206 */
207 public String getEmail()
208 {
209 return email;
210 }
211
212
213 /***
214 * Set the value of Email
215 *
216 * @param v new value
217 */
218 public void setEmail(String v)
219 {
220
221 if (!ObjectUtils.equals(this.email, v))
222 {
223 this.email = v;
224 setModified(true);
225 }
226
227
228 }
229
230 /***
231 * Get the Title
232 *
233 * @return String
234 */
235 public String getTitle()
236 {
237 return title;
238 }
239
240
241 /***
242 * Set the value of Title
243 *
244 * @param v new value
245 */
246 public void setTitle(String v)
247 {
248
249 if (!ObjectUtils.equals(this.title, v))
250 {
251 this.title = v;
252 setModified(true);
253 }
254
255
256 }
257
258 /***
259 * Get the Text
260 *
261 * @return String
262 */
263 public String getText()
264 {
265 return text;
266 }
267
268
269 /***
270 * Set the value of Text
271 *
272 * @param v new value
273 */
274 public void setText(String v)
275 {
276
277 if (!ObjectUtils.equals(this.text, v))
278 {
279 this.text = v;
280 setModified(true);
281 }
282
283
284 }
285
286
287
288
289
290 private Post aPost;
291
292 /***
293 * Declares an association between this object and a Post object
294 *
295 * @param v Post
296 * @throws TorqueException
297 */
298 public void setPost(Post v) throws TorqueException
299 {
300 if (v == null)
301 {
302 setPostId( 0);
303 }
304 else
305 {
306 setPostId(v.getPostId());
307 }
308 aPost = v;
309 }
310
311
312 /***
313 * Get the associated Post object
314 *
315 * @return the associated Post object
316 * @throws TorqueException
317 */
318 public Post getPost() throws TorqueException
319 {
320 if (aPost == null && (this.postId > 0))
321 {
322 aPost = PostPeer.retrieveByPK(SimpleKey.keyFor(this.postId));
323
324
325
326
327
328
329
330
331
332
333 }
334 return aPost;
335 }
336
337 /***
338 * Provides convenient way to set a relationship based on a
339 * ObjectKey. e.g.
340 * <code>bar.setFooKey(foo.getPrimaryKey())</code>
341 *
342 */
343 public void setPostKey(ObjectKey key) throws TorqueException
344 {
345
346 setPostId(((NumberKey) key).intValue());
347 }
348
349
350 private static List fieldNames = null;
351
352 /***
353 * Generate a list of field names.
354 *
355 * @return a list of field names
356 */
357 public static synchronized List getFieldNames()
358 {
359 if (fieldNames == null)
360 {
361 fieldNames = new ArrayList();
362 fieldNames.add("CommentId");
363 fieldNames.add("PostId");
364 fieldNames.add("PostedTime");
365 fieldNames.add("Name");
366 fieldNames.add("Url");
367 fieldNames.add("Email");
368 fieldNames.add("Title");
369 fieldNames.add("Text");
370 fieldNames = Collections.unmodifiableList(fieldNames);
371 }
372 return fieldNames;
373 }
374
375 /***
376 * Retrieves a field from the object by name passed in as a String.
377 *
378 * @param name field name
379 * @return value
380 */
381 public Object getByName(String name)
382 {
383 if (name.equals("CommentId"))
384 {
385 return new Integer(getCommentId());
386 }
387 if (name.equals("PostId"))
388 {
389 return new Integer(getPostId());
390 }
391 if (name.equals("PostedTime"))
392 {
393 return getPostedTime();
394 }
395 if (name.equals("Name"))
396 {
397 return getName();
398 }
399 if (name.equals("Url"))
400 {
401 return getUrl();
402 }
403 if (name.equals("Email"))
404 {
405 return getEmail();
406 }
407 if (name.equals("Title"))
408 {
409 return getTitle();
410 }
411 if (name.equals("Text"))
412 {
413 return getText();
414 }
415 return null;
416 }
417
418 /***
419 * Retrieves a field from the object by name passed in
420 * as a String. The String must be one of the static
421 * Strings defined in this Class' Peer.
422 *
423 * @param name peer name
424 * @return value
425 */
426 public Object getByPeerName(String name)
427 {
428 if (name.equals(CommentPeer.COMMENT_ID))
429 {
430 return new Integer(getCommentId());
431 }
432 if (name.equals(CommentPeer.POST_ID))
433 {
434 return new Integer(getPostId());
435 }
436 if (name.equals(CommentPeer.POSTED_TIME))
437 {
438 return getPostedTime();
439 }
440 if (name.equals(CommentPeer.NAME))
441 {
442 return getName();
443 }
444 if (name.equals(CommentPeer.URL))
445 {
446 return getUrl();
447 }
448 if (name.equals(CommentPeer.EMAIL))
449 {
450 return getEmail();
451 }
452 if (name.equals(CommentPeer.TITLE))
453 {
454 return getTitle();
455 }
456 if (name.equals(CommentPeer.TEXT))
457 {
458 return getText();
459 }
460 return null;
461 }
462
463 /***
464 * Retrieves a field from the object by Position as specified
465 * in the xml schema. Zero-based.
466 *
467 * @param pos position in xml schema
468 * @return value
469 */
470 public Object getByPosition(int pos)
471 {
472 if (pos == 0)
473 {
474 return new Integer(getCommentId());
475 }
476 if (pos == 1)
477 {
478 return new Integer(getPostId());
479 }
480 if (pos == 2)
481 {
482 return getPostedTime();
483 }
484 if (pos == 3)
485 {
486 return getName();
487 }
488 if (pos == 4)
489 {
490 return getUrl();
491 }
492 if (pos == 5)
493 {
494 return getEmail();
495 }
496 if (pos == 6)
497 {
498 return getTitle();
499 }
500 if (pos == 7)
501 {
502 return getText();
503 }
504 return null;
505 }
506
507 /***
508 * Stores the object in the database. If the object is new,
509 * it inserts it; otherwise an update is performed.
510 *
511 * @throws Exception
512 */
513 public void save() throws Exception
514 {
515 save(CommentPeer.getMapBuilder()
516 .getDatabaseMap().getName());
517 }
518
519 /***
520 * Stores the object in the database. If the object is new,
521 * it inserts it; otherwise an update is performed.
522 * Note: this code is here because the method body is
523 * auto-generated conditionally and therefore needs to be
524 * in this file instead of in the super class, BaseObject.
525 *
526 * @param dbName
527 * @throws TorqueException
528 */
529 public void save(String dbName) throws TorqueException
530 {
531 Connection con = null;
532 try
533 {
534 con = Transaction.begin(dbName);
535 save(con);
536 Transaction.commit(con);
537 }
538 catch(TorqueException e)
539 {
540 Transaction.safeRollback(con);
541 throw e;
542 }
543 }
544
545 /*** flag to prevent endless save loop, if this object is referenced
546 by another object which falls in this transaction. */
547 private boolean alreadyInSave = false;
548 /***
549 * Stores the object in the database. If the object is new,
550 * it inserts it; otherwise an update is performed. This method
551 * is meant to be used as part of a transaction, otherwise use
552 * the save() method and the connection details will be handled
553 * internally
554 *
555 * @param con
556 * @throws TorqueException
557 */
558 public void save(Connection con) throws TorqueException
559 {
560 if (!alreadyInSave)
561 {
562 alreadyInSave = true;
563
564
565
566
567 if (isModified())
568 {
569 if (isNew())
570 {
571 CommentPeer.doInsert((Comment) this, con);
572 setNew(false);
573 }
574 else
575 {
576 CommentPeer.doUpdate((Comment) this, con);
577 }
578 }
579
580 alreadyInSave = false;
581 }
582 }
583
584
585 /***
586 * Set the PrimaryKey using ObjectKey.
587 *
588 * @param commentId ObjectKey
589 */
590 public void setPrimaryKey(ObjectKey key)
591
592 {
593 setCommentId(((NumberKey) key).intValue());
594 }
595
596 /***
597 * Set the PrimaryKey using a String.
598 *
599 * @param key
600 */
601 public void setPrimaryKey(String key)
602 {
603 setCommentId(Integer.parseInt(key));
604 }
605
606
607 /***
608 * returns an id that differentiates this object from others
609 * of its class.
610 */
611 public ObjectKey getPrimaryKey()
612 {
613 return SimpleKey.keyFor(getCommentId());
614 }
615
616 /***
617 * get an id that differentiates this object from others
618 * of its class.
619 */
620 public String getQueryKey()
621 {
622 if (getPrimaryKey() == null)
623 {
624 return "";
625 }
626 else
627 {
628 return getPrimaryKey().toString();
629 }
630 }
631
632 /***
633 * set an id that differentiates this object from others
634 * of its class.
635 */
636 public void setQueryKey(String key)
637 throws TorqueException
638 {
639 setPrimaryKey(key);
640 }
641
642 /***
643 * Makes a copy of this object.
644 * It creates a new object filling in the simple attributes.
645 * It then fills all the association collections and sets the
646 * related objects to isNew=true.
647 */
648 public Comment copy() throws TorqueException
649 {
650 return copyInto(new Comment());
651 }
652
653 protected Comment copyInto(Comment copyObj) throws TorqueException
654 {
655 copyObj.setCommentId(commentId);
656 copyObj.setPostId(postId);
657 copyObj.setPostedTime(postedTime);
658 copyObj.setName(name);
659 copyObj.setUrl(url);
660 copyObj.setEmail(email);
661 copyObj.setTitle(title);
662 copyObj.setText(text);
663
664 copyObj.setCommentId( 0);
665
666 return copyObj;
667 }
668
669 /***
670 * returns a peer instance associated with this om. Since Peer classes
671 * are not to have any instance attributes, this method returns the
672 * same instance for all member of this class. The method could therefore
673 * be static, but this would prevent one from overriding the behavior.
674 */
675 public CommentPeer getPeer()
676 {
677 return peer;
678 }
679
680 public String toString()
681 {
682 StringBuffer str = new StringBuffer();
683 str.append("Comment:\n");
684 str.append("CommentId = ")
685 .append(getCommentId())
686 .append("\n");
687 str.append("PostId = ")
688 .append(getPostId())
689 .append("\n");
690 str.append("PostedTime = ")
691 .append(getPostedTime())
692 .append("\n");
693 str.append("Name = ")
694 .append(getName())
695 .append("\n");
696 str.append("Url = ")
697 .append(getUrl())
698 .append("\n");
699 str.append("Email = ")
700 .append(getEmail())
701 .append("\n");
702 str.append("Title = ")
703 .append(getTitle())
704 .append("\n");
705 str.append("Text = ")
706 .append(getText())
707 .append("\n");
708 return(str.toString());
709 }
710 }