Package com.azure.data.cosmos
Class ConflictResolutionPolicy
- java.lang.Object
-
- com.azure.data.cosmos.JsonSerializable
-
- com.azure.data.cosmos.ConflictResolutionPolicy
-
public class ConflictResolutionPolicy extends JsonSerializable
Represents the conflict resolution policy configuration for specifying how to resolve conflicts in case writes from different regions result in conflicts on documents in the collection in the Azure Cosmos DB service. A collection with custom conflict resolution with no user-registered stored procedure.
A collection with custom conflict resolution with a user-registered stored procedure.DocumentCollection collectionSpec = new DocumentCollection(); collectionSpec.id("Multi-master collection"); ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy(); collectionSpec.conflictResolutionPolicy(policy); DocumentCollection collection = client.createCollection(databaseLink, collectionSpec, null) .toBlocking().single().getResource();
A collection with last writer wins conflict resolution, based on a path in the conflicting documents. A collection with custom conflict resolution with a user-registered stored procedure.DocumentCollection collectionSpec = new DocumentCollection(); collectionSpec.id("Multi-master collection"); ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy(conflictResolutionSprocName); collectionSpec.conflictResolutionPolicy(policy); DocumentCollection collection = client.createCollection(databaseLink, collectionSpec, null) .toBlocking().single().getResource();
DocumentCollection collectionSpec = new DocumentCollection(); collectionSpec.id("Multi-master collection"); ConflictResolutionPolicy policy = ConflictResolutionPolicy.createLastWriterWinsPolicy("/path/for/conflict/resolution"); collectionSpec.conflictResolutionPolicy(policy); DocumentCollection collection = client.createCollection(databaseLink, collectionSpec, null) .toBlocking().single().getResource();
-
-
Constructor Summary
Constructors Constructor Description ConflictResolutionPolicy(String jsonString)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
conflictResolutionPath()
Gets the path which is present in each document in the Azure Cosmos DB service for last writer wins conflict-resolution.String
conflictResolutionProcedure()
Gets theStoredProcedure
which is used for conflict resolution in the Azure Cosmos DB service.static ConflictResolutionPolicy
createCustomPolicy()
Creates a CUSTOMConflictResolutionPolicy
without anyStoredProcedure
.static ConflictResolutionPolicy
createCustomPolicy(String conflictResolutionSprocName)
Creates a CUSTOMConflictResolutionPolicy
which uses the specified stored procedure to perform conflict resolution This stored procedure may be created after theDocumentCollection
is created and can be changed as required.static ConflictResolutionPolicy
createLastWriterWinsPolicy()
Creates a LAST_WRITER_WINSConflictResolutionPolicy
with "/_ts" as the resolution path.static ConflictResolutionPolicy
createLastWriterWinsPolicy(String conflictResolutionPath)
Creates a LAST_WRITER_WINSConflictResolutionPolicy
with path as the resolution path.ConflictResolutionMode
mode()
Gets theConflictResolutionMode
in the Azure Cosmos DB service.-
Methods inherited from class com.azure.data.cosmos.JsonSerializable
get, getBoolean, getCollection, getDouble, getInt, getList, getLogger, getLong, getMap, getObject, getObjectByPath, getString, has, toJson, toJson, toObject, toString
-
-
-
-
Constructor Detail
-
ConflictResolutionPolicy
public ConflictResolutionPolicy(String jsonString)
-
-
Method Detail
-
createLastWriterWinsPolicy
public static ConflictResolutionPolicy createLastWriterWinsPolicy()
Creates a LAST_WRITER_WINSConflictResolutionPolicy
with "/_ts" as the resolution path. In case of a conflict occurring on a document, the document with the higher integer value in the default pathResource.timestamp()
, i.e., "/_ts" will be used.- Returns:
- ConflictResolutionPolicy.
-
createLastWriterWinsPolicy
public static ConflictResolutionPolicy createLastWriterWinsPolicy(String conflictResolutionPath)
Creates a LAST_WRITER_WINSConflictResolutionPolicy
with path as the resolution path. The specified path must be present in each document and must be an integer value. In case of a conflict occurring on a document, the document with the higher integer value in the specified path will be picked.- Parameters:
conflictResolutionPath
- The path to check values for last-writer wins conflict resolution. That path is a rooted path of the property in the document, such as "/name/first".- Returns:
- ConflictResolutionPolicy.
-
createCustomPolicy
public static ConflictResolutionPolicy createCustomPolicy(String conflictResolutionSprocName)
Creates a CUSTOMConflictResolutionPolicy
which uses the specified stored procedure to perform conflict resolution This stored procedure may be created after theDocumentCollection
is created and can be changed as required.- In case the stored procedure fails or throws an exception, the conflict resolution will default to registering conflicts in the conflicts feed
- The user can provide the stored procedure @see
Resource.id()
- Parameters:
conflictResolutionSprocName
- stored procedure to perform conflict resolution.- Returns:
- ConflictResolutionPolicy.
-
createCustomPolicy
public static ConflictResolutionPolicy createCustomPolicy()
Creates a CUSTOMConflictResolutionPolicy
without anyStoredProcedure
. User manually should resolve conflicts. The conflicts will be registered in the conflicts feed and the user should manually resolve them.- Returns:
- ConflictResolutionPolicy.
-
mode
public ConflictResolutionMode mode()
Gets theConflictResolutionMode
in the Azure Cosmos DB service. By default it isConflictResolutionMode.LAST_WRITER_WINS
.- Returns:
- ConflictResolutionMode.
-
conflictResolutionPath
public String conflictResolutionPath()
Gets the path which is present in each document in the Azure Cosmos DB service for last writer wins conflict-resolution. This path must be present in each document and must be an integer value. In case of a conflict occurring on a document, the document with the higher integer value in the specified path will be picked. If the path is unspecified, by default theResource.timestamp()
path will be used. This value should only be set when usingConflictResolutionMode.LAST_WRITER_WINS
- Returns:
- The path to check values for last-writer wins conflict resolution. That path is a rooted path of the property in the document, such as "/name/first".
-
conflictResolutionProcedure
public String conflictResolutionProcedure()
Gets theStoredProcedure
which is used for conflict resolution in the Azure Cosmos DB service. This stored procedure may be created after theDocumentCollection
is created and can be changed as required.- This value should only be set when using
ConflictResolutionMode.CUSTOM
- In case the stored procedure fails or throws an exception, the conflict resolution will default to registering conflicts in the conflicts feed
- The user can provide the stored procedure @see
Resource.id()
- Returns:
- the stored procedure to perform conflict resolution.]
- This value should only be set when using
-
-