• 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
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

(B&S) The read() method

 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
I have been a bit confused on how to go by implementing the read() method. Since it accepts an Integer, my immediate instinct is that it would use the value supplied and jump to a particular section(That is after all the schema section and header section has been skipped)!I would like it if i could get a pseudo-code of some kind!
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you are basically correct. So try to write a formula for getting to the n-th record, n >= 0. Let p(n) be the file pointer position of the record you want to find. Let o be the offset to the first data record, r be the record length (including its delete flag). What's p(n)?

You may have to adjust that for your own particular file schema.
[ December 03, 2005: Message edited by: Barry Gaunt ]
 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thanks i was able to solve the above quoted problem on the same day! Now the problem i face s this:
I intend to use a cache(An arraylist), that would have the records on the data file. My algorithm would involve the constructor of my data class read the whole records of the datafile unto an arrayList(private static: so that only one instance is available if client requests for the data file).
My question is this: Do i allow the read() method read from this cache instead of the actual file?My second question is: Is it ok to have the constructor of data.java read all the record once it is invoked?Thanks!
 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
My other question is: Do i sync on my cache cause i figured, a client might be trying to update, a deleted record!In any case, i would luv a push in the right direction! Thanks!
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,Saheed

I think you are on the right track.

Do i allow the read() method read from this cache instead of the actual file?


I do the same thing as what you want to do. You may find in this forum that using cache is valid in this exam.

Is it ok to have the constructor of data.java read all the record once it is invoked?


I also did it just like what you said.

Do i sync on my cache cause i figured, a client might be trying to update, a deleted record!


Yes, I think you have to ensure thread safety in multithreading environment by using synchronized sign in this ArrayList when your program is running in the server mode.

I hope this would be helpful.

Regards, Ailsa Cape
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic