Nilanchala
Nilanchala

Reputation: 5941

Blackberry persistence store + user level access

I am currently working on the saving the information using blackberry persistence store. I have to save the details according to the user level access.

Scenario: User 1 has logged in and saved some details to the persistence store, and then User2 logged in. The data saved by User1 should not be available for User2. Can you please guide me how do i fix that.

I am using the below code.

try {       
    store = PersistentStore.getPersistentObject(key);
    CodeSigningKey codeSigningKey = CodeSigningKey.get("ACME");
       synchronized (store) {
        objectsList = new Vector();
        store.setContents(new ControlledAccess(objectsList,codeSigningKey));
        store.commit();
       }
   } catch (Exception e) {
       Dialog.inform(e.toString());
}

Upvotes: 0

Views: 252

Answers (1)

rfsk2010
rfsk2010

Reputation: 8611

You could create a different persistent store for each user by using the username as key

so what you should do is the following

try {

String username="joe";
String key =StringUtilities.stringHashToLong (username); 
store = PersistentStore.getPersistentObject(key);

CodeSigningKey codeSigningKey = CodeSigningKey.get("ACME");

synchronized (store) {
    objectsList = new Vector();
    store.setContents(new ControlledAccess(objectsList, codeSigningKey));
    store.commit();
}
} catch (Exception e) {
Dialog.inform(e.toString());
}

Upvotes: 2

Related Questions