• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which case is better? What is best way to solve?

 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a table in Oracle database, this is NE_DB_ENUM_VALUE table, in this table i have 4 column:
1- ENUMNAME: varchar
2- STRINGVALUE: varchar
3- INTEGERVALUE: int
4- ENUMTYPE: varchar
I wanna get String value and Integer value from this table. So i have 2 solution:
Solution 1
I select both value Integer value and String value one time then store it in HashMap, when i need to get String value or Integer value i will get from HashMap. I use Singeton pattern.



Solution 2.
I select directly.


I need get Integer value and String value many time so can you recommend me which solution is better.
Thanks you so much.
Best regards
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you are asking whether you should cache the tables in Java. Like many good computer questions, "it depends." Some critieria:
- how big is the table?
- what percentage of the table do you typically read?
- how often do you read the same records from the table?
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:It sounds like you are asking whether you should cache the tables in Java. Like many good computer questions, "it depends." Some critieria:
- how big is the table?
- what percentage of the table do you typically read?
- how often do you read the same records from the table?


Thanks you for reply, below is my answer
- The table some time have 1000 records.
- I dont need read this table too many times
- when client sent to server request with some conditions, server need to query from Databse and get String value or Integer value to reply to client. I think if i use solution 1, i query only one time and when i need get value, i will get it from HashMap but if i use solution 2 so when i need to get value (Integer or String) i have to query every times.
But i dont like to use the solution one because it's use singleton pattern.
thanks you
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tran,
I wouldn't cache 1000 records that aren't read often. If you want to cache something, it should be the most frequently read rows.

A singleton isn't an inherent problem if it is a read only copy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic