• 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

data access class

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm working on URLyBird 1.3.2. The spec says that I need to create a class Data that implements a DBMain interface (provided), but says nothing about persistence. I am loading the data file into memory of the data class and manipulating it there.

On the one hand there is nothing explicit in the spec about write-back (but maybe this is inferred?) So I could possibly do nothing. On the other hand I could provide (and document) a command line function from the server that commits changes to the data file upon closure. This of course won't work if the server process is killed.

How have others dealt with the data persistence problem? I'm not about to write an RDBMS for this assignment...

Raj.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raj,

I think the main issue that people have with the data file is wether to cache it into memory or not - I don't think it really matters which you choose as long as you document your reasons.

The system must persist changes to the database file on the other hand - I don't think customers would be too happy if their reservation was canceled because someone rebooted the server! The least complex way of achieving this is to write the changes to file 'as they happen'.

Regards,

Jon
 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, just make sure to document that you consider your failsafe mechanism if your database shuts before data is written.

RK
 
Raj Nagappan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for those responses. The spec is quite unclear about this (deliberately I suppose). I think I might go down the write-back "as it happens" route using a background thread on a timer so as not to waste too many CPU cycles.

Raj.
 
Ranch Hand
Posts: 531
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wish it were as easy as having the file in memory. No, you must implement record-level locking. This involves calculating where each record begins in the file, actually, so you can read from it or write to it. It's not good enough to lock the entire file. I wish it were. As far as clients knowing which records are locked, the best way is to implement a class-level static member to keep track of the information.
[ July 25, 2004: Message edited by: Anton Golovin ]
 
Raj Nagappan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anton,

After reading your other thread about DB locking and going over the spec yet again I see your point.

On one hand record-level locking has nothing to do with the location of the DB and could equally apply to an in-memory DB (which is what I was proposing) that is later flushed to disk.

On the other hand the "data file format" section talks about a 2 byte flag for each record to determine whether it's valid or has been deleted. As soon as you recognize that you know that the file is an archive of sorts, and is probably intended to be directly manipulated regularly.

So I didn't want to create a RDBMS but it looks like I'm coming close to it
I haven't had to "seek" since my C days (several years ago). Here's hoping...

Raj.
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raj, here are some discussions where I think people loaded the whole database into memory.

https://coderanch.com/t/184523/java-developer-SCJD/certification/NX-Notes-design-passed

https://coderanch.com/t/184108/java-developer-SCJD/certification/URLyBird-Locking
[ July 26, 2004: Message edited by: Marlene Miller ]
 
Raj Nagappan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that Marlene. The thread on the successful design probably answers most of my questions too!

Raj.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic