use of com.azure.cosmos.models.CosmosContainerResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleChangeFeedProcessor method createNewLeaseCollection.
public static CosmosAsyncContainer createNewLeaseCollection(CosmosAsyncClient client, String databaseName, String leaseCollectionName) {
CosmosAsyncDatabase databaseLink = client.getDatabase(databaseName);
CosmosAsyncContainer leaseCollectionLink = databaseLink.getContainer(leaseCollectionName);
CosmosContainerResponse leaseContainerResponse = null;
try {
leaseContainerResponse = leaseCollectionLink.read().block();
if (leaseContainerResponse != null) {
leaseCollectionLink.delete().block();
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
} catch (RuntimeException ex) {
if (ex instanceof CosmosException) {
CosmosException CosmosException = (CosmosException) ex;
if (CosmosException.getStatusCode() != 404) {
throw ex;
}
} else {
throw ex;
}
}
CosmosContainerProperties containerSettings = new CosmosContainerProperties(leaseCollectionName, "/id");
CosmosContainerRequestOptions requestOptions = new CosmosContainerRequestOptions();
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
leaseContainerResponse = databaseLink.createContainer(containerSettings, throughputProperties, requestOptions).block();
if (leaseContainerResponse == null) {
throw new RuntimeException(String.format("Failed to create collection %s in database %s.", leaseCollectionName, databaseName));
}
return databaseLink.getContainer(leaseContainerResponse.getProperties().getId());
}
use of com.azure.cosmos.models.CosmosContainerResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleChangeFeedProcessor method createNewCollection.
public static CosmosAsyncContainer createNewCollection(CosmosAsyncClient client, String databaseName, String collectionName) {
CosmosAsyncDatabase databaseLink = client.getDatabase(databaseName);
CosmosAsyncContainer collectionLink = databaseLink.getContainer(collectionName);
CosmosContainerResponse containerResponse = null;
try {
containerResponse = collectionLink.read().block();
if (containerResponse != null) {
throw new IllegalArgumentException(String.format("Collection %s already exists in database %s.", collectionName, databaseName));
}
} catch (RuntimeException ex) {
if (ex instanceof CosmosException) {
CosmosException CosmosException = (CosmosException) ex;
if (CosmosException.getStatusCode() != 404) {
throw ex;
}
} else {
throw ex;
}
}
CosmosContainerProperties containerSettings = new CosmosContainerProperties(collectionName, "/pk");
CosmosContainerRequestOptions requestOptions = new CosmosContainerRequestOptions();
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(10000);
containerResponse = databaseLink.createContainer(containerSettings, throughputProperties, requestOptions).block();
if (containerResponse == null) {
throw new RuntimeException(String.format("Failed to create collection %s in database %s.", collectionName, databaseName));
}
return databaseLink.getContainer(containerResponse.getProperties().getId());
}
use of com.azure.cosmos.models.CosmosContainerResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class AnalyticalContainerCRUDQuickstart method deleteAContainer.
// Container delete
private void deleteAContainer() throws Exception {
logger.info("Delete container " + containerName + " by ID.");
// Delete container
CosmosContainerResponse containerResp = database.getContainer(containerName).delete(new CosmosContainerRequestOptions());
logger.info("Status code for container delete: {}", containerResp.getStatusCode());
logger.info("Done.");
}
use of com.azure.cosmos.models.CosmosContainerResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class AnalyticalContainerCRUDQuickstart 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");
// Set analytical store properties
containerProperties.setAnalyticalStoreTimeToLiveInSeconds(-1);
// Create container
CosmosContainerResponse databaseResponse = database.createContainerIfNotExists(containerProperties);
CosmosContainer 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 AutoscaleContainerCRUDQuickstart method deleteAContainer.
// Container delete
private void deleteAContainer() throws Exception {
logger.info("Delete container " + containerName + " by ID.");
// Delete container
CosmosContainerResponse containerResp = database.getContainer(containerName).delete(new CosmosContainerRequestOptions());
logger.info("Status code for container delete: {}", containerResp.getStatusCode());
logger.info("Done.");
}
Aggregations