• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCJD....Database.....Problem

 
Animesh Saxena
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just got my assignment. Mostly I guess every assignment is all the same with Database , Lockin , Server , GUI and Socket implementation. I was thinking the Database would be a normal text file. But they have given the database file with Offset information kinda crude implementation of database. I am unable to figure out how to delete a record.

Cos By Deleting it means making a temporary file and copying all the data before the record to it and then copying the data after the deleted record. After that we copy this temporary file to original database file. Ofcourse offset changes will have to be made. Is there any generic way for this functionality. Cos everytime I delete a record if i have 1000 entries...I will have to copy 999 of them again and back to original file again. Any Suggestions???
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you copy the delete function comment from your assignment?
 
Kristof Janssens
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure that with deleting a record, they mean that you have to set a flag that will tell you if it is a deleted record or not.
 
Pankaja Bansal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Animesh

You dont have to physically delete a record from the file. Just mark the record as deleted. If you read your functional specs carefully again, you'll find a statement


// Creates a new record in the database (possibly reusing a
// deleted entry). Inserts the given data, and returns the record
// number of the new record.


which means that while creating a new record, you can search the first deleted entry and update it with the new record information. This way you can be sure that your database file is not ever increasing in size.

Cheers
PB
 
Eiji Seki
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Copying the whole file over and over is just one of the worst solutions ever. Just update the file directly. Research java.io package for ways of doing that.
 
Animesh Saxena
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am workin on Bodgitt and Scraper Assignment

My Database File goes like this

[edited too many assignment details here]
[ March 17, 2006: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not post large parts of your assignment description. You were asked for just the delete method description comment.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quoted from duplicated topic:
According to SCJD Requirement
// Creates a new record in the database (possibly reusing a
// deleted entry). Inserts the given data, and returns the record
// number of the new record.

which means that while creating a new record, we can search the first deleted entry and update it with the new record information. This means we can be sure that our database file is not ever increasing in size.

But what I get is suppose I have this entry
Suppose 34 indicates valid record and 85 denotes an invalid record.
34 Data1 Data2 Data3
now to delete it I need to change it to
85 Data1 Data2 Data3
How do I make dynamic change to this file. Cos in all the API's in APPEND mode we can only add some content at the end of file.

Similarly when adding a new record suppose we need to find the first deleted record and update it with new one. Again the question of replacement comes?

Is there any API in java.io package to accomplish it without creating some temporary file?


Animesh Saxena
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any API in java.io package to accomplish it without creating some temporary file?


Yes. It has been mentioned in one of the replies to your other topics on the same subject.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic