This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
i have a database and i need to store all the data into a data structure. but which one? my database contains authors, coauthors, and book titles. my data structure should make it possible for me retrieve all authors and coauthors who have worked on the same books together.
can anyone help me out? recommend a data structure for me to use?
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
I don't think a single data structure will fit your needs here. I agree with Marilyn that a Map will be helpful. You will probably also need to use a List to keep track of all the authors for a particular book. I would create two classes: Author and Book. Then you can use a Map with a Book object as the key and a List of Author objects as the value.
If you are unfamiliar with the data structures that are provided by the Collections API, I suggest you check out this tutorial. It will help you get started using them. You will also want to use the Java API docs for the version of Java you are using. These are a great reference when you need to look up a specific class or method.
You can make object models that mimic your database model. One bit that goes backwards is one-to-many. In the database the many all have pkey pointers to the one. In the object model the one probably has a collection of references to the many.
Your database might have a many-to-many with a joining relationship table in between. Your object model can duplicate that if you need to put some attributes on the relationship, or just give each side a collection of references to the other.
Google for "object relational mapping" for much more. HERE is an article by Scott Ambler. He's written tons on the subject.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi