I am developing a Location-based J2ME app & in that I'm using RMS to store data.
In RecordStore
when I delete any record, the underlying records doesn't get re-indexed. For example, if I have 5 records & I delete record no.2 then record ids will be {1, 3, 4, 5}. But I want record ids after deletion to be {1, 2, 3, 4}. How should I do this??? Because recordId is playing an important role in my app to retrieve & update the record.
So, since you've said that your record store is basically small (not that much data), I would recommend simply adding your own custom
id
field to each record. As Meier said, the RMS record id is not really meant to be recalculated, and changed, once a record has been created. So, I would use your own.If each of your records contain:
then, I would simply add another field at the start of each record:
It makes your records a little bigger, but not much (4 bytes/record). If you'll have less than 64k records, then you could also use a
short
for theid
, and save a couple bytes.Here's an example (adapted from this IBM tutorial), of reading, writing, and deleting with this kind of record:
Here, I make use of a couple small
RecordFilter
classes, to use when searching the record store: