07-16-2009 01:28 PM
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?
07-16-2009 02:07 PM
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.
07-16-2009 02:19 PM
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?
07-16-2009 02:34 PM
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"
07-17-2009 10:03 AM
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...
07-17-2009 10:07 AM - edited 07-17-2009 10:08 AM
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).
07-17-2009 10:11 AM
07-17-2009 10:11 AM
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.
07-17-2009 10:15 AM
07-17-2009 10:16 AM
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.