I am trying to implement downloading of bulk data from several tables on the server.
In my case there are 16 tables. For all these tables I will be firing 10 requests to the server. This means I have done a bit of logical groupings for related tables, but it is like all tables are inter-related with each other through one or the other relationship.
I need to consider three cases while doing downloading:
- Saving data to each table at local.
- Managing relationships between inserted objects.
- Handling situation when one of the requests fails during download, say 8th request failed.
I will be following this approach for each response:
- Inserting data in managed object context.
- Managing relationships by firing NSPredicate and associating the related objects.
- Saving the context.
In case of a response failure, I have two options:
- Next time continue from the failed response.
- Revert all saved data to its previous state.
1st approach may lead to some data inconsistency, so I am going with 2nd approach.
I know that if a managed object context is not saved, we can revert the changes, but
is it possible to revert the changes, if the managed object context is saved?
I require some useful answers from the community.
Please suggest.