Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

data structures and databases

 
vicky kieu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

thanks!
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about a HashMap?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

HTH

Layne
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic