Merge Algorithm
The heuristic used by the Offline Store to compute the fixed requests attempts to merge the details of new requests as far forward as possible, in order to replace any incorrect data in the original requests with correct data.
Here are some common scenarios:
Fixing the properties of a failed POST request
A subsequent PATCH can be made to the entity with the corrected values. The merge heuristic combines the PATCH and POST requests into a single new POST request containing the corrected values.
// createEntity results in an error
// Load the entry in the error archive
DataQuery errorArchiveQuery = new DataQuery().from(errorArchiveSet);
EntityValueList errors = eventService.executeQuery(errorArchiveQuery).getEntityList();
// Assume error is first entry
EntityValue error = errors.get(0);
// Examine the error message from the OData producer
// From error messages, determined create has failed and need to remedy a specific property
// Load navigation proper AffectEntity
eventService.loadProperty(affectedEntityProp, error, null);
EntityValue entity = affectedEntityProp.getEntity(error);
Event eventInError = (Event)entity;
// update property in the event
eventInError.setType("PUBLIC_EVENT");
eventService.updateEntity(eventInError);
// Upload to retry. Merge algorithm will merge create and update to a single create
// with a new value for the Type property.
Fixing the properties of a failed PATCH request
A subsequent PATCH can be made to the entity with the corrected values. The merge heuristic combines both PATCH requests into a single new PATCH request containing the corrected values.
// Locate the event in error just as the example above. In this case, what is causing the error is the
// updateEntity has failed.
eventInError.setType("PUBLIC_EVENT");
eventService.updateEntity(eventInError);
// Upload to retry. Merge the two updates together to a single update
// with a new value for the Type property.
Discarding a failed POST request
A subsequent DELETE can be made to the entity. The merge heuristic deletes the original POST request and nothing is sent to the back end.
// The createEntity has failed // Locate the event in error just as the example above // Decided that get rid of the createEntity operation as the remedy eventService.deletEntity(eventInError); // Upload to retry. The delete will void the create
Fixing a PATCH or DELETE request that failed due to a stale ETag
The application can perform a refresh operation to refresh the fresh entity data and ETag. If appropriate, use only a subset of the defining requests that include entity type in error. If resubmitted without further changes, the merge heuristic replaces the stale ETag in the failed request with the fresh one. This will essentially apply what is local to the OData producer. In the event that the end users need to examine information from the OData producer to understand what has changed and adjust the current request accordingly, we will revert the error state after saving the existing value of the entity. Once reverted, local store will have the latest from the producer. The complication arises when there are other errors in the Error Archive. They need to be fixed first as deleting one entry in the Error Archive will result in all errors being reverted.
Fixing a DELETE request
When the deleteEntity fails because of current value for one or more its properties, it can be remedied by submitting an updateEntity. The merge algorithm will resequence the updateEntity to be executed ahead of the deleteEntity.
eventService.deleteEntity(event);
// Locally, it will work as it has no business logic
// Upload to OData producer will result in error
upload();
// Locate the entity in error state as (see earlier code fragments)
eventInError.setType("PUBLIC_EVENT_CLOSED");
eventService.updateEntity(eventInError);
If a deleteEntity operation results in an error and the remedy calls for its removal, the only way is to revert the error state is by deleting the entry from the Error Archive. This carries the same complication mentioned in previous section i.e. fixing other errors in the Error Archive.
Fixing a Non-Mergeable
Should a request that fails has a non-mergeable header, merging will not be applied. In this case and only in this case, we are to use the RequestEntity navigation property to remedy the error by patching the entity.
The RequestEntity navigation gives us the entity in the request queue. Hence, we are literally fixing the request itself. The local store will not have the latest until a download is completed. There is a limitation if the refresh is not performed. The Error Archive, even after a successful flush, will not be cleared. The corresponding request in the request queue will be marked as completed. After refresh, both will be cleared. Hence, it is recommended that a refresh be done to avoid misinterpreting the Error Archive in subsequent flushes.// Get the error from the Error Archive
EntityValue error = errors.get(0);
// Load navigation proper RequestEntityProp
eventService.loadProperty(requestEntityProp, error, null);
// Get the entity within the failed request
EntityValue entity = requestEntityProp.getEntity(error);
// Update the entity to remedy the failure
Event eventInRequest = (Event)entity;
eventInRequest.setType("PUBLIC_EVENT");
eventService.updateEntity(eventInRequest);
// Now we can trigger another upload to retry the fixed request