MetastoresImpl.java

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.analytics.synapse.artifacts.implementation;

import com.azure.analytics.synapse.artifacts.models.ErrorContractException;
import com.azure.analytics.synapse.artifacts.models.MetastoreRegisterObject;
import com.azure.analytics.synapse.artifacts.models.MetastoreRegistrationResponse;
import com.azure.analytics.synapse.artifacts.models.MetastoreRequestSuccessResponse;
import com.azure.analytics.synapse.artifacts.models.MetastoreUpdateObject;
import com.azure.analytics.synapse.artifacts.models.MetastoreUpdationResponse;
import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import reactor.core.publisher.Mono;

/** An instance of this class provides access to all the operations defined in Metastores. */
public final class MetastoresImpl {
    /** The proxy service used to perform REST calls. */
    private final MetastoresService service;

    /** The service client containing this operation class. */
    private final ArtifactsClientImpl client;

    /**
     * Initializes an instance of MetastoresImpl.
     *
     * @param client the instance of the service client containing this operation class.
     */
    MetastoresImpl(ArtifactsClientImpl client) {
        this.service =
                RestProxy.create(MetastoresService.class, client.getHttpPipeline(), client.getSerializerAdapter());
        this.client = client;
    }

    /**
     * The interface defining all the services for ArtifactsClientMetastores to be used by the proxy service to perform
     * REST calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(name = "ArtifactsClientMetas")
    private interface MetastoresService {
        @Put("/metastore/create-database-operations/{id}")
        @ExpectedResponses({201})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<MetastoreRegistrationResponse>> register(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("id") String id,
                @BodyParam("application/json") MetastoreRegisterObject registerBody,
                @HeaderParam("Accept") String accept,
                Context context);

        @Get("/metastore/create-database-operations/{id}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<MetastoreRequestSuccessResponse>> getDatabaseOperations(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("id") String id,
                @HeaderParam("Accept") String accept,
                Context context);

        @Put("/metastore/update-database-operations/{id}")
        @ExpectedResponses({201})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<MetastoreUpdationResponse>> update(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("id") String id,
                @BodyParam("application/json") MetastoreUpdateObject updateBody,
                @HeaderParam("Accept") String accept,
                Context context);

        @Delete("/metastore/databases/{id}")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<Void>> delete(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("id") String id,
                @HeaderParam("Accept") String accept,
                Context context);
    }

    /**
     * Register files in Syms.
     *
     * @param id The name of the database to be created. The name can contain only alphanumeric characters and should
     *     not exceed 24 characters.
     * @param registerBody The body for the register request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<MetastoreRegistrationResponse>> registerWithResponseAsync(
            String id, MetastoreRegisterObject registerBody) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.register(this.client.getEndpoint(), apiVersion, id, registerBody, accept, context));
    }

    /**
     * Register files in Syms.
     *
     * @param id The name of the database to be created. The name can contain only alphanumeric characters and should
     *     not exceed 24 characters.
     * @param registerBody The body for the register request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<MetastoreRegistrationResponse>> registerWithResponseAsync(
            String id, MetastoreRegisterObject registerBody, Context context) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return service.register(this.client.getEndpoint(), apiVersion, id, registerBody, accept, context);
    }

    /**
     * Register files in Syms.
     *
     * @param id The name of the database to be created. The name can contain only alphanumeric characters and should
     *     not exceed 24 characters.
     * @param registerBody The body for the register request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<MetastoreRegistrationResponse> registerAsync(String id, MetastoreRegisterObject registerBody) {
        return registerWithResponseAsync(id, registerBody)
                .flatMap(
                        (Response<MetastoreRegistrationResponse> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Register files in Syms.
     *
     * @param id The name of the database to be created. The name can contain only alphanumeric characters and should
     *     not exceed 24 characters.
     * @param registerBody The body for the register request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<MetastoreRegistrationResponse> registerAsync(
            String id, MetastoreRegisterObject registerBody, Context context) {
        return registerWithResponseAsync(id, registerBody, context)
                .flatMap(
                        (Response<MetastoreRegistrationResponse> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Register files in Syms.
     *
     * @param id The name of the database to be created. The name can contain only alphanumeric characters and should
     *     not exceed 24 characters.
     * @param registerBody The body for the register request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public MetastoreRegistrationResponse register(String id, MetastoreRegisterObject registerBody) {
        return registerAsync(id, registerBody).block();
    }

    /**
     * Register files in Syms.
     *
     * @param id The name of the database to be created. The name can contain only alphanumeric characters and should
     *     not exceed 24 characters.
     * @param registerBody The body for the register request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<MetastoreRegistrationResponse> registerWithResponse(
            String id, MetastoreRegisterObject registerBody, Context context) {
        return registerWithResponseAsync(id, registerBody, context).block();
    }

    /**
     * Gets status of the database.
     *
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return status of the database.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<MetastoreRequestSuccessResponse>> getDatabaseOperationsWithResponseAsync(String id) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.getDatabaseOperations(this.client.getEndpoint(), apiVersion, id, accept, context));
    }

    /**
     * Gets status of the database.
     *
     * @param id The id parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return status of the database.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<MetastoreRequestSuccessResponse>> getDatabaseOperationsWithResponseAsync(
            String id, Context context) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return service.getDatabaseOperations(this.client.getEndpoint(), apiVersion, id, accept, context);
    }

    /**
     * Gets status of the database.
     *
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return status of the database.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<MetastoreRequestSuccessResponse> getDatabaseOperationsAsync(String id) {
        return getDatabaseOperationsWithResponseAsync(id)
                .flatMap(
                        (Response<MetastoreRequestSuccessResponse> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Gets status of the database.
     *
     * @param id The id parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return status of the database.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<MetastoreRequestSuccessResponse> getDatabaseOperationsAsync(String id, Context context) {
        return getDatabaseOperationsWithResponseAsync(id, context)
                .flatMap(
                        (Response<MetastoreRequestSuccessResponse> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Gets status of the database.
     *
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return status of the database.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public MetastoreRequestSuccessResponse getDatabaseOperations(String id) {
        return getDatabaseOperationsAsync(id).block();
    }

    /**
     * Gets status of the database.
     *
     * @param id The id parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return status of the database.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<MetastoreRequestSuccessResponse> getDatabaseOperationsWithResponse(String id, Context context) {
        return getDatabaseOperationsWithResponseAsync(id, context).block();
    }

    /**
     * Update files in Syms.
     *
     * @param id The name of the database to be updated.
     * @param updateBody The body for the update request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<MetastoreUpdationResponse>> updateWithResponseAsync(
            String id, MetastoreUpdateObject updateBody) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.update(this.client.getEndpoint(), apiVersion, id, updateBody, accept, context));
    }

    /**
     * Update files in Syms.
     *
     * @param id The name of the database to be updated.
     * @param updateBody The body for the update request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<MetastoreUpdationResponse>> updateWithResponseAsync(
            String id, MetastoreUpdateObject updateBody, Context context) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return service.update(this.client.getEndpoint(), apiVersion, id, updateBody, accept, context);
    }

    /**
     * Update files in Syms.
     *
     * @param id The name of the database to be updated.
     * @param updateBody The body for the update request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<MetastoreUpdationResponse> updateAsync(String id, MetastoreUpdateObject updateBody) {
        return updateWithResponseAsync(id, updateBody)
                .flatMap(
                        (Response<MetastoreUpdationResponse> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Update files in Syms.
     *
     * @param id The name of the database to be updated.
     * @param updateBody The body for the update request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<MetastoreUpdationResponse> updateAsync(String id, MetastoreUpdateObject updateBody, Context context) {
        return updateWithResponseAsync(id, updateBody, context)
                .flatMap(
                        (Response<MetastoreUpdationResponse> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Update files in Syms.
     *
     * @param id The name of the database to be updated.
     * @param updateBody The body for the update request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public MetastoreUpdationResponse update(String id, MetastoreUpdateObject updateBody) {
        return updateAsync(id, updateBody).block();
    }

    /**
     * Update files in Syms.
     *
     * @param id The name of the database to be updated.
     * @param updateBody The body for the update request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<MetastoreUpdationResponse> updateWithResponse(
            String id, MetastoreUpdateObject updateBody, Context context) {
        return updateWithResponseAsync(id, updateBody, context).block();
    }

    /**
     * Remove files in Syms.
     *
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> deleteWithResponseAsync(String id) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.delete(this.client.getEndpoint(), apiVersion, id, accept, context));
    }

    /**
     * Remove files in Syms.
     *
     * @param id The id parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> deleteWithResponseAsync(String id, Context context) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return service.delete(this.client.getEndpoint(), apiVersion, id, accept, context);
    }

    /**
     * Remove files in Syms.
     *
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> deleteAsync(String id) {
        return deleteWithResponseAsync(id).flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Remove files in Syms.
     *
     * @param id The id parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> deleteAsync(String id, Context context) {
        return deleteWithResponseAsync(id, context).flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Remove files in Syms.
     *
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String id) {
        deleteAsync(id).block();
    }

    /**
     * Remove files in Syms.
     *
     * @param id The id parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(String id, Context context) {
        return deleteWithResponseAsync(id, context).block();
    }
}