Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A design decision question (UrlYBird)

 
Alexandre Baldo
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys! I have a doubt about a design decision...

I am using a Map<Long, Long> to store the recNo and locantion of each record.
This Map is built once when the application is loaded and then it is updated every time a client creates or deletes a record.

I'm using this map to store both the valid records and deleted records, but a deleted record have it's location multiplied by -1. This means that a positive location holds a valid record and a negative location holds a deleted record.

So, when a client creates a new record I use this map to find a reusable location (trying to find a negative location), then the location is updated (turn it positive):
.
And when a client deletes a record the location is update again (turn it negative).

The question is... is this a good design choice ? Or is it a 'gambiarra'* ?

I tried to use two maps: onde for valid record and another to deleted records but it turn to be difficult to synchronized them... so I gave up this design.

Any suggestions?

Thank you all!

* Gambiarra: Here in Brazil we use this word when we need to do/fix something that can't be done in a good way. It's generaly not a good work...
 
Jevgeni Zhukov
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest not to use any cache at all. Imagine the data file is so big that your application ran out of memory while creating a Map.
I didn't use cache nor value objects in my assignment and got max points for database layer. Just try to keep your solution as simple as possible.
 
Alexandre Baldo
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Jevgeni!
I'll think about that!
 
Roman Yankin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jevgeni But you still had to keep all data in TableModel, correct?
 
Ananth Chellathurai
Ranch Hand
Posts: 349
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Yankin,

He can always make a connection to the database at the time of delete or update. Do not need to store the whole data in memory.

Ananth Chellathurai
 
Roman Yankin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chellathurai, didn't think about this. But how would you go about displaying data in a JTable when user is scrolling through records?
 
David Winters Junior
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have doen this design of having two caches one for the deleted records and one for the actual records in a database file. Accessing the database directly is not a good idea in my opinion, having a cache improves performance although i can see the alternate argument also that if the cache grows this will take up memory but memory should not be an issue on the hosted server these days.

Just my opinion anyways
 
Roman Yankin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have doen this design of having two caches one for the deleted records and one for the actual records in a database file.
Did the same thing. Especially useful when you are reusing deleted records in your data file, because as soon as you need to create new record you can really easily pickup one form deleted records cache without sniffing through the data file
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic