Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

deleting records from File

 
Pankaja Bansal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody

I am caching all the records in my DB file on the start of the application and whenever there is a write operation, I persist the changes on to the file. For memory I am using a flag for deleted or valid record but my confusion is when I am persisting this change on the file, I should actually be removing this record completely from the file. What I am doing right now is marking the record as deleted on the file but this will lead to a lengthy file which is not correct.

Is there any way by which I can reclaim the space on the file system deleting the deleted records permanently. I dont want to write the whole file again and again on any write operation as it will be a less efficient. Any suggestions would be really appreciated.

Cheers
PB
 
Pankaja Bansal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry guys, I just found the answer to my query. I request the moderators to please delete this topic.

For the benefit of others though, I would like to post this link which is a very good resource for developing a small database system using RandomAccessFile class .


Use a RandomAccessFile to build a low-level database
http://www.javaworld.com/gomail.cgi?id=658086
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pankaja,

If you have some specific reason for asking for this topic to be deleted, then please contact me via private message to explain why, and it will be deleted. Otherwise our standard procedure is to leave these topics in existance so that someone else can later read your posts and see the link you provided.

Regards, Andrew
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This link is awesome!
 
Pankaja Bansal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My latest confusion is related to the deletion of records from the database. The method provided in the interface takes an integer value pointing to the record tbe deleted

// Deletes a record, making the record number and associated disk
// storage available for reuse.
// Throws SecurityException if the record is locked with a cookie
// other than lockCookie.
public void delete(int recNo, long lockCookie)
throws RecordNotFoundException, SecurityException;


Now the problem is, suppose I receive a list of records from server. And I delete a particular record , say 5th. Now by the time my request is executed on server, Another user has updated or booked the record 5th. How do we deal suuch a situation ?

The same problem may arise during various other cases when the record we are updating has already been updated or deleted by some other person.

Another doubt I was having was related to add/ update/ delete feature. My assignment does not mention explicitly that I should provide any such feature. It only asks me to provide an option for booking. Should I be providing these abilities in my applications or not ?

Thanks in advance ..

Cheers
PB
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe your client would not talk to the db interface directly. There is an service layer in between which will lock between read and update then unlock to ensure the operation is atomic.
 
Pankaja Bansal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me reframe my problem

Say at time 0, I read a record and displayed on my client.

At time 5 secs, another client, updated the same record.

At time 10 secs, my client wants to update that record.

Since I cam seeing the status of that record as it was 10 secs before, I am actually updating a record which was already updated 5 secs ago by another client. This should not happen, but I cant figure out how to handle such a situation.

Moreover, I am not using a service layer in between. My client is directly talking to the DB layer as I've adopted a 2 tier framework after going through the long discussion on this forum.

Cheers
PB
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't finish this part so I am just trying to figure it out just like you.

Your client has the previous values, before your update, can you lock it and read it one more time to verify the old recond is identical? Then update the record if it was unchanged.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic