• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[NX URLyBird]: About deleted flag in URLyBird

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 ]
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Veda Dou
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Veda Dou
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic