Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Developer
Posts: 167
Registered: ‎11-12-2008
My Device: Not Specified

How does the static PersistentObject.commit work?

[ Edited ]

I'm looking at code that I wrote which works, but I'm not quite sure how PersistentObject.commit() works.  More specifically how does it know what persistent store ID to use?

 

Here's some sample code:

 

PersistentObject persistentObject = PersistentStore.getPersistentObject(PERSISTENT_ID);
Object o = persistentObject.getContents();

// code to cast o to "data"
PersistentObject.commit(data);

 


 

 

Message Edited by bo on 10-14-2009 05:50 PM
Developer
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: How does the static PersistentObject.commit work?

[ Edited ]
In the non-static case, it may be the case that the PersistentObject has a reference to the ID; in the static case, I'm not so sure -- it may pick an ID for you -- but then how is one supposed to retrieve it statically?
Message Edited by ydaraishy on 10-14-2009 06:20 PM
Developer
Developer
Posts: 167
Registered: ‎11-12-2008
My Device: Not Specified

Re: How does the static PersistentObject.commit work?

Yep that's my thought process.  Perhaps it keeps track of them by type?
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: How does the static PersistentObject.commit work?

I think it does keep them by type since only one type of an object is allowed in persistent memory.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How does the static PersistentObject.commit work?

I don't think type is relevant, you have multiple objects of the same type stored in different IDs. 

 

I must admit that I had always assumed that the static commit was used against objects that you had previously used with a setContents, so the persistence processing just had to search the defined PersistentObjects and find the one whose content was the Object identified.  But there is no Exception defined that can be thrown if the object has not been previously used in a setContents and no documentation that I can find that says this.  Just my speculation.

Highlighted
Developer
Developer
Posts: 167
Registered: ‎11-12-2008
My Device: Not Specified

Re: How does the static PersistentObject.commit work?

Thanks Peter, maybe I'll try the static commit without calling setContents first and see what happens.