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
Jeff_Lu
Posts: 384
Registered: ‎08-12-2008
My Device: 8700

persistence store curious question....

Hi All,

 

I am curious about if two persistence store hold same object, what will happen and what is memory allocated?

 

for example:

 

Store A object handle -------- Object content --------- object handle Store B.

 

if changing Object from Store A handle and save it, I believe it will effect B.

what is pros / cons?

 

Thanks.

Please use plain text.
Developer
simon_hain
Posts: 15,874
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: persistence store curious question....

yes, you can persist an object multiple times.
unless you commit it any changes are not saved to the persistant store.

an object in persistant store is a serialized version, if you retrieve it you create a new object.
that means even if you serialize the same object into two stores you retrieve two different objects.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: persistence store curious question....

OK, well I have a slightly different model on PersistentStore from Simon. 

 

Firstly the difference is does the BB actually Serialize the Object.  I don't think it does.  I think it stores the Object in its internal Object form.  And I think you can actually reference this Object.  Until you change it, it will remain in the Persisted memory.

 

The follow-on form this is what happens when an Object is referenced twice.  There are two cases. 

 

First the simple case. 

 

I have a Vector, in element 0 and element 1, I have a reference to an Object - the same Object.  I persist that Vector.  When I restart my device and get back my Vector will I still have element 0 and element 1 referencing the same Object.  I think so. 

 

Now the more complicated case.

 

Say I have two Vectors, Both have in Element 0, a reference to the same Object.  I persist both Vectors, but I persist them in different 'IDs'  Then I retrieve both.  So I have two different Vectors, but do both have the same Object in element 0.  I think they do. 

 

This would be easy to test.  But unfortunately I'm not going to find time in the immediate future, but if some one else could test, that would be fantastic. :smileyhappy:    Thanks 

 

And I should point out when designing data that is going to be persisted,I recommend that you make sure there are no cross references, so this sort of problem does not worry you.  One way is to 'normalize' the Objects, so that if Object A references Object B, it will actually have an id for Object B, not a reference for Object B. 

Please use plain text.
Developer
simon_hain
Posts: 15,874
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: persistence store curious question....

would be good to test, yes. entirely possible that the full object is persisted, yes.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
Jeff_Lu
Posts: 384
Registered: ‎08-12-2008
My Device: 8700

Re: persistence store curious question....

Thanks you guys kind post.

 

I keep my words to test in future. my project is whipping my A... right now.

 

I will do test which peter mentioned in thread and let you know the result.

 

Thanks again.

Please use plain text.