io.micronaut.data.operations.reactive.BlockingExecutorReactorRepositoryOperations Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micronaut-data-model Show documentation
Show all versions of micronaut-data-model Show documentation
Data Repository Support for Micronaut
The newest version!
/*
* Copyright 2017-2021 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.Experimental;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.data.model.Page;
import io.micronaut.data.model.runtime.DeleteBatchOperation;
import io.micronaut.data.model.runtime.DeleteOperation;
import io.micronaut.data.model.runtime.InsertBatchOperation;
import io.micronaut.data.model.runtime.InsertOperation;
import io.micronaut.data.model.runtime.PagedQuery;
import io.micronaut.data.model.runtime.PreparedQuery;
import io.micronaut.data.model.runtime.UpdateBatchOperation;
import io.micronaut.data.model.runtime.UpdateOperation;
import io.micronaut.data.operations.RepositoryOperations;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;
/**
* Implementation of {@link RepositoryOperations} that blocks every call from {@link ReactorReactiveRepositoryOperations}.
*
* @author Denis Stepanov
* @since 3.3.0
*/
@Experimental
public interface BlockingExecutorReactorRepositoryOperations extends RepositoryOperations, ReactorReactiveCapableRepository {
T block(Function> supplier);
Optional blockOptional(Function> supplier);
@Override
@Nullable
default T findOne(@NonNull Class type, @NonNull Object id) {
return block(reactive -> reactive.findOne(type, id));
}
@Nullable
@Override
default R findOne(@NonNull PreparedQuery preparedQuery) {
return block(reactive -> reactive.findOne(preparedQuery));
}
@NonNull
@Override
default Iterable findAll(@NonNull PreparedQuery preparedQuery) {
return block(reactive -> reactive.findAll(preparedQuery).collectList());
}
@NonNull
@Override
default Stream findStream(@NonNull PreparedQuery preparedQuery) {
return block(reactive -> reactive.findAll(preparedQuery).collectList()).stream();
}
@NonNull
@Override
default T persist(@NonNull InsertOperation operation) {
return blockOptional(reactive -> reactive.persist(operation)).orElseGet(operation::getEntity);
}
@NonNull
@Override
default T update(@NonNull UpdateOperation operation) {
return blockOptional(reactive -> reactive.update(operation)).orElseGet(operation::getEntity);
}
@Override
default Iterable updateAll(UpdateBatchOperation operation) {
return blockOptional(reactive -> reactive.updateAll(operation).collectList().>map(it -> it)).orElse(operation);
}
@NonNull
@Override
default Iterable persistAll(@NonNull InsertBatchOperation operation) {
return blockOptional(reactive -> reactive.persistAll(operation).collectList().>map(it -> it)).orElse(operation);
}
@NonNull
@Override
default Optional executeUpdate(@NonNull PreparedQuery, Number> preparedQuery) {
return blockOptional(reactive -> reactive.executeUpdate(preparedQuery));
}
@Override
default Optional executeDelete(@NonNull PreparedQuery, Number> preparedQuery) {
return blockOptional(reactive -> reactive.executeDelete(preparedQuery));
}
@Override
default List execute(PreparedQuery, R> preparedQuery) {
return block(reactive -> reactive.execute(preparedQuery).collectList());
}
@Override
default int delete(@NonNull DeleteOperation operation) {
return blockOptional(reactive -> reactive.delete(operation)).orElse(0).intValue();
}
@Override
default Optional deleteAll(@NonNull DeleteBatchOperation operation) {
return blockOptional(reactive -> reactive.deleteAll(operation));
}
@Override
default boolean exists(@NonNull PreparedQuery preparedQuery) {
return blockOptional(reactive -> reactive.exists(preparedQuery)).orElse(false);
}
@Override
default Page findPage(@NonNull PagedQuery query) {
return block(reactive -> reactive.findPage(query));
}
@NonNull
@Override
default Iterable findAll(@NonNull PagedQuery query) {
return block(reactive -> reactive.findAll(query).collectList());
}
@Override
default long count(PagedQuery pagedQuery) {
return blockOptional(reactive -> reactive.count(pagedQuery)).orElse(0L);
}
@NonNull
@Override
default Stream findStream(@NonNull PagedQuery query) {
return block(reactive -> reactive.findAll(query).collectList()).stream();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy