hi,all my assignment is B&C constractor,and i have a question about the instructions. thanks in advance the deleteRecord(long recNo, long lockCookie) method require deleting a record,making the record number and associated disk storage available for reuse,but the data section of the data file already has a deleted flag for each record which implies the record deleted with 0
Originally posted by janvy wei: ...but the data section of the data file already has a deleted flag for each record which implies the record deleted with 0
Don't you have something like this in your assignment instructions:
Data section. Repeat to end of file: 1 byte flag. 00 implies valid record, 0xFF implies deleted record Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information
Are you saying that in your database file that all the records in the data section have a zero value for the 1 byte flag that implies a valid record? If so, and if your instructions are the same as I quoted above, then the records in your database are all valid (that is, not deleted). To delete a particular record you merely set the 1 byte validity flag to 0xFF as directed in the assignment instructions. If you're saying that all the records in your database file are already marked as deleted, then that is an unusual but possible situation. If I were you though, I would be tempted to check how I am reading the database file. You could be experiencing an off-by-one error somewhere in your reading of the database file. I believe it is the usual case that none of the records are marked for deletion in the database file that Sun supplies (although of course there are many different versions of this file, even for the the same general assignment such as Bodgitt and Scarper Contractors). Hope this helps, George
SCJP, SCJD, SCWCD, SCBCD
posted 16 years ago
george,thanks your help once again. my instructions are the same as yours.i am at a loss for how to make the record number and associated disk storage available for reuse in this situation--i can't delete a record really. could anybody give me some advice about this?
posted 16 years ago
Originally posted by janvy wei: i am at a loss for how to make the record number and associated disk storage available for reuse in this situation--i can't delete a record really. could anybody give me some advice about this?
The only thing the delete needs to do in order to make the associated disk storage available for reuse is to mark the record as deleted (i.e., write 0xFF as the validity flag for the record). So now the record is deleted, but it still occupies physical storage space in the database file. When you implement the create method you can take advantage of this fact by reusing the associated disk storage for this record to store the new record in the same physical location (and changing the validity flag to 0x00). So you can delete a record by simply marking it for deletion (that is, setting it's validity flag to 0xFF). And you can reuse this storage by implementing the create method to do so. Additionally, you could write a method that would compact the database file, that is, physically remove all space associated with records that have been marked for deletion. But you are not required to do this and therefore I don't recommend creating such a method. Hope this helps, George