• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

B&S Record Number Question

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I realise this is probably a really silly question, and its my first time to post so I hope I don't annoy anyone

I've just started on my SCJD project and I'm in the design phase of the data access part. I've been looking at the instructions, at the part where it tells you about the fields that are in the database and I notice that there are no record numbers, i.e. no unique identifiers for the records in the database. Now, maybe I've just been using relational databases too long but I can't see how this is going to work.

I could of course read all the records and create record numbers for them on the fly but then how do you find them once they've been written to the database? Am I missing something?
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hadled this issue by caching the data in the application. All interactions that the users have with the data is actually with the application cache of the data, not the file itself. When I read in the records, into a Vector, the order in which they get added becomes their key. Occasionally I write them back out to the file (when needed do to changes by the users), and it doesn't matter what order they end up in as/when they go out.

This is my first post here too, but I hope that helps you some.
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each record is defined by its offset from the beginning of the database file, with record 0 (or 1, depending on how you count) starting at 1 byte past the last byte of the file header.
If the record is 200 bytes long (for example), and the header 400 bytes (for example), that would mean that you can calculate the location of a record in the database as

if you use zero-based recordIds.

Or more correctly, as there's the flag indicating whether a record has been deleted (which I don't count as part of the record):


Therefore the recordId can be determined as


If you ever needed to calculate it based on the position of a record in the database.
 
Katie McGettrick
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you!
 
Die Fledermaus does not fear such a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic