use of com.azure.cosmos.models.CosmosContainerProperties 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.models.CosmosContainerProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleIndexManagementAsync method createContainerIfNotExistsWithSpecifiedIndex.
private void createContainerIfNotExistsWithSpecifiedIndex() throws Exception {
logger.info("Create container " + containerName + " if not exists.");
// Create container if not exists
// <CreateContainerIfNotExists>
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, "/lastName");
// <CustomIndexingPolicy>
IndexingPolicy indexingPolicy = new IndexingPolicy();
// To turn indexing off set IndexingMode.NONE
indexingPolicy.setIndexingMode(IndexingMode.CONSISTENT);
// Included paths
List<IncludedPath> includedPaths = new ArrayList<>();
includedPaths.add(new IncludedPath("/*"));
indexingPolicy.setIncludedPaths(includedPaths);
// Excluded paths
List<ExcludedPath> excludedPaths = new ArrayList<>();
excludedPaths.add(new ExcludedPath("/name/*"));
indexingPolicy.setExcludedPaths(excludedPaths);
// Spatial indices - if you need them, here is how to set them up:
/*
List<SpatialSpec> spatialIndexes = new ArrayList<SpatialSpec>();
List<SpatialType> collectionOfSpatialTypes = new ArrayList<SpatialType>();
SpatialSpec spec = new SpatialSpec();
spec.setPath("/locations/*");
collectionOfSpatialTypes.add(SpatialType.Point);
spec.setSpatialTypes(collectionOfSpatialTypes);
spatialIndexes.add(spec);
indexingPolicy.setSpatialIndexes(spatialIndexes);
*/
// Composite indices - if you need them, here is how to set them up:
/*
List<List<CompositePath>> compositeIndexes = new ArrayList<>();
List<CompositePath> compositePaths = new ArrayList<>();
CompositePath nameCompositePath = new CompositePath();
nameCompositePath.setPath("/name");
nameCompositePath.setOrder(CompositePathSortOrder.ASCENDING);
CompositePath ageCompositePath = new CompositePath();
ageCompositePath.setPath("/age");
ageCompositePath.setOrder(CompositePathSortOrder.DESCENDING);
compositePaths.add(ageCompositePath);
compositePaths.add(nameCompositePath);
compositeIndexes.add(compositePaths);
indexingPolicy.setCompositeIndexes(compositeIndexes);
*/
containerProperties.setIndexingPolicy(indexingPolicy);
// </CustomIndexingPolicy>
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
Mono<CosmosContainerResponse> containerIfNotExists = database.createContainerIfNotExists(containerProperties, throughputProperties);
// Create container with 400 RU/s
containerIfNotExists.flatMap(containerResponse -> {
container = database.getContainer(containerResponse.getProperties().getId());
logger.info("Checking container " + container.getId() + " completed!\n");
return Mono.empty();
}).block();
// </CreateContainerIfNotExists>
}
use of com.azure.cosmos.models.CosmosContainerProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleIndexManagement method createContainerIfNotExistsWithSpecifiedIndex.
private void createContainerIfNotExistsWithSpecifiedIndex() throws Exception {
logger.info("Create container " + containerName + " if not exists.");
// Create container if not exists
CosmosContainerProperties containerProperties = new CosmosContainerProperties(containerName, "/lastName");
// <CustomIndexingPolicy>
IndexingPolicy indexingPolicy = new IndexingPolicy();
// To turn indexing off set IndexingMode.NONE
indexingPolicy.setIndexingMode(IndexingMode.CONSISTENT);
// Included paths
List<IncludedPath> includedPaths = new ArrayList<>();
includedPaths.add(new IncludedPath("/*"));
indexingPolicy.setIncludedPaths(includedPaths);
// Excluded paths
List<ExcludedPath> excludedPaths = new ArrayList<>();
excludedPaths.add(new ExcludedPath("/name/*"));
indexingPolicy.setExcludedPaths(excludedPaths);
// Spatial indices - if you need them, here is how to set them up:
/*
List<SpatialSpec> spatialIndexes = new ArrayList<SpatialSpec>();
List<SpatialType> collectionOfSpatialTypes = new ArrayList<SpatialType>();
SpatialSpec spec = new SpatialSpec();
spec.setPath("/locations/*");
collectionOfSpatialTypes.add(SpatialType.Point);
spec.setSpatialTypes(collectionOfSpatialTypes);
spatialIndexes.add(spec);
indexingPolicy.setSpatialIndexes(spatialIndexes);
*/
// Composite indices - if you need them, here is how to set them up:
/*
List<List<CompositePath>> compositeIndexes = new ArrayList<>();
List<CompositePath> compositePaths = new ArrayList<>();
CompositePath nameCompositePath = new CompositePath();
nameCompositePath.setPath("/name");
nameCompositePath.setOrder(CompositePathSortOrder.ASCENDING);
CompositePath ageCompositePath = new CompositePath();
ageCompositePath.setPath("/age");
ageCompositePath.setOrder(CompositePathSortOrder.DESCENDING);
compositePaths.add(ageCompositePath);
compositePaths.add(nameCompositePath);
compositeIndexes.add(compositePaths);
indexingPolicy.setCompositeIndexes(compositeIndexes);
*/
containerProperties.setIndexingPolicy(indexingPolicy);
// </CustomIndexingPolicy>
// Create container with 400 RU/s
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
CosmosContainerResponse containerResponse = database.createContainerIfNotExists(containerProperties, throughputProperties);
container = database.getContainer(containerResponse.getProperties().getId());
logger.info("Checking container " + container.getId() + " completed!\n");
}
use of com.azure.cosmos.models.CosmosContainerProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SamplePatchQuickstart method createContainerIfNotExists.
private void createContainerIfNotExists() throws Exception {
logger.info("Create container {} if not exists.", containerName);
// 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 {} completed!\n", container.getId());
}
use of com.azure.cosmos.models.CosmosContainerProperties in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class QueriesQuickstart 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.");
}
Aggregations