0

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());
}
V.J.
  • 9,492
  • 4
  • 33
  • 49
Nilanchala
  • 5,891
  • 8
  • 42
  • 72

1 Answers1

2

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());
}
rfsk2010
  • 8,571
  • 4
  • 32
  • 46
  • Mr. rfsk2010 :- from your suggestion if there are 1000+ user then Mr. Neel have to create 1000+ persistent store. – V.J. Dec 30 '11 at 10:19
  • 1
    I highly doubt a mobile device will be used by even handful of users, let alone 1000s. Even if it has to work for 1000 users, it is better than having a single persistent store with records for 1000s of users, bear in mind there are size limitations for entries in persistent stores. – rfsk2010 Dec 30 '11 at 10:22
  • i have only one question. which is better to use (1+ persistent store) or (SQLite Database)..? – V.J. Dec 30 '11 at 10:28
  • Ok. Then create 1+ "Persistent Store". – V.J. Dec 30 '11 at 10:34
  • 1
    I am looking to implement in BB 4.5 – Nilanchala Dec 30 '11 at 11:04
  • Cool, so did you try the above answer i posted? Any thoughts? – rfsk2010 Dec 30 '11 at 11:06