All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.cosmos.models.CosmosBulkItemResponse Maven / Gradle / Ivy

Go to download

This Package contains Microsoft Azure Cosmos SDK (with Reactive Extension Reactor support) for Azure Cosmos DB SQL API

There is a newer version: 4.61.1
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.models;

import com.azure.cosmos.CosmosAsyncContainer;
import com.azure.cosmos.CosmosDiagnostics;
import com.azure.cosmos.implementation.ImplementationBridgeHelpers;
import com.azure.cosmos.implementation.JsonSerializable;
import com.azure.cosmos.implementation.batch.BatchExecUtils;
import com.azure.cosmos.util.Beta;
import com.fasterxml.jackson.databind.node.ObjectNode;
import reactor.core.publisher.Flux;

import java.time.Duration;
import java.util.Map;

import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;

/**
 * Response of a {@link CosmosItemOperation} request when processed using Bulk by calling
 * {@link CosmosAsyncContainer#executeBulkOperations(Flux, CosmosBulkExecutionOptions)}.
 *
 */
@Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public final class CosmosBulkItemResponse {

    private final String eTag;
    private final double requestCharge;
    private final ObjectNode resourceObject;
    private final int statusCode;
    private final Duration retryAfter;
    private final int subStatusCode;
    private final Map responseHeaders;
    private final CosmosDiagnostics cosmosDiagnostics;

    /**
     * Initializes a new instance of the {@link CosmosBulkItemResponse} class.
     */
    CosmosBulkItemResponse(String eTag,
                           double requestCharge,
                           ObjectNode resourceObject,
                           int statusCode,
                           Duration retryAfter,
                           int subStatusCode,
                           Map responseHeaders,
                           CosmosDiagnostics cosmosDiagnostics) {

        checkNotNull(responseHeaders, "expected non-null responseHeaders");

        this.eTag = eTag;
        this.requestCharge = requestCharge;
        this.resourceObject = resourceObject;
        this.statusCode = statusCode;
        this.retryAfter = retryAfter;
        this.subStatusCode = subStatusCode;
        this.responseHeaders = responseHeaders;
        this.cosmosDiagnostics = cosmosDiagnostics;
    }

    /**
     * Gets the activity ID that identifies the server request made to execute this operation.
     *
     * @return the activity ID that identifies the server request made to execute this operation.
     */
    @Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
    public String getActivityId() {
        return BatchExecUtils.getActivityId(this.responseHeaders);
    }

    /**
     * Gets the entity tag associated with the current item.
     *
     * ETags are used for concurrency checking when updating resources.
     *
     * @return Entity tag associated with the current item.
     */
    @Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
    public String getETag() {
        return this.eTag;
    }

    /**
     * Gets the request charge as request units (RU) consumed by the current operation.
     * 

* For more information about the RU and factors that can impact the effective charges please visit * Request Units in Azure Cosmos DB * * @return the request charge. */ @Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING) public double getRequestCharge() { return this.requestCharge; } /** * Gets the item associated with the current result. * * @param the type parameter * * @param type class type for which deserialization is needed. * * @return item associated with the current result. */ @Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING) public T getItem(final Class type) { T item = null; if (this.getResourceObject() != null) { item = new JsonSerializable(this.getResourceObject()).toObject(type); } return item; } /** * Gets retry after. * * @return the retry after */ @Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING) public Duration getRetryAfterDuration() { return this.retryAfter; } /** * Gets sub status code associated with the current result. * * @return the sub status code */ @Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING) public int getSubStatusCode() { return this.subStatusCode; } /** * Gets a value indicating whether the current operation completed successfully. * * @return {@code true} if the current operation completed successfully; {@code false} otherwise. */ @Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING) public boolean isSuccessStatusCode() { return this.statusCode >= 200 && this.statusCode <= 299; } /** * Gets the HTTP status code associated with the current result. * * @return the status code. */ @Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING) public int getStatusCode() { return this.statusCode; } /** * Gets the cosmos diagnostic for this operation. * * @return the CosmosDiagnostics{@link CosmosDiagnostics} */ @Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING) public CosmosDiagnostics getCosmosDiagnostics() { return cosmosDiagnostics; } /** * Gets the token used for managing client's consistency requirements. * * @return the session token. */ @Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING) public String getSessionToken() { return BatchExecUtils.getSessionToken(this.responseHeaders); } /** * Gets the headers associated with the response. * * @return the response headers. */ @Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING) public Map getResponseHeaders() { return this.responseHeaders; } /** * Gets the end-to-end request latency for the current request to Azure Cosmos DB service. * * @return end-to-end request latency for the current request to Azure Cosmos DB service. */ @Beta(value = Beta.SinceVersion.V4_19_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING) public Duration getDuration() { if (cosmosDiagnostics == null) { return Duration.ZERO; } return this.cosmosDiagnostics.getDuration(); } private ObjectNode getResourceObject() { return resourceObject; } /////////////////////////////////////////////////////////////////////////////////////////// // the following helper/accessor only helps to access this class outside of this package.// /////////////////////////////////////////////////////////////////////////////////////////// static { ImplementationBridgeHelpers.CosmosBulkItemResponseHelper.setCosmosBulkItemResponseAccessor( new ImplementationBridgeHelpers.CosmosBulkItemResponseHelper.CosmosBulkItemResponseAccessor() { @Override public ObjectNode getResourceObject(CosmosBulkItemResponse cosmosBulkItemResponse) { return cosmosBulkItemResponse.getResourceObject(); } }); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy