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
Highlighted
Developer
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Persistent Store Across Application Upgrades

If I have a custom class which is stored in the Persistent Store and I make an upgrade to the application that gets installed (overwriting the old), will the Persistent Store which contained my custom object of application data be cleared first and then would the new object from the updated application be stored in its place?

 

If not, what if the my custom class to store in the Persistent Store changes (i.e. I add another member variable), wouldn't this cause the old object to be overwritten once the update application gets installed?

 

Thanks

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Persistent Store Across Application Upgrades

If you are installing new app over existing one (old) then all persistent objects will be intact.

 

If you preserve full qualified class names (package structure) and use the same persistence keys (long values) you can access persistent objects stored by old previous application.

 

Persistent object created from custom class will be cleared if you uninstall old application before installing a new one.

Developer
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Persistent Store Across Application Upgrades

I was wondering how the blackberry handled that without you manually doing an uninstall and reinstall --  You know when it asks you "This app already exists, would you like to upgrade?".

 

You should use a custom class to store application data because if you use standard java objects like Strings, they will never ever get removed -- even when you remove the application from the blackberry.  The only way to remove this stray data is to wipe the blackberry.

 

So are you saying if you store the persistent object using the recommended custom class approach, without changing that class in an upgrade, it would still get cleared?  This doesn't seem right.  Imagine if an application required a dynamic license key...there would be no way to upgrade without the application losing the fact that the customer already used a valid key.

 

What do you think?

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Persistent Store Across Application Upgrades

Q: I was wondering how the blackberry handled that without you manually doing an uninstall and reinstall --  You know when it asks you "This app already exists, would you like to upgrade?".

 

A: If there is same cod filename as an existing one you get this message.

 

Q: So are you saying if you store the persistent object using the recommended custom class approach, without changing that class in an upgrade, it would still get cleared?

 

A: Negative. No. I did not mention that.

 

If a class instance: com.mypackage.MyClass has been saved in PersistentStore it won't be cleared until you either uninstall the application or deliberately destroy the persistent object in your application using the right persistence long key.

 

If you are uninstalling an application all persistent object built on custom classes of this application are cleared.

 

If you are rewriting an old app with a new one it does not make affect on persistent objects. If you are installing a module with the same cod filename you get a confirmation dialog and if accepted the old application is going to be rewritten with the new one.

 

If you install a cod module with the same full qualified class names (including package name) but different cod filename you will get runtime error like that: "Class com.mypackage.MyClass is already defined"

 

 

Developer
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Persistent Store Across Application Upgrades

Ok.  Thanks tbilisoft, thats what I thought...but now the original question still stands: if I release an upgrade that added to the custom class that I persist (I add two new variables because the new version requires this), will that object, stored by the previous version, get overwritten because the structure has changed?

 

I actually looked at my code and I know the answer to this question as I think I came across this before.  The object would be invalid and you would lose everything you stored if you had a custom class with separatae variables for data you need saved. My custom class just has one Hashtable as a variable and I add all data elements to it.  The structure doesn't change if I add new data so I shouldn't have to worry about this. 

 

I guess I just had to write this all out...Smiley Happy

 

Thanks

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Persistent Store Across Application Upgrades

[ Edited ]

If you amend the structure of class which instance is already saved in persistent store it will cause a RuntimeException if you will try to load old instance and cast it to the modified class type.

 

If you won't read old information and just want to overwrite it with new object created with new class and using the same persistent key it will be overwritten without problem.

 

Nothing will be done automatically. You will need to compose an object according to the new class and write it to the persistent store using old persistent key (long value).

Message Edited by tbilisoft on 17-07-2009 03:08 PM
Developer
Posts: 91
Registered: ‎02-04-2009
My Device: Not Specified

Re: Persistent Store Across Application Upgrades

If you change the signature of a Persistable class (i.e., add or remove fields), Desktop Manager and OTA installs will wipe your persistant data.  JavaLoader will tell you that the data is imcompatible and won't let you load the new module.
Developer
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Persistent Store Across Application Upgrades

Right. Yes, I was trying to see how to preserve the fact that the customer has enetered the valid key when the application gets upgraded which would require a read from the object.

 

Thanks again!

Developer
Posts: 91
Registered: ‎02-04-2009
My Device: Not Specified

Re: Persistent Store Across Application Upgrades

tbilisoft, are you sure about the RuntimeException?  Whenever I've changed a Persistable class, the upgrade process has always wiped the old data automatically.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Persistent Store Across Application Upgrades

If you wish to have persistent data working after update store all data as an xml string into a custom wrapper object.

 

And parse this string when you need to use persisted information.

 

This custom wrapper object won't change and will always have the same structure.

 

And you will be able to update other your classes as often as you wish.