use of com.azure.cosmos.CosmosDiagnostics in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStart method createDatabaseIfNotExists.
// Database Diagnostics
private void createDatabaseIfNotExists() throws Exception {
logger.info("Creating database {} if not exists", databaseName);
// Create database if not exists
CosmosDatabaseResponse databaseResponse = client.createDatabaseIfNotExists(databaseName);
CosmosDiagnostics diagnostics = databaseResponse.getDiagnostics();
logger.info("Create database diagnostics : {}", diagnostics);
database = client.getDatabase(databaseResponse.getProperties().getId());
logger.info("Done.");
}
use of com.azure.cosmos.CosmosDiagnostics in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStart method readDocumentDoesntExist.
// Document read doesn't exist
private void readDocumentDoesntExist() throws Exception {
logger.info("Read document by ID : bad-ID");
// Read document by ID
try {
CosmosItemResponse<Family> familyCosmosItemResponse = container.readItem("bad-ID", new PartitionKey("bad-lastName"), Family.class);
} catch (CosmosException cosmosException) {
CosmosDiagnostics diagnostics = cosmosException.getDiagnostics();
logger.info("Read item exception diagnostics : {}", diagnostics);
}
logger.info("Done.");
}
use of com.azure.cosmos.CosmosDiagnostics in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStart method replaceDocument.
private void replaceDocument() throws Exception {
logger.info("Replace document : {}", documentId);
// Replace existing document with new modified document
Family family = new Family();
family.setLastName(documentLastName);
family.setId(documentId);
// Document modification
family.setDistrict("Columbia");
CosmosItemResponse<Family> itemResponse = container.replaceItem(family, family.getId(), new PartitionKey(family.getLastName()), new CosmosItemRequestOptions());
CosmosDiagnostics diagnostics = itemResponse.getDiagnostics();
logger.info("Replace item diagnostics : {}", diagnostics);
logger.info("Request charge of replace operation: {} RU", itemResponse.getRequestCharge());
logger.info("Done.");
}
use of com.azure.cosmos.CosmosDiagnostics in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStart method upsertDocument.
private void upsertDocument() throws Exception {
logger.info("Replace document : {}", documentId);
// Replace existing document with new modified document (contingent on modification).
Family family = new Family();
family.setLastName(documentLastName);
family.setId(documentId);
// Document modification
family.setDistrict("Columbia");
CosmosItemResponse<Family> itemResponse = container.upsertItem(family, new CosmosItemRequestOptions());
CosmosDiagnostics diagnostics = itemResponse.getDiagnostics();
logger.info("Upsert item diagnostics : {}", diagnostics);
logger.info("Done.");
}
use of com.azure.cosmos.CosmosDiagnostics 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.");
}
Aggregations