共用方式為


ConflictResolutionPolicy Class

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.

DocumentCollection collectionSpec = new DocumentCollection();
 collectionSpec.setId("Multi-master collection");

 ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy();
 collectionSpec.setConflictResolutionPolicy(policy);

 DocumentCollection collection = client.createCollection(databaseLink, collectionSpec, null)
         .toBlocking().single().getResource();

A collection with custom conflict resolution with a user-registered stored procedure.

DocumentCollection collectionSpec = new DocumentCollection();
 collectionSpec.setId("Multi-master collection");

 ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy(conflictResolutionSprocName);
 collectionSpec.setConflictResolutionPolicy(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.setId("Multi-master collection");

 ConflictResolutionPolicy policy = ConflictResolutionPolicy.createLastWriterWinsPolicy("/path/for/conflict/resolution");
 collectionSpec.setConflictResolutionPolicy(policy);

 DocumentCollection collection = client.createCollection(databaseLink, collectionSpec, null)
         .toBlocking().single().getResource();

Constructor Summary

Constructor Description
ConflictResolutionPolicy()

Initializes a new instance of the ConflictResolutionPolicy class for the Azure Cosmos DB service.

ConflictResolutionPolicy(String jsonString)

Method Summary

Modifier and Type Method and Description
static ConflictResolutionPolicy createCustomPolicy(String sprocLink)

Creates a Custom conflict resolution policy.

static ConflictResolutionPolicy createLastWriterWinsPolicy()

Creates a LastWriterWins conflict resolution policy.

static ConflictResolutionPolicy createLastWriterWinsPolicy(String path)

Creates a LastWriterWins conflict resolution policy.

ConflictResolutionMode getConflictResolutionMode()

Gets the ConflictResolutionMode in the Azure Cosmos DB service.

java.lang.String getConflictResolutionPath()

Gets the path which is present in each document in the Azure Cosmos DB service for last writer wins conflict-resolution.

java.lang.String getConflictResolutionProcedure()

Gets the StoredProcedure which is used for conflict resolution in the Azure Cosmos DB service.

Methods inherited from JsonSerializable

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

ConflictResolutionPolicy

public ConflictResolutionPolicy()

Initializes a new instance of the ConflictResolutionPolicy class for the Azure Cosmos DB service.

ConflictResolutionPolicy

public ConflictResolutionPolicy(String jsonString)

Parameters:

jsonString

Method Details

createCustomPolicy

public static ConflictResolutionPolicy createCustomPolicy(String sprocLink)

Creates a Custom conflict resolution policy. The Conflict resolution mode is set to Custom. Sets the StoredProcedure which is used for conflict resolution in the Azure Cosmos DB service. This stored procedure may be created after the DocumentCollection 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 getId()

Parameters:

sprocLink - The link to the stored procedure to perform conflict resolution.

Returns:

policy the Custom conflict resolution policy

createLastWriterWinsPolicy

public static ConflictResolutionPolicy createLastWriterWinsPolicy()

Creates a LastWriterWins conflict resolution policy. The Conflict resolution mode is set to LastWriterWins. The getTimestamp() path will be used for last writer wins conflict-resolution. In case of a conflict occurring on a document, the document with the higher timestamp value wins.

Returns:

policy the LastWriterWins conflict resolution policy

createLastWriterWinsPolicy

public static ConflictResolutionPolicy createLastWriterWinsPolicy(String path)

Creates a LastWriterWins conflict resolution policy. The Conflict resolution mode is set to LastWriterWins. The path which is present in each document in the Azure Cosmos DB service is used 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.

Parameters:

path - 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:

policy the LastWriterWins conflict resolution policy

getConflictResolutionMode

public ConflictResolutionMode getConflictResolutionMode()

Gets the ConflictResolutionMode in the Azure Cosmos DB service. By default it is LastWriterWins.

Returns:

ConflictResolutionMode.

getConflictResolutionPath

public String getConflictResolutionPath()

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 the getTimestamp() path will be used. This value should only be set when using LastWriterWins

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".

getConflictResolutionProcedure

public String getConflictResolutionProcedure()

Gets the StoredProcedure which is used for conflict resolution in the Azure Cosmos DB service. This stored procedure may be created after the DocumentCollection is created and can be changed as required.

  • This value should only be set when using 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 getId()

Returns:

the stored procedure to perform conflict resolution.]

Applies to