Search in sources :

Example 11 with CosmosAsyncDatabase

use of com.azure.cosmos.CosmosAsyncDatabase 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 12 with CosmosAsyncDatabase

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

the class SalesOrder method MigrateJavaSDKv4ItemTTLAsync.

/**
 * https://docs.microsoft.com/en-us/azure/cosmos-db/migrate-java-v4-sdk
 * Item TTL
 */
/**
 * Item TTL
 */
public static void MigrateJavaSDKv4ItemTTLAsync() {
    String hostName = "hostname";
    String partition_key = "/pk";
    CosmosAsyncDatabase database = null;
    // <MigrateItemTTLAsync>
    // Set the value to the expiration in seconds
    SalesOrder salesOrder = new SalesOrder("SO05", "CO18009186470", // Expire sales orders in 30 days
    60 * 60 * 24 * 30);
// </MigrateItemTTLAsync>
}
Also used : CosmosAsyncDatabase(com.azure.cosmos.CosmosAsyncDatabase)

Aggregations

CosmosAsyncDatabase (com.azure.cosmos.CosmosAsyncDatabase)12 CosmosContainerProperties (com.azure.cosmos.models.CosmosContainerProperties)10 CosmosAsyncContainer (com.azure.cosmos.CosmosAsyncContainer)8 ThroughputProperties (com.azure.cosmos.models.ThroughputProperties)7 ConflictResolutionPolicy (com.azure.cosmos.models.ConflictResolutionPolicy)5 CosmosAsyncClient (com.azure.cosmos.CosmosAsyncClient)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ChangeFeedProcessor (com.azure.cosmos.ChangeFeedProcessor)3 ChangeFeedProcessorBuilder (com.azure.cosmos.ChangeFeedProcessorBuilder)3 ConsistencyLevel (com.azure.cosmos.ConsistencyLevel)3 CosmosClientBuilder (com.azure.cosmos.CosmosClientBuilder)3 CosmosException (com.azure.cosmos.CosmosException)3 CosmosContainerRequestOptions (com.azure.cosmos.models.CosmosContainerRequestOptions)3 CosmosContainerResponse (com.azure.cosmos.models.CosmosContainerResponse)3 ExcludedPath (com.azure.cosmos.models.ExcludedPath)3 IncludedPath (com.azure.cosmos.models.IncludedPath)3 IndexingPolicy (com.azure.cosmos.models.IndexingPolicy)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Duration (java.time.Duration)3