none
[Java][Mobile Service] Offline incremental sync and soft delete RRS feed

  • Question

  • Hello,
    We have integrated the Android SDK 2.0.3 with Offline Incremental Sync and soft delete in our project, but we have problems with the syncronization of the deleted records.

    More specifically, when we delete a record from a client the "__deleted" column on the backend database is correctly setted to 1. However the other clients continue to see the deleted record after the synchronization.

    For the syncronization we are using the following code:

    private MobileServiceSyncTable<placedso> t_place = mClient.getSyncTable("Place", PlaceDSO.class);
    
    Query q = mClient.getTable("Place").orderBy("name", QueryOrder.Ascending);
    
    t_place.pull(q, "placesPullQueryId").get();

    Could you tell us the changes we have to do in our code, to make the pull work correctly with soft deleted records?

    Thank you.




    Wednesday, February 24, 2016 10:34 AM

Answers

  • We solved forcing an "include deleted" in our JS backend.

    It seems there's a problem in Android SDK (2.0.3 and 3.0) because include deleted option is set properly only the first time (first pull, not included instead) which seems logically incorrect. If we force to include deleted records in server scripts, incremental sync works correctly also with (soft) deleted records (with new and updated records it's ok).

    Please take a look at IncrementalPullStrategy class, method setupQuery... Hope it helps.

    Monday, March 21, 2016 4:04 PM

All replies

  • Hi Juicy,

    I reviewed the source code of Class MobileServiceClient, and I found the function `public MobileServiceJsonTable getTable(String name)` is different from the function `public <E> MobileServiceTable<E> getTable(Class<E> clazz)`. They separately return the `MobileServiceJsonTable` Object and the `MobileServiceTable<E>` Object.

    Please try to use the code below instead of your code in the second line.

    Query q = mClient.getTable(PlaceDSO.class).orderBy("name", QueryQrder.Ascending);

    Hope it helps.

    Best Regards.

    Thursday, February 25, 2016 7:07 AM
    Moderator
  • Hi Peter and thank you for your response.

    Unfortunately that doesn't solve the problem, we still cannot sync soft deleted records using offline incremental sync. We also tried to use null as Query parameter without success

    t_place.pull( null, "placesPullQueryId").get();

    Obviously without incremental sync (as follows) it works!

    t_place.pull(q).get();



    • Edited by Juicy Srl Thursday, February 25, 2016 11:08 AM
    Thursday, February 25, 2016 9:38 AM
  • Hi Juicy,

    Could you share your implementation thinking for the offline incremental sync?

    I think it can help analyzing your issue.

    Best Regards.
    Friday, February 26, 2016 11:17 AM
    Moderator
  • Hi Peter,

    we are working on a client-server project where mobile clients can edit and post data to an Azure Mobile service.

    Android client app can perform CRUD operations on offline DB and then sync changes to Azure backend when internet connection becomes available. We want to use incremental sync to improve sync performances but we also need to use soft delete.

    All operations seem to sync correctly except (soft) delete.

    User A and user B starts with the same data.

    1. User A deletes a record from placeTable (it is a MobileServiceSyncTable<PlaceDSO>)

    placeTable.delete(placeId).get();

    2. When needed, user A sync changes online with the following sync request

    private MobileServiceSyncTable<PlaceDSO> t_place = mClient.getSyncTable("Place", PlaceDSO.class);
    
    Query q = mClient.getTable(PlaceDSO.class).orderBy("name", QueryOrder.Ascending);
    
    t_place.pull(q, "placesPullQueryId").get(); //An Id is required by incremental sync

    3. Record is deleted in client A local DB.

    4. User B performs the same sync request but...

    5. ...deleted record is still visible by user B (problem).

    We want that deleted record by user A will also be deleted for user B!

    Thanks in advance


    • Edited by Juicy Srl Friday, February 26, 2016 5:20 PM
    Friday, February 26, 2016 5:19 PM
  • Did you enable soft delete in your server?  If you are using .NET, you need to add a parameter to the constructor for EntityDomainManager. See https://azure.microsoft.com/en-us/documentation/articles/mobile-services-using-soft-delete/ for more information.
    Tuesday, March 15, 2016 2:08 AM
  • We solved forcing an "include deleted" in our JS backend.

    It seems there's a problem in Android SDK (2.0.3 and 3.0) because include deleted option is set properly only the first time (first pull, not included instead) which seems logically incorrect. If we force to include deleted records in server scripts, incremental sync works correctly also with (soft) deleted records (with new and updated records it's ok).

    Please take a look at IncrementalPullStrategy class, method setupQuery... Hope it helps.

    Monday, March 21, 2016 4:04 PM