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

com.azure.cosmos.CosmosAsyncStoredProcedure Maven / Gradle / Ivy

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.cosmos;

import com.azure.cosmos.implementation.Paths;
import com.azure.cosmos.implementation.StoredProcedure;
import reactor.core.publisher.Mono;

public class CosmosAsyncStoredProcedure {

    @SuppressWarnings("EnforceFinalFields")
    private final CosmosAsyncContainer cosmosContainer;
    private String id;

    CosmosAsyncStoredProcedure(String id, CosmosAsyncContainer cosmosContainer) {
        this.id = id;
        this.cosmosContainer = cosmosContainer;
    }

    /**
     * Get the id of the {@link CosmosAsyncStoredProcedure}
     *
     * @return the id of the {@link CosmosAsyncStoredProcedure}
     */
    public String id() {
        return id;
    }

    /**
     * Set the id of the {@link CosmosAsyncStoredProcedure}
     *
     * @param id the id of the {@link CosmosAsyncStoredProcedure}
     * @return the same {@link CosmosAsyncStoredProcedure} that had the id set
     */
    CosmosAsyncStoredProcedure id(String id) {
        this.id = id;
        return this;
    }

    /**
     * Read a stored procedure by the stored procedure link.
     * 

* After subscription the operation will be performed. * The {@link Mono} upon successful completion will contain a single resource response with the read stored * procedure. * In case of failure the {@link Mono} will error. * * @return an {@link Mono} containing the single resource response with the read stored procedure or an error. */ public Mono read() { return read(null); } /** * Read a stored procedure by the stored procedure link. *

* After subscription the operation will be performed. * The {@link Mono} upon successful completion will contain a single resource response with the read stored * procedure. * In case of failure the {@link Mono} will error. * * @param options the request options. * @return an {@link Mono} containing the single resource response with the read stored procedure or an error. */ public Mono read(CosmosStoredProcedureRequestOptions options) { if (options == null) { options = new CosmosStoredProcedureRequestOptions(); } return cosmosContainer.getDatabase().getDocClientWrapper().readStoredProcedure(getLink(), options.toRequestOptions()) .map(response -> new CosmosAsyncStoredProcedureResponse(response, cosmosContainer)).single(); } /** * Deletes a stored procedure by the stored procedure link. *

* After subscription the operation will be performed. * The {@link Mono} upon successful completion will contain a single resource response for the deleted stored * procedure. * In case of failure the {@link Mono} will error. * * @return an {@link Mono} containing the single resource response for the deleted stored procedure or an error. */ public Mono delete() { return delete(null); } /** * Deletes a stored procedure by the stored procedure link. *

* After subscription the operation will be performed. * The {@link Mono} upon successful completion will contain a single resource response for the deleted stored * procedure. * In case of failure the {@link Mono} will error. * * @param options the request options. * @return an {@link Mono} containing the single resource response for the deleted stored procedure or an error. */ public Mono delete(CosmosStoredProcedureRequestOptions options) { if (options == null) { options = new CosmosStoredProcedureRequestOptions(); } return cosmosContainer.getDatabase() .getDocClientWrapper() .deleteStoredProcedure(getLink(), options.toRequestOptions()) .map(response -> new CosmosAsyncStoredProcedureResponse(response, cosmosContainer)) .single(); } /** * Executes a stored procedure by the stored procedure link. *

* After subscription the operation will be performed. * The {@link Mono} upon successful completion will contain a single resource response with the stored procedure * response. * In case of failure the {@link Mono} will error. * * @param procedureParams the array of procedure parameter values. * @param options the request options. * @return an {@link Mono} containing the single resource response with the stored procedure response or an error. */ public Mono execute(Object[] procedureParams, CosmosStoredProcedureRequestOptions options) { if (options == null) { options = new CosmosStoredProcedureRequestOptions(); } return cosmosContainer.getDatabase() .getDocClientWrapper() .executeStoredProcedure(getLink(), options.toRequestOptions(), procedureParams) .map(response -> new CosmosAsyncStoredProcedureResponse(response, cosmosContainer, this.id)) .single(); } /** * Replaces a stored procedure. *

* After subscription the operation will be performed. * The {@link Mono} upon successful completion will contain a single resource response with the replaced stored * procedure. * In case of failure the {@link Mono} will error. * * @param storedProcedureSettings the stored procedure properties * @return an {@link Mono} containing the single resource response with the replaced stored procedure or an error. */ public Mono replace(CosmosStoredProcedureProperties storedProcedureSettings) { return replace(storedProcedureSettings, null); } /** * Replaces a stored procedure. *

* After subscription the operation will be performed. * The {@link Mono} upon successful completion will contain a single resource response with the replaced stored * procedure. * In case of failure the {@link Mono} will error. * * @param storedProcedureSettings the stored procedure properties. * @param options the request options. * @return an {@link Mono} containing the single resource response with the replaced stored procedure or an error. */ public Mono replace(CosmosStoredProcedureProperties storedProcedureSettings, CosmosStoredProcedureRequestOptions options) { if (options == null) { options = new CosmosStoredProcedureRequestOptions(); } return cosmosContainer.getDatabase() .getDocClientWrapper() .replaceStoredProcedure(new StoredProcedure(storedProcedureSettings.toJson()), options.toRequestOptions()) .map(response -> new CosmosAsyncStoredProcedureResponse(response, cosmosContainer)) .single(); } String getURIPathSegment() { return Paths.STORED_PROCEDURES_PATH_SEGMENT; } String getParentLink() { return cosmosContainer.getLink(); } String getLink() { StringBuilder builder = new StringBuilder(); builder.append(getParentLink()); builder.append("/"); builder.append(getURIPathSegment()); builder.append("/"); builder.append(id()); return builder.toString(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy