Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A Design Question

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I am in a process of writing a java program which queries a database. I am retreiving all kinds of information and then I have to display it as a report. My concern is that that I have to make a HashMap inside a HashMap. What I mean is
HashMap1
-------------
Keys | Values
--------------
Unique| HashMap2
Unique| HashMap3
.
.
.
.
The HashMap2 also have there unique keys and values.
Is there a better solution than the soln I presented??
Thanks in advance for your help!
-Amish
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you need to be able to access the key Set or value Collection for the maps, this is equivalent to a single Map keyed by the composite of the two keys in your example (i.e. the composite of Hashmap1Key and Hashmap2Key, etc). One way to create composite keys isAlternatively, if your keys are Strings you might come up with a unique way to concatenate them, etc.
- Peter
 
Zakaria Haque
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It pretty much depends on how much time you can put on this project and what the future needs are.
You can use javabeans to represent a record in your database. It can give you type safety. It will take less memory than using a hashtable for each record, it can be crucial if you are retrieving a lot of data.
Rather than having a hastable represent the results from a table, you can use a broker. The immidiate benefit is, you can use lazy data retrieval, which can be important for large amount of data.
Another good thing about using this type of design is, you are open to use other features in future, like client side caching and bluh bluh bluh. But of course, this is not as important if no one will ever need to enhance this program ever.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic