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 [NX URLyBird]: About deleted flag in URLyBird Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "[NX URLyBird]: About deleted flag in URLyBird " Watch "[NX URLyBird]: About deleted flag in URLyBird " New topic
Author

[NX URLyBird]: About deleted flag in URLyBird

Veda Dou
Greenhorn

Joined: Sep 27, 2003
Posts: 5

1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record.

After one record been deleted, if we will locate another record ,how to recompute the record number ( locate the position of new record)correctly and efficiently ?

My solution , Every time I will search it from beginning until the record found . I know That is unefficient .
1. Can I use a List to keep all records' positions (not including the deleted records )?
2 . What are other solutions to this question?
Give me some suggestion please.
Thanks.
[ September 27, 2003: Message edited by: Veda Dou ]

SCJP2 MAY.2002
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11478
    
  94

Hi Veda,
Welcome to JavaRanch.
Why do you want to recalculate the record numbers? If a customer asks for record number 5, then a different application deletes record number 4, then the first customer updates record number 5, it still has to update the record that was at position 5 before the deletion.
It seems simpler to me to have record 5 always be treated as record 5. Regardless of whether any of the records from 1 - 4 have been deleted.
So when a customer asks to update record number 5, I can just seek to (recordNumber * sizeOfRecords) + sizeOfHeader (this assumes record counts start at zero of course). This works regardless of whether record 4 has been deleted.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Veda Dou
Greenhorn

Joined: Sep 27, 2003
Posts: 5
Maybe I said my intention unclearly.
A example as bellow , before update one record , I must seek the Record . "recNo" shouldn't be the deleted record . the "recNO" should be a real record number which can be update .
Another example , if we caculate the total count of records . we can't caculate those deleted records.

for your example,
if the No.5 was deleted , then another application find(5) should go to the next record because the original 5 was not exists(deleted) . How to ignore the deleted record .
that is ,if number 5 deleted, getRecord(5) can't use :

(recordNumber * sizeOfRecords) + sizeOfHeader

to compute the real number 5 position,you just get the old deleted one .
[ September 27, 2003: Message edited by: Veda Dou ]
Light Wan
Ranch Hand

Joined: May 15, 2002
Posts: 31
Hi Veda:

that is ,if number 5 deleted, getRecord(5) can't use :

quote:
--------------------------------------------------------------------------------
(recordNumber * sizeOfRecords) + sizeOfHeader
--------------------------------------------------------------------------------

to compute the real number 5 position,you just get the old deleted one

If one client deleted record 5 and other clients do not know(provided that you do not implement callback). Then maybe other clients want to read record 5, now Data class should throw new RecordNotFoundException. That adhere to the specification.
Regards.


SCJP2
Veda Dou
Greenhorn

Joined: Sep 27, 2003
Posts: 5
Here----
deleted flag fields value
0 rec1Fields
0 rec2Fields
1 rec3Fields
0 rec4Fields
1 rec5Fields
0 rec6Fields
0 rec7Fields
If I want to caculate the total number(recordsCount) ,it should be 5 . because 2 records were deleted.
If i want to getRecord(5) , it should be "rec7Fields" .
Veda Dou
Greenhorn

Joined: Sep 27, 2003
Posts: 5
I think that bellow code has a bug , when read(5), if physical 5 was deleted ,but the logical 5 is exist , then it's error that bellow code throw exception.

[ September 28, 2003: Message edited by: Veda Dou ]
Light Wan
Ranch Hand

Joined: May 15, 2002
Posts: 31
Hi Veda,
Firstly, let's look at the following scene:

Client A and client B have read these two records. Client A deleted record 1 and client B did not know that happened. After a moment, client B want to book the room at record 1(the room at L.A.). Now, do you let client B to book the room at N.Y.?
Best rgards.
[ September 28, 2003: Message edited by: Xiaoguang Wan ]
Veda Dou
Greenhorn

Joined: Sep 27, 2003
Posts: 5
I see. Thanks!
because the "recNo" is a physical concept in specification(associate with file point), then it 's correct to use :
(recordNumber * sizeOfRecords) + sizeOfHeader

to seek record position .
but ,I understand it deviatly .
if the "recNo" is a logical concept(associate with valid record) , then it will be complex in the method read(recNo); ... some puzzle
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Veda,
Recnos represent plysical positions of records in the file. So if you delete record 5, any attempt to read, update or delete record 5 will throw a RecordNotFoundException.
Now, if you want to optimize an isDeleted() method as well as the createRecord() one, you could put all deleted recNos in some deletedRecords HashSet (or TreeSet) and maintain it up-to-date. That's what I do.
Best,
Phil.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [NX URLyBird]: About deleted flag in URLyBird