Search in sources :

Example 11 with CosmosDiagnostics

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.");
}
Also used : CosmosItemResponse(com.azure.cosmos.models.CosmosItemResponse) PartitionKey(com.azure.cosmos.models.PartitionKey) Family(com.azure.cosmos.examples.common.Family) CosmosDiagnostics(com.azure.cosmos.CosmosDiagnostics)

Example 12 with CosmosDiagnostics

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.");
}
Also used : CosmosDatabaseResponse(com.azure.cosmos.models.CosmosDatabaseResponse) CosmosDiagnostics(com.azure.cosmos.CosmosDiagnostics)

Example 13 with CosmosDiagnostics

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.");
}
Also used : Family(com.azure.cosmos.examples.common.Family) PartitionKey(com.azure.cosmos.models.PartitionKey) CosmosDiagnostics(com.azure.cosmos.CosmosDiagnostics)

Example 14 with CosmosDiagnostics

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.");
}
Also used : CosmosItemRequestOptions(com.azure.cosmos.models.CosmosItemRequestOptions) Family(com.azure.cosmos.examples.common.Family) PartitionKey(com.azure.cosmos.models.PartitionKey) CosmosDiagnostics(com.azure.cosmos.CosmosDiagnostics)

Example 15 with CosmosDiagnostics

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.");
}
Also used : CosmosItemRequestOptions(com.azure.cosmos.models.CosmosItemRequestOptions) PartitionKey(com.azure.cosmos.models.PartitionKey) CosmosDiagnostics(com.azure.cosmos.CosmosDiagnostics)

Aggregations

CosmosDiagnostics (com.azure.cosmos.CosmosDiagnostics)15 Family (com.azure.cosmos.examples.common.Family)9 PartitionKey (com.azure.cosmos.models.PartitionKey)9 CosmosItemRequestOptions (com.azure.cosmos.models.CosmosItemRequestOptions)8 CosmosItemResponse (com.azure.cosmos.models.CosmosItemResponse)5 CosmosContainerProperties (com.azure.cosmos.models.CosmosContainerProperties)2 CosmosContainerResponse (com.azure.cosmos.models.CosmosContainerResponse)2 CosmosDatabaseResponse (com.azure.cosmos.models.CosmosDatabaseResponse)2 ThroughputProperties (com.azure.cosmos.models.ThroughputProperties)2 CosmosException (com.azure.cosmos.CosmosException)1