Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a Result from Azure a row is Inserted and Delete a Row Data From Local Database After Inserted in Azure Database

1.My Application is Every 2 mins data is inserting in local Database(Using Azure Offline Sync), then every 5 mins data is Sync to Azure Database with a Background Service.

2.Each Row Data After Inserting in AZURE server, i want to delete from Local Database.

My Question :

1.how can i know My each row is Inserted or not in Server. Any response will send back to client End from Server. Else Other Solution? .

2.Delete a row Inserted in Azure Server from Local Sqlite(After Getting Conformation as Inserted from Azure Server).

Also I want to Retrieve Data saved In local Database Using Azure method.

I am Using Azure Cloud for Server End.

Link I referred for Offline Azure Sync from Sqlite

like image 334
Kumar Avatar asked Jan 07 '16 07:01

Kumar


1 Answers

For 1, you can implement your handler to intercept the server responses before giving that data back to the client (see: https://github.com/Azure/azure-mobile-apps-android-client/blob/ef4759078cb031de9a5cbb05d07dc52322952ac1/sdk/src/sdk/src/main/java/com/microsoft/windowsazure/mobileservices/table/sync/synchandler/SimpleSyncHandler.java)

public class MySyncHandler implements MobileServiceSyncHandler {

@Override
public JsonObject executeTableOperation(RemoteTableOperationProcessor processor, TableOperation operation) throws MobileServiceSyncHandlerException {
    try {
        return operation.accept(processor);
    } catch (Throwable e) {
        throw new MobileServiceSyncHandlerException(e);
    }
} 

If the operation didn't throw, that means the HTTP request was successful, so you can then move to deleting the item.

To delete a row, you don't want to use a sync table since that would track the operation. You could use a direct SQL connection to do so. Another option would be to update the above function to throw a custom error instead of returning. This would allow the error to bubble up to the next method in the handler (onPushComplete).

With the TableOperationError class, its easy to cancel the operation and discard the local item using a built in method on the sync context.

So loop through the getOperationErrors() method and for each one that is your custom error simply call the cancelAndDiscardItem method (https://github.com/Azure/azure-mobile-apps-android-client/blob/ef4759078cb031de9a5cbb05d07dc52322952ac1/sdk/src/sdk/src/main/java/com/microsoft/windowsazure/mobileservices/table/sync/MobileServiceSyncContext.java#L283)

Finally, retrieving data out of the local store is done via the SyncTable class. The read and query methods are mostly indentical to the online versions. Here's an example lifted from the Android QS:

    Query query = QueryOperations.field("complete").eq(val(false));
    return mToDoTable.read(query).get();
like image 53
phillipv Avatar answered Sep 28 '22 21:09

phillipv