use of com.azure.cosmos.models.CosmosContainerResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class AutoscaleContainerCRUDQuickstart method createContainerIfNotExists.
// Container create
private void createContainerIfNotExists() throws Exception {
logger.info("Create autoscale container " + containerName + " if not exists.");
// Container and autoscale throughput settings
CosmosContainerProperties autoscaleContainerProperties = new CosmosContainerProperties(containerName, "/lastName");
// Set autoscale max RU/s
ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.createAutoscaledThroughput(4000);
// Create the container with autoscale enabled
CosmosContainerResponse databaseResponse = database.createContainer(autoscaleContainerProperties, autoscaleThroughputProperties, new CosmosContainerRequestOptions());
container = database.getContainer(databaseResponse.getProperties().getId());
logger.info("Done.");
}
use of com.azure.cosmos.models.CosmosContainerResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class DocumentCRUDQuickstart method createContainerIfNotExists.
// Container create
private void createContainerIfNotExists() throws Exception {
logger.info("Create container " + containerName + " if not exists.");
// Create container if not exists
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, "/lastName");
// Provision throughput
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
// Create container with 200 RU/s
CosmosContainerResponse containerResponse = database.createContainerIfNotExists(containerProperties, throughputProperties);
container = database.getContainer(containerResponse.getProperties().getId());
logger.info("Done.");
}
use of com.azure.cosmos.models.CosmosContainerResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStart method createContainerIfNotExists.
// Container create
private void createContainerIfNotExists() throws Exception {
logger.info("Creating container {} if not exists", containerName);
// Create container if not exists
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, "/lastName");
// Provision throughput
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
// Create container with 200 RU/s
CosmosContainerResponse containerResponse = database.createContainerIfNotExists(containerProperties, throughputProperties);
CosmosDiagnostics diagnostics = containerResponse.getDiagnostics();
logger.info("Create container diagnostics : {}", diagnostics);
container = database.getContainer(containerResponse.getProperties().getId());
logger.info("Done.");
}
use of com.azure.cosmos.models.CosmosContainerResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleSubpartitioningAsync method createContainerIfNotExists.
private void createContainerIfNotExists() throws Exception {
logger.info("Create container " + containerName + " if not exists.");
// Create container if not exists
// <Create PartitionKeyDefinition>
List<String> partitionKeyPaths = new ArrayList<String>();
partitionKeyPaths.add("/tenantId");
partitionKeyPaths.add("/userId");
partitionKeyPaths.add("/sessionId");
PartitionKeyDefinition subpartitionKeyDefinition = new PartitionKeyDefinition();
subpartitionKeyDefinition.setPaths(partitionKeyPaths);
subpartitionKeyDefinition.setKind(PartitionKind.MULTI_HASH);
subpartitionKeyDefinition.setVersion(PartitionKeyDefinitionVersion.V2);
// <CreateContainerIfNotExists>
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, subpartitionKeyDefinition);
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
Mono<CosmosContainerResponse> containerIfNotExists = database.createContainerIfNotExists(containerProperties, throughputProperties);
// Create container with 400 RU/s
CosmosContainerResponse cosmosContainerResponse = containerIfNotExists.block();
container = database.getContainer(cosmosContainerResponse.getProperties().getId());
// </CreateContainerIfNotExists>
// Modify existing container
containerProperties = cosmosContainerResponse.getProperties();
Mono<CosmosContainerResponse> propertiesReplace = container.replace(containerProperties, new CosmosContainerRequestOptions());
propertiesReplace.flatMap(containerResponse -> {
logger.info("setupContainer(): Container " + container.getId() + " in " + database.getId() + "has been updated with it's new properties.");
return Mono.empty();
}).onErrorResume((exception) -> {
logger.error("setupContainer(): Unable to update properties for container " + container.getId() + " in database " + database.getId() + ". e: " + exception.getLocalizedMessage());
return Mono.empty();
}).block();
}
use of com.azure.cosmos.models.CosmosContainerResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleCRUDQuickstart method createContainerIfNotExists.
private void createContainerIfNotExists() throws Exception {
logger.info("Create container " + containerName + " if not exists.");
// Create container if not exists
// <CreateContainerIfNotExists>
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, "/lastName");
// Create container with 400 RU/s
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
CosmosContainerResponse containerResponse = database.createContainerIfNotExists(containerProperties, throughputProperties);
container = database.getContainer(containerResponse.getProperties().getId());
// </CreateContainerIfNotExists>
logger.info("Checking container " + container.getId() + " completed!\n");
}
Aggregations