Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

modify

 
Kruger Scheitz
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do i need to knwo about modify? i have problem getting the seats to be deducted by one..where to start off??
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you describe your problem in detail? All you have to do is follow the sequence: lock-read-modify-unlock.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kruger,
The way modify() works is that it takes a DataInfo, verifies that another record in the db does not have the same key and then attempts to overwrite the record in the database. If the record does not exist, then the call to seek() will generate an IOException which will then be rethrown as a DatabaseException in modify, otherwise the modification proceeds. Now if you want to book one seat on a flight you need to build a DataInfo from that record, decrementing the seats by one. Maybe something like this:

Hope this helps,
Michael Morris
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesn't really relate to the original question, but to the modify() method implementation in the Data class provided.
I just started the assignment and wrote a simple test client to test modify() (among other stuff). I noticed that although my lock-read-modify-unlock worked fine (seats were always deducted as supposed to) aborting execution with Ctrl-C also "rolled back" all deductions and the seats always increased back to the original.
Is this intentional? By a swift browsing of the Data implementation it seems that the RandomAccessFile.write(byte[]) is called eventually, which I think should write the data straight to the disk, right? Why do I get the feeling that the only way to "force" a flush for the RandomAccessFile would be the close() the RandomAccessFile?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lasse,

... which I think should write the data straight to the disk, right?

I can't say for sure but I doubt it. I would think, that to guarantee that the disc data is synced is to close the RandomAccessFile.
Michael Morris
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So are we supposed to force a close() on the Data and re-create after every call to modify()?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lasse,

So are we supposed to force a close() on the Data and re-create after every call to modify()?

No. If you're really concerned, just do a graceful shutdown of the server by locking the database and calling close() on Data.
Hope this helps,
Michael Morris
 
Kruger Scheitz
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hie morris..thx for your reply..
-- i see that we need to pass a DataInfo object into doBooking() right? where is this object passed from? from the client? if so, we need to do a "READ", which is the find() since it returns DataInfo reference....And is this the "READ" here one of the sequence in lock-read-modify-unlock that you all are talking about??
-- what is seatsToBook that u coded here? u mean the number of seats the end user keys in ??
 
Kruger Scheitz
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and we do not need a lock and unlock in a local mode right? so we only need read - modify here right? am i correct? and what is "read" here really mean? does it means it finds the record from the d/b and return DataInfo reference ??
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kruger,

-- i see that we need to pass a DataInfo object into doBooking() right? where is this object passed from? from the client?

That's where I did it. My DataFacade had a private inner class that built the DataInfo that was passed to the modify() method.

... if so, we need to do a "READ", which is the find() since it returns DataInfo reference....And is this the "READ" here one of the sequence in lock-read-modify-unlock that you all are talking about??

Actually I used getRecord() instead of find() but find() is OK too. It is the read that everyone is talking about. You should use that DataInfo to create the updated DataInfo to pass to modify(). You'll need to change the seats field by decrementing it by the number or seats requested.

-- what is seatsToBook that u coded here? u mean the number of seats the end user keys in ??

That's what I mean.
Hope this helps,
Michael Morris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic