views:

310

answers:

1

Hi there,

I have a record store of items which have (name, quantity, owner, status)

Now when the user triggers an event i want to set the status of all items in my recordstore with "purchased"

        re = shoppingListStore.enumerateRecords(null, null, false);

        while (re.hasNextElement())
        {
            // read current values of item
            byte [] itemRecord = re.nextRecord();
            // deserialise byte array
            newItemObject.fromByteArray(itemRecord);
            // set item status to purchased
            newItemObject.setItemStatus("Purchased");
            // create new bytearray and call newitemobject . tobytearray method to return a byte array of the object (using UTF8 encoded strings~)
            byte[] itemData = newItemObject.toByteArray();

            // add new byte array to shoppinglist store

            shoppingListStore.setRecord(re.nextRecordId(), itemData, 0, itemData.length);
        }

However I am overwriting the next record (using the nextRecordId), i've tried using nextRecordId - 1 but obviously this is out of bounds on the first one

Hope you can help,

Many thanks,

andy

+1  A: 

Have you tried that ?

re = shoppingListStore.enumerateRecords(null, null, false);

while (re.hasNextElement())
{
    int id = re.nextRecordId();
    // read current values of item
    byte [] itemRecord = shoppingListStore.getRecord(id);
    // deserialise byte array
    newItemObject.fromByteArray(itemRecord);
    // set item status to purchased
    newItemObject.setItemStatus("Purchased");
    // create new bytearray and call newitemobject . tobytearray method to return a byte array of the object (using UTF8 encoded strings~)
    byte[] itemData = newItemObject.toByteArray();

    // add new byte array to shoppinglist store

    shoppingListStore.setRecord(id, itemData, 0, itemData.length);
}
Maurice Perry
Just tried the above code, if you ammend the re.getRecord(id) and do recordStoreName.getRecord(id) then it works a treat :) thanks (edit your code and i'll tick your answer) thanks
Garbit
right, I updated the post
Maurice Perry