use of com.azure.cosmos.CosmosDatabase 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>
}
use of com.azure.cosmos.CosmosDatabase in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleDocumentationSnippets method ManageConflictResolutionPoliciesInAzureCosmosDBSprocSync.
/**
* 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 ManageConflictResolutionPoliciesInAzureCosmosDBSprocSync() {
String container_id = "family_container";
String partition_key = "/pk";
CosmosDatabase database = null;
// <ManageConflictResolutionSprocSync>
ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy("resolver");
CosmosContainerProperties containerProperties = new CosmosContainerProperties(container_id, partition_key);
containerProperties.setConflictResolutionPolicy(policy);
/* ...other container config... */
database.createContainerIfNotExists(containerProperties);
// </ManageConflictResolutionSprocSync>
}
use of com.azure.cosmos.CosmosDatabase in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosDbApiImpl method getContainer.
private static CosmosContainer getContainer(Vault vault, AbstractCosmosConfig config) {
CosmosClient client = createClient(vault, config.getAccountName(), Collections.singletonList(config.getPreferredRegion()));
CosmosDatabase database = getDatabase(client, config.getDbName());
if (database.readAllContainers().stream().noneMatch(sp -> sp.getId().equals(config.getContainerName()))) {
throw new EdcException("No CosmosDB container named '" + config.getContainerName() + "' was found in account '" + config.getAccountName() + "'. Please create one, preferably using terraform.");
}
return database.getContainer(config.getContainerName());
}
Aggregations