Search in sources :

Example 1 with CosmosDiagnostics

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

Example 2 with CosmosDiagnostics

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

Example 3 with CosmosDiagnostics

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.");
}
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 4 with CosmosDiagnostics

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

Example 5 with CosmosDiagnostics

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

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