Search in sources :

Example 1 with ConflictResolutionPolicy

use of com.azure.cosmos.models.ConflictResolutionPolicy in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SalesOrder method ManageConflictResolutionPoliciesInAzureCosmosDBCustomAsync.

/**
 * https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-manage-conflicts
 * Resolve conflicts, stored procedure
 */
/**
 * Client-side conflict resolution with fully custom policy
 */
public static void ManageConflictResolutionPoliciesInAzureCosmosDBCustomAsync() {
    String container_id = "family_container";
    String partition_key = "/pk";
    CosmosAsyncDatabase database = null;
    // <ManageConflictResolutionCustomAsync>
    ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy();
    CosmosContainerProperties containerProperties = new CosmosContainerProperties(container_id, partition_key);
    containerProperties.setConflictResolutionPolicy(policy);
    /* ...other container config... */
    database.createContainerIfNotExists(containerProperties).block();
// </ManageConflictResolutionCustomAsync>
}
Also used : CosmosAsyncDatabase(com.azure.cosmos.CosmosAsyncDatabase) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) ConflictResolutionPolicy(com.azure.cosmos.models.ConflictResolutionPolicy)

Example 2 with ConflictResolutionPolicy

use of com.azure.cosmos.models.ConflictResolutionPolicy in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SalesOrder method ManageConflictResolutionPoliciesInAzureCosmosDBLWWAsync.

/**
 * https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-manage-conflicts
 * Resolve conflicts, LWW policy
 */
/**
 * Client-side conflict resolution settings for LWW policy
 */
public static void ManageConflictResolutionPoliciesInAzureCosmosDBLWWAsync() {
    String container_id = "family_container";
    String partition_key = "/pk";
    CosmosAsyncDatabase database = null;
    // <ManageConflictResolutionLWWAsync>
    ConflictResolutionPolicy policy = ConflictResolutionPolicy.createLastWriterWinsPolicy("/myCustomId");
    CosmosContainerProperties containerProperties = new CosmosContainerProperties(container_id, partition_key);
    containerProperties.setConflictResolutionPolicy(policy);
    /* ...other container config... */
    database.createContainerIfNotExists(containerProperties).block();
// </ManageConflictResolutionLWWAsync>
}
Also used : CosmosAsyncDatabase(com.azure.cosmos.CosmosAsyncDatabase) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) ConflictResolutionPolicy(com.azure.cosmos.models.ConflictResolutionPolicy)

Example 3 with ConflictResolutionPolicy

use of com.azure.cosmos.models.ConflictResolutionPolicy in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SalesOrder method ManageConflictResolutionPoliciesInAzureCosmosDBSprocAsync.

/**
 * https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-manage-conflicts
 * Resolve conflicts, stored procedure
 */
/**
 * Client-side conflict resolution using stored procedure
 */
public static void ManageConflictResolutionPoliciesInAzureCosmosDBSprocAsync() {
    String container_id = "family_container";
    String partition_key = "/pk";
    CosmosAsyncDatabase database = null;
    // <ManageConflictResolutionSprocAsync>
    ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy("resolver");
    CosmosContainerProperties containerProperties = new CosmosContainerProperties(container_id, partition_key);
    containerProperties.setConflictResolutionPolicy(policy);
    /* ...other container config... */
    database.createContainerIfNotExists(containerProperties).block();
// </ManageConflictResolutionSprocAsync>
}
Also used : CosmosAsyncDatabase(com.azure.cosmos.CosmosAsyncDatabase) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) ConflictResolutionPolicy(com.azure.cosmos.models.ConflictResolutionPolicy)

Example 4 with ConflictResolutionPolicy

use of com.azure.cosmos.models.ConflictResolutionPolicy in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SampleDocumentationSnippets method ManageConflictResolutionPoliciesInAzureCosmosDBLWWSync.

/**
 * https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-manage-conflicts
 * Resolve conflicts, LWW policy
 */
/**
 * Client-side conflict resolution settings for LWW policy
 */
public static void ManageConflictResolutionPoliciesInAzureCosmosDBLWWSync() {
    String container_id = "family_container";
    String partition_key = "/pk";
    CosmosDatabase database = null;
    // <ManageConflictResolutionLWWSync>
    ConflictResolutionPolicy policy = ConflictResolutionPolicy.createLastWriterWinsPolicy("/myCustomId");
    CosmosContainerProperties containerProperties = new CosmosContainerProperties(container_id, partition_key);
    containerProperties.setConflictResolutionPolicy(policy);
    /* ...other container config... */
    database.createContainerIfNotExists(containerProperties);
// </ManageConflictResolutionLWWSync>
}
Also used : CosmosDatabase(com.azure.cosmos.CosmosDatabase) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) ConflictResolutionPolicy(com.azure.cosmos.models.ConflictResolutionPolicy)

Example 5 with ConflictResolutionPolicy

use of com.azure.cosmos.models.ConflictResolutionPolicy in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SampleDocumentationSnippets method ManageConflictResolutionPoliciesInAzureCosmosDBCustomSync.

/**
 * https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-manage-conflicts
 * Resolve conflicts, stored procedure
 */
/**
 * Client-side conflict resolution with fully custom policy
 */
public static void ManageConflictResolutionPoliciesInAzureCosmosDBCustomSync() {
    String container_id = "family_container";
    String partition_key = "/pk";
    CosmosDatabase database = null;
    // <ManageConflictResolutionCustomSync>
    ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy();
    CosmosContainerProperties containerProperties = new CosmosContainerProperties(container_id, partition_key);
    containerProperties.setConflictResolutionPolicy(policy);
    /* ...other container config... */
    database.createContainerIfNotExists(containerProperties);
// </ManageConflictResolutionCustomSync>
}
Also used : CosmosDatabase(com.azure.cosmos.CosmosDatabase) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) ConflictResolutionPolicy(com.azure.cosmos.models.ConflictResolutionPolicy)

Aggregations

ConflictResolutionPolicy (com.azure.cosmos.models.ConflictResolutionPolicy)6 CosmosContainerProperties (com.azure.cosmos.models.CosmosContainerProperties)6 CosmosAsyncDatabase (com.azure.cosmos.CosmosAsyncDatabase)3 CosmosDatabase (com.azure.cosmos.CosmosDatabase)3