use of com.azure.cosmos.CosmosDiagnostics in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStartAsync method readDocumentById.
// Document read
private void readDocumentById() throws Exception {
logger.info("Read document by ID : {}", documentId);
// Read document by ID
Mono<CosmosItemResponse<Family>> itemResponseMono = container.readItem(documentId, new PartitionKey(documentLastName), Family.class);
CosmosItemResponse<Family> familyCosmosItemResponse = itemResponseMono.block();
CosmosDiagnostics diagnostics = familyCosmosItemResponse.getDiagnostics();
logger.info("Read item diagnostics : {}", diagnostics);
Family family = familyCosmosItemResponse.getItem();
// Check result
logger.info("Finished reading family {} with partition key {}", family.getId(), family.getLastName());
logger.info("Done.");
}
use of com.azure.cosmos.CosmosDiagnostics in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStartAsync method createDatabaseIfNotExists.
// Database Diagnostics
private void createDatabaseIfNotExists() throws Exception {
logger.info("Creating database {} if not exists", databaseName);
// Create database if not exists
Mono<CosmosDatabaseResponse> databaseResponseMono = client.createDatabaseIfNotExists(databaseName);
CosmosDatabaseResponse cosmosDatabaseResponse = databaseResponseMono.block();
CosmosDiagnostics diagnostics = cosmosDatabaseResponse.getDiagnostics();
logger.info("Create database diagnostics : {}", diagnostics);
database = client.getDatabase(cosmosDatabaseResponse.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 readDocumentById.
// Document read
private void readDocumentById() throws Exception {
logger.info("Read document by ID : {}", documentId);
// Read document by ID
CosmosItemResponse<Family> familyCosmosItemResponse = container.readItem(documentId, new PartitionKey(documentLastName), Family.class);
CosmosDiagnostics diagnostics = familyCosmosItemResponse.getDiagnostics();
logger.info("Read item diagnostics : {}", diagnostics);
Family family = familyCosmosItemResponse.getItem();
// Check result
logger.info("Finished reading family " + family.getId() + " with partition key " + family.getLastName());
logger.info("Done.");
}
use of com.azure.cosmos.CosmosDiagnostics in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStart 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.
CosmosItemResponse<Family> item = container.createItem(family, new PartitionKey(family.getLastName()), new CosmosItemRequestOptions());
CosmosDiagnostics diagnostics = item.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 CosmosDiagnosticsQuickStart method deleteDocument.
// Document delete
private void deleteDocument() throws Exception {
logger.info("Delete document by ID {}", documentId);
// Delete document
CosmosItemResponse<Object> itemResponse = container.deleteItem(documentId, new PartitionKey(documentLastName), new CosmosItemRequestOptions());
CosmosDiagnostics diagnostics = itemResponse.getDiagnostics();
logger.info("Delete item diagnostics : {}", diagnostics);
logger.info("Done.");
}
Aggregations