public interface CustomConflictResolver
Conflict arises when the data at the server has been changed after the data is downloaded by the client.
Upon each upload, the Server makes a get call to fetch the data corresponding to primary key being uploaded. It calculates the checksum out of the data and compares with the checksum of the to be uploaded data. If both have same checksum, then there is no conflict. If there is a checksum change then conflict is marked. Based on the action of client data and the action of server data, the corresponding method is called to handle particular conflict. For each conflict type, refer to method level comments.
The required information can be accessed from ConflictContext
and the
ConflictResolutionResult
has to be returned with proper actionType
and submitToServer.
The ActionType set for ConflictResolutionResult
should be the
supported operation on the object and should be acceptable on the current
state
If the implementation returns null ConflictResolutionResult then flow
continues as if there is no conflict. If conflictResolutionResult
submitToServer is false, then the server data and action is returned to
client, irrespective of what has been set in the conflictResult to ensure
proper replica of server data on client ConflictResolutionResult
if (conflictcontext.getObjectId().equals("categories")) { if (clientData.get("CategoryID").getAsInt() == 4) { JsonObject resolvedData = getResolvedData(serverData, conflictContext); conflictResult = new ConflictResolutionResult(resolvedData, ActionType.update, true); } else { if (clientData.get("CategoryID").getAsInt() == 3) { clientData.addProperty("CategoryName", serverData.get("CategoryName").getAsString()); } conflictResult = new ConflictResolutionResult(clientData, ActionType.update, true); } }
ConflictContext
,
ConflictResolutionResult
Modifier and Type | Method and Description |
---|---|
ConflictResolutionResult |
resolveClientCreateServerExists(com.google.gson.JsonObject clientData,
com.google.gson.JsonObject serverData,
ConflictContext conflictContext)
This method is used to represent the create conflict, i.e when client
creates and the record with same primary key exists on server.
|
ConflictResolutionResult |
resolveClientDeleteServerUpdate(com.google.gson.JsonObject clientData,
com.google.gson.JsonObject serverData,
ConflictContext conflictContext)
This method is used to represent the delete conflict, i.e when client
deletes and record with same primary key on server is updated.
|
ConflictResolutionResult |
resolveClientUpdateServerDelete(com.google.gson.JsonObject clientData,
com.google.gson.JsonObject serverData,
ConflictContext conflictContext)
This method is used to represent the update conflict with delete, i.e when
client update and record with same primary key on server is either soft
deleted or hard deleted.
|
ConflictResolutionResult |
resolveClientUpdateServerUpdate(com.google.gson.JsonObject clientData,
com.google.gson.JsonObject serverData,
ConflictContext conflictContext)
This method is used to represent the update conflict, i.e when client
update and record with same primary key on server is updated post download.
|
ConflictResolutionResult resolveClientCreateServerExists(com.google.gson.JsonObject clientData, com.google.gson.JsonObject serverData, ConflictContext conflictContext)
clientData
- Holds the data from client sideserverData
- Holds the data from server sideconflictContext
- Holds the accessible meta informationConflictResolutionResult resolveClientUpdateServerUpdate(com.google.gson.JsonObject clientData, com.google.gson.JsonObject serverData, ConflictContext conflictContext)
clientData
- Holds the data from client sideserverData
- Holds the data from server sideconflictContext
- Holds the accessible meta informationConflictResolutionResult resolveClientUpdateServerDelete(com.google.gson.JsonObject clientData, com.google.gson.JsonObject serverData, ConflictContext conflictContext)
clientData
- Holds the data from client sideserverData
- Holds the data from server sideconflictContext
- Holds the accessible meta informationConflictResolutionResult resolveClientDeleteServerUpdate(com.google.gson.JsonObject clientData, com.google.gson.JsonObject serverData, ConflictContext conflictContext)
clientData
- Holds the data from client sideserverData
- Holds the data from server sideconflictContext
- Holds the accessible meta informationCopyright © 2019. All rights reserved.