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

DB Records finder ?

 
steve mcdonald
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,
i am implementing the find method that searches for a matched record column value. Looks like i may have to seek all the records from record 1 thru end, every time a user tries to search.
There is no caching requirement mentioned, but this is very inefficient, do i address this somehow or just go with it.

Any ideas ?

-- steve
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search all records whether you implement caching or not, really has little to do with it. All that changes is where to search, you'll still check every record.
Maybe you're thinking of indices/indexes? Where every searchable table is cached. Since performance isn't an issue I'd not risk losing marks for a section I stand to gain nothing in. It's your call though, you can ace that section regardless of your decision.
 
Lara McCarver
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most people who post on the forums don't say anything about using caching. Using caching... it's sounds nice, because of the efficiency, and I started designing it into my program, but then I realized that keeping the cache up to date and safeguarding it against corruption is not a trivial task. Overall, I would say that if the requirements mentioned efficiency, that would be a stronger case for adding caching, but they don't.

One thing you could do is to design your code with enough indirection so that you could easily add caching in the future. For example, instead of having the Data class read/update the records in your "database" directly, have them call an intermediate class. This class could then, at some time in the future, hand off the read() functionality to a CachedDB class, post notification about writes that the CachedDB class would you, etc. You wouldn't have to implement all that now, but if you have the separate class, then it's all possible in the future, at least in theory

Good luck!
Lara
 
Robert Aragon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In response of "safeguarding it against corruption", meaning the cache, do you think we have to worry about that? I mean, the actual database is also corruptible. I'm not into debating, it is waste of time, but if the cache must be safeguarded against corruption, then the database must also be safeguarded. That means neither way makes any difference in regards to corruptability.

Robert
 
Alan Mc Kernan
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am planning to use a simple cache..

Have the Data class load all the data into a Database class.. then do all the read/search ops on this Database class, and any write ops will update the database, then re-write the database file out.. (ill also have a SchemaDescriptor which the Database is based off of.. therefore its dynamic)

One problem i see here is that your obviously gonna rewrite the entire db for every write.. But your gonna have to look after compacting the db file anyway.. ie when you do delete ops you need to reclaim the space and the recordNumber right? (okay you could keep a record of in use recordNumbers and available recordNumbers.. but this could get messy im guessing).

Any thoguhts?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alan,

I don't see any need to write the entire database each time. You probably need some way to associate each record with a record number - this cannot change dynamically since you may have multiple clients who all know an old record number. You might possibly be storing the cache in a Map of some description with the record number as the key, in which case a deleted record is simply indicated by not having a record in the Map (Map.get(deletedRecord) == null).

Doing this should be fairly simple, and means that you only need to write the modified record back to the data file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic