Search in sources :

Example 6 with CosmosDiagnostics

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

Example 7 with CosmosDiagnostics

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

Example 8 with CosmosDiagnostics

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

Example 9 with CosmosDiagnostics

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

Example 10 with CosmosDiagnostics

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