use of com.azure.cosmos.CosmosDiagnostics in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStartAsync 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");
Mono<CosmosItemResponse<Family>> itemResponseMono = container.replaceItem(family, family.getId(), new PartitionKey(family.getLastName()), new CosmosItemRequestOptions());
CosmosItemResponse<Family> itemResponse = itemResponseMono.block();
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 CosmosDiagnosticsQuickStartAsync 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");
Mono<CosmosItemResponse<Family>> itemResponseMono = container.upsertItem(family, new CosmosItemRequestOptions());
CosmosItemResponse<Family> itemResponse = itemResponseMono.block();
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 CosmosDiagnosticsQuickStartAsync method deleteDocument.
// Document delete
private void deleteDocument() throws Exception {
logger.info("Delete document by ID {}", documentId);
// Delete document
Mono<CosmosItemResponse<Object>> itemResponseMono = container.deleteItem(documentId, new PartitionKey(documentLastName), new CosmosItemRequestOptions());
CosmosItemResponse<Object> itemResponse = itemResponseMono.block();
CosmosDiagnostics diagnostics = itemResponse.getDiagnostics();
logger.info("Delete 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 CosmosDiagnosticsQuickStartAsync method createDocument.
private void createDocument() throws Exception {
logger.info("Create document : {}", documentId);
// Define a document as a POJO (internally this
// is converted to JSON via custom serialization)
Family family = new Family();
family.setLastName(documentLastName);
family.setId(documentId);
// Insert this item as a document
// Explicitly specifying the /pk value improves performance.
Mono<CosmosItemResponse<Family>> itemResponseMono = container.createItem(family, new PartitionKey(family.getLastName()), new CosmosItemRequestOptions());
CosmosItemResponse<Family> itemResponse = itemResponseMono.block();
CosmosDiagnostics diagnostics = itemResponse.getDiagnostics();
logger.info("Create 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 CosmosDiagnosticsQuickStartAsync 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
Mono<CosmosContainerResponse> containerResponseMono = database.createContainerIfNotExists(containerProperties, throughputProperties);
CosmosContainerResponse cosmosContainerResponse = containerResponseMono.block();
CosmosDiagnostics diagnostics = cosmosContainerResponse.getDiagnostics();
logger.info("Create container diagnostics : {}", diagnostics);
container = database.getContainer(cosmosContainerResponse.getProperties().getId());
logger.info("Done.");
}
Aggregations