开发者

BlackBerry persistent object /storage nuance question

开发者 https://www.devze.com 2022-12-25 02:35 出处:网络
I\'m using PS to store data in my app.I think I have a misunderstanding of how PS works.If anyone could tell me how to make it so that the bill I retrieve from PS is unencrypted as opposed to the encr

I'm using PS to store data in my app. I think I have a misunderstanding of how PS works. If anyone could tell me how to make it so that the bill I retrieve from PS is unencrypted as opposed to the encrypted bill I end up with? Note: I originally store and unencrypted bill!

From what I can tell, it considers both bills, and both PO objects to be the same objects! When I look at their memory locations in Eclispe, both bill and both PO objects have identical memory locations! What am I missing?

Thanks!

    //create an unencrypted bill
    BillDAO testBill = new BillDAO();

    //store it in PS
    PersistentObject po = PersistentStore.getPersistentObject(4);
    po.setContents(testBill);
    po.forceCommit();

    //encrypt the bill
    testBill.encrypt();

    //retrieve it from PS using a different PO
    PersistentObject po2 = PersistentStore.getPersistentObject(4);
    BillDAO retrievedBill = (BillDAO) po2.g开发者_StackOverflowetContents();

    //and now for some reason my retrieved bill is encrypted!
    //it should be unencrypted


The two objects (in PS and in RAM) are linked, therefore changes to one reflect on the other. See Mike Kirkup response to this thread on the BB forum and in specific:

You should only ever call setContents() once. This would occur on the very first time that you are adding data. For each subsequent call you should be calling getContents() and then modifying that object directly. By modifying the object directly, you would then call commit at the end of your work where the system would properly commit your changes...

Also, you might wanna checkout his recommendations for key generation :)

Hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消