This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threaded Newsgroup

 
Sylvia H Charbonneau
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello !

I'm tasked to build a newsgroup. I will need to display messages saved in a database that are linked. For example,

Message A
\- Question A1
\- Answer A1-1
\- Answer A1-2
\- Question A2
\- Answer A2-1

Message B
Message C
\- Question C1

etc.....

All questions and answers must be displayed together when we do a message list. There must be a design pattern for something like this....I've seen newsgroups doing what I want to do, but I haven't manage to locate a design pattern.

If anyone has an answer, or a suggestion or a direction to search - I'd really appreciate it.

Thank you all kindly !

Sylvia
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between a message, a question and an answer - technically, I mean?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you actually mean a "newsgroup", i.e a cluster of messages synchronized and passed from one machine to another, typically using the NNTP protocol? Or do you mean what is more commonly known as a "forum", "bulletin board" or "BB". i.e the Big Moose Saloon here at JavaRanch?
 
Sylvia H Charbonneau
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, technically, they save different data in the database. Questions, and answers have less data.

However, there is sufficient in common that I'm leaning towards keeping the messages, questions and answers in the same table. Perhaps simplifying my queries.

Sylvia
 
Sylvia H Charbonneau
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Frank Carver:
Do you actually mean a "newsgroup", i.e a cluster of messages synchronized and passed from one machine to another, typically using the NNTP protocol? Or do you mean what is more commonly known as a "forum", "bulletin board" or "BB". i.e the Big Moose Saloon here at JavaRanch?


Nope, not the "newsgroup" type of thing. By newsgroup I meant only how message threads are displayed, the linking between them and the order that in which they are presented.

Sylvia
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quacks like a tree to me. In a database each posting might have a reference to a single parent posting. In Java objects, a parent might have a collection of children. Does that seem to fit?
 
Sylvia H Charbonneau
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
Quacks like a tree to me. In a database each posting might have a reference to a single parent posting. In Java objects, a parent might have a collection of children. Does that seem to fit?


Something like. It is the details that are throwing me off though. I'm ok to link Question A1 and Question A2 to Message A, but how do I link Answer A1-1 to both Message A and and Question A1, and have them displayed together

Message A
...\- Question A1
........\- Answer A1-1
........\- Answer A1-2
...\- Question A2
........\- Answer A2-1

Maybe your response answers it, but I'm pretty new so I'm not seeing it ?

Sylvia
 
Sylvia H Charbonneau
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like what is at the bottom of this page

Slashdot | Java Regular Expressions
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sylvia H Charbonneau:

I'm ok to link Question A1 and Question A2 to Message A, but how do I link Answer A1-1 to both Message A and and Question A1, and have them displayed together


Well, if Answer A1-1 is linked to Question A1, and Question A1 is linked to Message A, Answer A1-1 already is linked to Message A implicitly, isn't it?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like trees and recursion might be new to you? Just in case, here are some basics. Trees are often made up of objects called Nodes. You can call them anything, but other folks will recognize what Node means. A node structure might have the posting and a collection of child nodes. The Posting object might have have posting title, date, author, full text, etc.

The anchor or root for the tree would have child nodes for the postings "Message-A" and "Message-B" and so on. The node for "Message-A" would have children "Question-A1" and "Question-A2". The node for "Question A1" would have children "Answer A1-1" and so on. Does that much make sense?

A recursive method - one that calls itself - will display them nicely. It will look something like:


Ilja's a master at this so I'll put him on the spot: Suggest a first test or the first thing to build. If we get helping you with code you'll find we hint at the next three or four lines rather than giving full answers. Trust me, it's more fun that way.

Did that answer the right questions?
 
Sylvia H Charbonneau
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you ! Thank you ! Thank you !
I've been away for the last week or so, but I'll get right on this.

Sylvia
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, keep us posted on how it goes!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic