Class ConflictResolutionPolicy
A container with custom conflict resolution with no user-registered stored procedure.
CosmosContainerProperties containerProperties =
new CosmosContainerProperties("Multi-master container", "Multi-master container partition key");
containerProperties.setConflictResolutionPolicy(ConflictResolutionPolicy.createCustomPolicy());
CosmosAsyncDatabase database = client.createDatabase(databaseProperties).block().getDatabase();
CosmosAsyncContainer container = database.createContainer(containerProperties).block().getContainer();
A container with custom conflict resolution with a user-registered stored procedure.
CosmosContainerProperties containerProperties =
new CosmosContainerProperties("Multi-master container", "Multi-master container partition key");
ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy(conflictResolutionSprocName);
containerProperties.setConflictResolutionPolicy(policy);
CosmosAsyncDatabase database = client.createDatabase(databaseProperties).block().getDatabase();
CosmosAsyncContainer container = database.createContainer(containerProperties).block().getContainer();
A container with last writer wins conflict resolution, based on a path in the conflicting items. A container with custom conflict resolution with a user-registered stored procedure.
CosmosContainerProperties containerProperties =
new CosmosContainerProperties("Multi-master container", "Multi-master container partition key");
ConflictResolutionPolicy policy = ConflictResolutionPolicy.createLastWriterWinsPolicy("/path/for/conflict/resolution");
containerProperties.setConflictResolutionPolicy(policy);
CosmosAsyncDatabase database = client.createDatabase(databaseProperties).block().getDatabase();
CosmosAsyncContainer container = database.createContainer(containerProperties).block().getContainer();
-
Method Summary
Modifier and TypeMethodDescriptionstatic ConflictResolutionPolicyCreates a CUSTOMConflictResolutionPolicywithout anyStoredProcedure.static ConflictResolutionPolicycreateCustomPolicy(String conflictResolutionStoredProcFullPath) Creates a CUSTOMConflictResolutionPolicywhich uses the specified stored procedure to perform conflict resolutionstatic ConflictResolutionPolicycreateCustomPolicy(String dbName, String containerName, String sprocName) Creates a CUSTOMConflictResolutionPolicywhich uses the specified stored procedure to perform conflict resolutionstatic ConflictResolutionPolicyCreates a LAST_WRITER_WINSConflictResolutionPolicywith "/_ts" as the resolution path.static ConflictResolutionPolicycreateLastWriterWinsPolicy(String conflictResolutionPath) Creates a LAST_WRITER_WINSConflictResolutionPolicywith path as the resolution path.Gets the path which is present in each item in the Azure Cosmos DB service for last writer wins conflict-resolution.Gets theStoredProcedurewhich is used for conflict resolution in the Azure Cosmos DB service.getMode()Gets theConflictResolutionModein the Azure Cosmos DB service.
-
Method Details
-
createLastWriterWinsPolicy
Creates a LAST_WRITER_WINSConflictResolutionPolicywith "/_ts" as the resolution path.In case of a conflict occurring on an item, the item with the higher integer value in the default path
Resource.getTimestamp()()}, i.e., "/_ts" will be used.Resource.getTimestamp(), i.e., "/_ts" will be used.- Returns:
- ConflictResolutionPolicy.
-
createLastWriterWinsPolicy
Creates a LAST_WRITER_WINSConflictResolutionPolicywith path as the resolution path.The specified path must be present in each item and must be an integer value. In case of a conflict occurring on an item, the item 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 item, such as "/name/first".- Returns:
- ConflictResolutionPolicy.
-
createCustomPolicy
public static ConflictResolutionPolicy createCustomPolicy(String conflictResolutionStoredProcFullPath) Creates a CUSTOMConflictResolutionPolicywhich uses the specified stored procedure to perform conflict resolutionThis stored procedure may be created after the
CosmosContainerPropertiesis created and can be changed as required.- This method requires conflictResolutionStoredProcFullPath in format
dbs/%s/colls/%s/sprocs/%s. User can also use equivalent method
createCustomPolicy(String, String, String) - 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.getId()
- Parameters:
conflictResolutionStoredProcFullPath- stored procedure full path to perform conflict resolution.- Returns:
- ConflictResolutionPolicy.
- This method requires conflictResolutionStoredProcFullPath in format
dbs/%s/colls/%s/sprocs/%s. User can also use equivalent method
-
createCustomPolicy
public static ConflictResolutionPolicy createCustomPolicy(String dbName, String containerName, String sprocName) Creates a CUSTOMConflictResolutionPolicywhich uses the specified stored procedure to perform conflict resolutionThis stored procedure may be created after the
CosmosContainerPropertiesis 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.getId()
- Parameters:
dbName- database name.containerName- container name.sprocName- stored procedure name to perform conflict resolution.- Returns:
- ConflictResolutionPolicy.
-
createCustomPolicy
Creates a CUSTOMConflictResolutionPolicywithout anyStoredProcedure. User manually should resolve conflicts.The conflicts will be registered in the conflicts feed and the user should manually resolve them.
- Returns:
- ConflictResolutionPolicy.
-
getMode
Gets theConflictResolutionModein the Azure Cosmos DB service. By default it isConflictResolutionMode.LAST_WRITER_WINS.- Returns:
- ConflictResolutionMode.
-
getConflictResolutionPath
Gets the path which is present in each item in the Azure Cosmos DB service for last writer wins conflict-resolution. This path must be present in each item and must be an integer value. In case of a conflict occurring on an item, the item with the higher integer value in the specified path will be picked. If the path is unspecified, by default theResource.getTimestamp()()} path will be used.This value should only be set when using
ConflictResolutionMode.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 item, such as "/name/first".
-
getConflictResolutionProcedure
Gets theStoredProcedurewhich is used for conflict resolution in the Azure Cosmos DB service. This stored procedure may be created after theCosmosContainerPropertiesis 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.getId()()}
- Returns:
- the stored procedure to perform conflict resolution.]
- This value should only be set when using
-