File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes modify Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "modify" Watch "modify" New topic
Author

modify

Kruger Scheitz
Ranch Hand

Joined: Jul 31, 2002
Posts: 72
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

Joined: Feb 25, 2002
Posts: 560
Can you describe your problem in detail? All you have to do is follow the sequence: lock-read-modify-unlock.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
So are we supposed to force a close() on the Data and re-create after every call to modify()?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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

Joined: Jul 31, 2002
Posts: 72
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

Joined: Jul 31, 2002
Posts: 72
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

Joined: Jan 30, 2002
Posts: 3451
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: modify