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

io.micronaut.data.operations.reactive.ReactiveRepositoryOperations Maven / Gradle / Ivy

There is a newer version: 4.10.3
Show newest version
/*
 * Copyright 2017-2020 original authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.micronaut.data.operations.reactive;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.async.annotation.SingleResult;
import io.micronaut.core.convert.ConversionServiceProvider;
import io.micronaut.data.model.Page;
import io.micronaut.data.model.runtime.*;
import org.reactivestreams.Publisher;

/**
 * Reactive operations for reading data from a backing implementations.
 *
 * @author graemerocher
 * @since 1.0.0
 */
public interface ReactiveRepositoryOperations extends ConversionServiceProvider {

    /**
     * Find one by ID.
     *
     * @param type The type
     * @param id The id
     * @param  The generic type
     * @return A publisher that emits the result
     */
    @NonNull
    @SingleResult
     Publisher findOne(@NonNull Class type, @NonNull Object id);

    /**
     * Check with an record exists for the given query.
     * @param preparedQuery The query
     * @param  The declaring type
     * @return True if it exists
     */
    @NonNull
    @SingleResult
     Publisher exists(@NonNull PreparedQuery preparedQuery);

    /**
     * Find one by Query.
     *
     * @param preparedQuery The prepared query
     * @param  The generic resultType
     * @param  The result type
     * @return A publisher that emits the result
     */
    @NonNull
    @SingleResult
     Publisher findOne(@NonNull PreparedQuery preparedQuery);

    /**
     * Find one by ID.
     *
     * @param type The type
     * @param id The id
     * @param  The generic type
     * @return A publisher that emits zero or one result
     */
    @NonNull
    @SingleResult
     Publisher findOptional(@NonNull Class type, @NonNull Object id);

    /**
     * Find one by Query.
     *
     * @param preparedQuery The prepared query
     * @param  The generic resultType
     * @param  The result type
     * @return A publisher that emits the zero or one result
     */
    @NonNull
    @SingleResult
     Publisher findOptional(@NonNull PreparedQuery preparedQuery);

    /**
     * Finds all results for the given query.
     * @param pagedQuery The paged query
     * @param  The generic type
     * @return A publisher that emits the results
     */
    @NonNull
     Publisher findAll(PagedQuery pagedQuery);

    /**
     * Counts all results for the given query.
     * @param pagedQuery The paged query
     * @param  The generic type
     * @return A publisher that emits the count as a long
     */
    @NonNull
    @SingleResult
     Publisher count(PagedQuery pagedQuery);

    /**
     * Finds all results for the given query.
     * @param preparedQuery The prepared query
     * @param  The entity type
     * @param  The result type
     * @return A publisher that emits an iterable with all results
     */
    @NonNull
     Publisher findAll(@NonNull PreparedQuery preparedQuery);

    /**
     * Persist the entity returning a possibly new entity.
     * @param operation The entity operation
     * @param  The generic type
     * @return A publisher that emits the entity
     */
    @NonNull
    @SingleResult
     Publisher persist(@NonNull InsertOperation operation);

    /**
     * Updates the entity returning a possibly new entity.
     * @param operation The entity operation
     * @param  The generic type
     * @return A publisher that emits the entity
     */
    @NonNull
    @SingleResult
     Publisher update(@NonNull UpdateOperation operation);

    /**
     * Updates the entities for the given operation.
     *
     * @param operation The operation
     * @param  The generic type
     * @return The updated entities
     */
    @NonNull
     Publisher updateAll(@NonNull UpdateBatchOperation operation);

    /**
     * Persist all the given entities.
     * @param operation The batch operation
     * @param  The generic type
     * @return The entities, possibly mutated
     */
    @NonNull
     Publisher persistAll(@NonNull InsertBatchOperation operation);

    /**
     * Executes an update for the given query and parameter values. If it is possible to
     * return the number of objects updated, then do so.
     * @param preparedQuery The prepared query
     * @return A publisher that emits a boolean true if the update was successful
     */
    @NonNull
    @SingleResult
    Publisher executeUpdate(
            @NonNull PreparedQuery preparedQuery
    );

    /**
     * Executes a batch delete for the given query and parameter values. If it is possible to
     * return the number of objects updated, then do so.
     * @param preparedQuery The prepared query
     * @return A publisher that emits a boolean true if the update was successful
     */
    @NonNull
    @SingleResult
    default Publisher executeDelete(
            @NonNull PreparedQuery preparedQuery
    ) {
        return executeUpdate(preparedQuery);
    }

    /**
     * Deletes the entity.
     * @param operation The batch operation
     * @param  The generic type
     * @return A publisher that emits the number of entities deleted
     */
    @NonNull
    @SingleResult
     Publisher delete(@NonNull DeleteOperation operation);

    /**
     * Deletes all the entities of the given type.
     * @param operation The batch operation
     * @param  The generic type
     * @return A publisher that emits the number of entities deleted
     */
    @NonNull
    @SingleResult
     Publisher deleteAll(@NonNull DeleteBatchOperation operation);

    /**
     * Find a page for the given entity and pageable.
     * @param pagedQuery The paged query
     * @param  The entity generic type
     * @return The page type
     */
    @NonNull
    @SingleResult
     Publisher> findPage(@NonNull PagedQuery pagedQuery);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy