Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

A Design Question

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic