clarification on blackberry persistent store - blackberry

I have a blackberry app that's already been deployed and I'm currently working on an update for the app. In the existing app, I use a persistent store that stores 3 primitives (int, String and String). In this update I decided to add a new String to the persistent store. My question is this, will the "new" String somehow affect the app when users upgrade? Will the app just simply add in the new String to the existing persistent store or will it wipe the existing persistent store completely and create a fresh one because of the new String? Thanks

If the object being persisted is your own class and you add a variable to it, then it will wipe out the existing data completely. The reason is that once the class changes, the system cannot deserialize your older object anymore. To handle the current situation, if you want to preserve the original data, do not make any changes to the original class.
Add the additional variable in another persistent object. This time take care to ensure that your object can handle additional data that you may need to save in the future.
The best way is to create such a class is by extending a collection class - like an IntHashtable or a Hashtable or a Vector and use it to store your settings data.

Related

Deleting entity from core data

After making a rough version of my app, I am now looking to make the finalised version which is better and has many improvements. This involves changing the attributes in the entity holding the timers.
Having put the app on TestFlight already, some of the downloads will have data stored already. I am going to delete the current entity and make a new one. Will this cause any problems if data is already stored for the attributes within the entity that is going to be deleted?
IMPORTANT: I do not want to keep any of the data in the entity to delete and I want to delete it all, so when users update all their data will be gone (this is fine as I distributed it only to people I know e.g. family/friends), who have given some feedback.
Any help is much appreciated. Thanks in advance.
CoreData is very pedantic. Once a store has been created based on a data model, you cannot use it with a different model unless you do some kind of migration. Different in this case means almost any change to the model. Certainly changing the attributes for an entity, or adding a new entity, will be sufficient for CoreData to throw an exception if you try to open the existing store with the new model.
If you want to preserve the data in the existing store, you would have to do a migration, but since you do not want to preserve that data, it will be easier to delete the store when the new version of your app is first run, and let CoreData create a new store using the new model.

Copy records between persistent stores in core data?

I want to copy data from one store to an other. Destination persistent store could already have records. Is it any easier way, than manually go though all the records and insert into the new context and save?
If you want to copy all of the data, you can use migratePersistentStore:toURL:options:withType:error:, which is a method on NSPersistentStoreCoordinator. This will effectively copy the entire persistent store to a new persistent store file. Some things to be aware of:
Despite the name, this method has nothing at all to do with model versioning. Both use the word "migrate" but they're different processes.
You should be sure that you have saved all outstanding changes before attempting this.
After doing this, the store that you're migrating from is removed from the coordinator-- which means that
Any existing references to managed objects are now invalid. You should re-fetch them.
If you continue using the coordinator, you're using the new store file.
If you don't want to copy all of the data, you need to do it "by hand", fetching objects from the old store and creating equivalent objects in the new one.

Core Data with multiple persistent stores

I am trying to use multiple (two) persistent stores with Core Data for the first time.
It seems quite simple to add a store; but once this is done, how do I specify that a request to write (or read) some information to (or from) an entity has to be performed on one store or the other?
Some sample code would be welcome, but I can’t find anything on the net.
Fetches always cover all of the persistent stores managed by the coordinator.
When adding data, you can do either of the following:
Use configurations in your data model and when adding persistent stores. Configurations define named subsets of your model that contain some but not all entities. If an entity only exists in a configuration that's only used with one persistent store file, then new instances will automatically go to that store.
If the above doesn't work for your app, you'll need to call assignObject:toPersistentStore: to tell the managed object context which store to use.

Will the data stored in my PersistentObject be retained on App update in Blackberry.?

I have developed a blackberry app, in which I am using Persistent Storage to save some data. The app is already live on the market. I am creating some new PersistentStorage values in my second version. Will this data be retained if I update my app from BlackBerry App store? or the data will be lost?
If you change the class definition of your persistent objects (like adding, removing or changing the type of data members) then you will likely loose your data. The system will detect the change in structure and will have to delete the class definition and all instances of the class.
There are two ways around this problem:
Only use classes that are defined in the OS (HashTables, Strings, int, float, double, etc) to build up the structure that you need. (this will have the side effect of the data persisting past application deletion as well);
If you need to use a new class, and then need to change it, create a new class that uses a different persistent object ID and during start up detect if the user has data stored under the old class. If so, migrate the data to the new class and delete the old class.

CoreData Update Database Leaving User Entries

First, Thank you for any help provided.
I have an iOS leveraging CoreData to retain various presentations, this data comes from a sqlite file and there is no server connection.
I will have to be able to provide App updates (via appstore), this update may add more data to the database.
The tricky part is that it can not simply overwrite the current database, there are a few user tables that I will not like touched.
Please provide any information I should consider when accomplishing this or any links are greatly appreciated.
Thank you.
Given your app has no server connection, you will have to rely on shipping data within the updated application itself. I would recommend using a plist file or define your own xml or json structure. You can then read this data to create/update core data nsmanagedobjects.
It looks like someone in the past was using plist->coredata on SO
Would you have relationships between user created data and shipped data?
If not, you might go the route of connecting two stored to the persistent store coordinator. The shipped store would be read-only. The store with user created data would be read-write. You can use this approach, too, if you have relationships between shipped and user-created objects, but it's a lot more complicated, since CoreData doesn't manage cross-store relationships for you, and you'll need to write your own logic (doable, but not straight forward).
If you need to have relationships between shipped and user-created objects, you can still ship a CoreData store. When the app launches for the first time (no user-created objects), you copy the store to the Documents folder and user this store to create your CoreData stack. User created objects will be added to this store. Once you have new 'shipped' objects (i.e. a new store in the app-bundle), you'll have to manually migrate that stores data into the store that the user has changed. You'll have to be able to find
(1) objects that need to be deleted
(2) objects that need to be updated (changed)
(3) objects that need to be added
If you mark your shipped objects with a special flag such that you can tell if it's a user created object or a shipped one, that would be doable. You also have to have some sort of ID to be able to tell which objects in the new store correspond to which ones in the existing (old) store.
You do not need to go the route of using plists. In fact, I'd recommend against it. You can easily open two stores at the same time. Either to use both stored, or just to migrate objects from one store to the other store.

Resources