• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

delete and enumeration in RMS

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
insert this in the startApp method.


why isnt this working? I read the documentation. It said that if i set the update to true i might face performance but at least i guarantee i wont get bad results when sorting or searching. so how come the num of records (last line) is 2? i entered 4 records. i deleted record number 1. so i expect to get 2,3,4 when i run the second print line 4 times. but i didnt. i got an invalididexception. i tried hte last print line and surprisingly i only have 2 records which explains why i got the exception.
i even read about rebuild.

im trying to implement a delete funciton on records in my store.
 
Leo Max
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A THOUSAND APOLOGIES!!! I JUST COUNTED HOW MANY TIMES I INSERTED RECORDS
 
Leo Max
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A THOUSAND APOLOGIES!!! I JUST COUNTED HOW MANY TIMES I INSERTED RECORDS
EDIT: here's a REAL question.

here's what i no. rebuild is like 'reinitializing' the recordnum. you're using an existing one. renum setting its 3rd parameter to true is a good thing tho it might come at a cost of performance.



if i remove enum line and add it where i mentioned in the comment, then i get a result of 2 then nameofbyteinstring then 5 then invalididexception

if i remove the COMMENT1 comment and leave rebuild i get the same result

The current result is 5 then nameofbyteinstring then 2 then invalididexception. so rebuilding is a good thing.

now, can someone please explain to me why im getting 5 after 2 let alone an exception? i thought it didnt jump through 'holes' but it did. but thts wierd. all i deleted were 2 records. wht happened to records 2 3 5 6? why did it jump from 2 to 5?
how do i fix this?
 
Leo Max
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A THOUSAND APOLOGIES!!! I JUST COUNTED HOW MANY TIMES I INSERTED RECORDS
EDIT: here's a REAL question.

here's what i no. rebuild is like 'reinitializing' the recordnum. you're using an existing one. renum setting its 3rd parameter to true is a good thing tho it might come at a cost of performance.

{code}
try
{
RecordStore rs = RecordStore.openRecordStore("name", true);
String one = "a", two = "b", three = "c", four = "d", five = "e", six = "f";
/*remove this line*/RecordEnumeration re = rs.enumerateRecords(null, null, true);
byte[] b;

b = one.getBytes();
rs.addRecord(b, 0, b.length);
b = two.getBytes();
rs.addRecord(b, 0, b.length);
b = three.getBytes();
rs.addRecord(b, 0, b.length);

rs.deleteRecord(1);


b = four.getBytes();
rs.addRecord(b, 0, b.length);
b = five.getBytes();
rs.addRecord(b, 0, b.length);

rs.deleteRecord(4);

/*add that line here*/
///*COMMENT1:*/ re.rebuild();
while(re.hasNextElement())
{
System.out.println(re.nextRecordId());
b = re.nextRecord();
System.out.println(b.toString());
}
}
{code}

if i remove enum line and add it where i mentioned in the comment, then i get a result of 2 then nameofbyteinstring then 5 then invalididexception

if i remove the COMMENT1 comment and leave rebuild i get the same result

The current result is 5 then nameofbyteinstring then 2 then invalididexception. so rebuilding is a good thing.

now, can someone please explain to me why im getting 5 after 2 let alone an exception? i thought it didnt jump through 'holes' but it did. but thts wierd. all i deleted were 2 records. wht happened to records 2 3 5 6? why did it jump from 2 to 5?
how do i fix this?

EDIT HERE LOOK HERE
any chance the reason why im getting an invalididexception is because re.nextRecord and .nextRecordID actually move the pointer to the next record and get the information? so what really happened is tht i printed the id of 2, the string representation of 4 and then the id of 5? cuz thts what it looks like. i ran the loop with only one print statement (id) and i got 2 3 5. i tried nextrecord alone and i got 3 strin names of the byte objects.
so this isnt like a while where you keep the pointer where it is and look ahead at the next record to find out if its null.
so there are two slutoins to track this
either have two recordenumerators, one for nextrecord, the other for nextrecordid
OR
whenever the list iof records is created i create a vector or array where i insert the index of each record. everytime i delete the record, i update the vector/array by removing it from the list.
any other third solution? thanks
reply
    Bookmark Topic Watch Topic
  • New Topic