• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

URLyBird:1.2.1 Accessing the database

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when first looking at this assignment it seemed to be straight forward but the further I analyze this project the more questions come up, and the more my pen gets gnarled at with all the bite marks. But from other responses I here, I am glad I am not alone ...

When I read the URLyBird database upon first connection I read through the
entire database and collect the meta data info of the database: i.e the header information , schema info and the record status of all the records (the 1, 0 flag if a record has been deleted or not). I do not read the actual data in, but leave the file open and my RandomAccessFile pointer ready available to jump to a record in the file. So when a client calls on one of the database access functions, my file pointer will jump to the record in the file and retrieve the data for the user. The update and create functions will actually write to the file instead of saving it in a buffer.

Is this a reasonable way ? I have noticed that the other option is to read the entire datafile and input it in a data structure and upon exiting then save the data structure back to the file.

I think the former is better as far as saving storage space but of course access time will slow down. And I felt that the implementation better represented the DBAccess readRecord(recNo) description:

// Reads a record from the file. Returns an array where each element is
// a record value.

(did they mean file in the literal since ? )

Any comments ?
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael

I do the same thing. read update delete etc everything is done directly from and to the file. I dont have any cache yet. I thought it is easier to maintain than with using a cache(the data structure that you mentioned in your post)

cache will be good when searches are lot more than update and delete operations.

This is my understanding. and there are lots of posts on whether to use cache or not. Havent gone through them thoroughly yet.

I dont think that read from file literally mean read directly from file only. It guess its our choice on how to implement the read.
Thanks
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael,

I am also intended not to cache my records but just access file when necessary, because with caching the records you have a lot of issues that makes your code more complex and less clear:
- what to do if the saving on exiting fails? what if there is some power break (maybe a whole day of reserving rooms may be disappeared? ...
- if you choose to update file and cache each time, you have other issues like i described in this thread

so that's why my intention is not too implement a cache, but work with direct file access

i have also a question for you: at first connection you read complete db-info (header info, schema info, record status,...), how did you implement locking with this one? do you have 1 method doing it all where you lock at start and unlock at the end, or do you use small pieces of code between a synchronized block? because you will need locking on different objects (e.g. you need to lock db and lock the object containing schema-info when reading in schema-info), so that may turn in a dead-lock situation.
 
Michael Fisherman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roel

Thanks Mary and Roel for your input. This is a cool community here !

i have also a question for you: at first connection you read complete db-info (header info, schema info, record status,...), how did you implement locking with this one? do you have 1 method doing it all where you lock at start and unlock at the end, or do you use small pieces of code between a synchronized block? because you will need locking on different objects (e.g. you need to lock db and lock the object containing schema-info when reading in schema-info), so that may turn in a dead-lock situation.




What I assume is that the Server is up before any client connects. My Data class's constructor function is implemented when the Server starts. Through my meta class I read all the db-info without locks, since there is no client there anyway. My meta-data structure created at the start just contains the list of meta like records , where each record just contains a delete flag and a lock cookie. Then when a client connects and calls a update, create or delete function my Data class uses my meta class as a proxy which will handle the locking before and after accessing the class that loads and manages the file.
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic