Class DefaultReactiveMongoRepositoryOperations
java.lang.Object
io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperations
io.micronaut.data.mongodb.operations.DefaultReactiveMongoRepositoryOperations
- All Implemented Interfaces:
io.micronaut.context.ApplicationContextProvider, io.micronaut.core.convert.ConversionServiceProvider, MongoReactiveRepositoryOperations, MongoReactorRepositoryOperations, HintsCapableRepository, ReactiveRepositoryOperations, ReactorReactiveRepositoryOperations, ReactiveCascadeOperations.ReactiveCascadeOperationsHelper<DefaultReactiveMongoRepositoryOperations.MongoOperationContext>, MethodContextAwareStoredQueryDecorator, PreparedQueryDecorator
@RequiresReactiveMongo
@EachBean(com.mongodb.reactivestreams.client.MongoClient.class)
@Internal
public final class DefaultReactiveMongoRepositoryOperations
extends AbstractRepositoryOperations
implements MongoReactorRepositoryOperations, ReactorReactiveRepositoryOperations, ReactiveCascadeOperations.ReactiveCascadeOperationsHelper<DefaultReactiveMongoRepositoryOperations.MongoOperationContext>
The reactive MongoDB repository operations implementation.
- Since:
- 3.3
- Author:
- Denis Stepanov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final MongoCollectionNameProviderprotected final MongoDatabaseNameProviderprotected static final org.bson.BsonDocumentFields inherited from class AbstractRepositoryOperations
attributeConverterRegistry, conversionService, dateTimeProvider, entityEventRegistry, runtimeEntityRegistry -
Method Summary
Modifier and TypeMethodDescriptionprotected org.bson.BsonDocumentassociation(org.bson.codecs.configuration.CodecRegistry codecRegistry, Object value, RuntimePersistentEntity<Object> persistentEntity, Object child, RuntimePersistentEntity<Object> childPersistentEntity) protected <R> RconvertResult(PreparedQuery<?, ?> preparedQuery, org.bson.codecs.configuration.CodecRegistry codecRegistry, Class<R> resultType, org.bson.BsonDocument result, boolean isDtoProjection) protected <R> Optional<R> convertUsingIntrospected(PreparedQuery<?, ?> preparedQuery, org.bson.BsonDocument result, Class<R> resultType) Attempts to convert a BSON document into an instance of the specified result type using introspection.<T> reactor.core.publisher.Mono<Long> count(PagedQuery<T> pagedQuery) Counts all results for the given query.protected final <T> org.bson.conversions.BsoncreateFilterIdAndVersion(RuntimePersistentEntity<T> persistentEntity, T entity, org.bson.codecs.configuration.CodecRegistry codecRegistry) <E,R> StoredQuery <E, R> decorate(io.micronaut.aop.MethodInvocationContext<?, ?> context, StoredQuery<E, R> storedQuery) Decorate stored query.<E,R> PreparedQuery <E, R> decorate(PreparedQuery<E, R> preparedQuery) Decorate prepared query.<T> reactor.core.publisher.Mono<Number> delete(DeleteOperation<T> operation) Deletes the entity.<T> reactor.core.publisher.Mono<Number> deleteAll(DeleteBatchOperation<T> operation) Deletes all the entities of the given type.reactor.core.publisher.Mono<Number> executeDelete(PreparedQuery<?, Number> preparedQuery) Executes a batch delete for the given query and parameter values.reactor.core.publisher.Mono<Number> executeUpdate(PreparedQuery<?, Number> preparedQuery) Executes an update for the given query and parameter values.<T> reactor.core.publisher.Mono<Boolean> exists(PreparedQuery<T, Boolean> preparedQuery) Check with a record exists for the given query.<T> reactor.core.publisher.Flux<T> findAll(PagedQuery<T> query) Finds all results for the given query.<T,R> reactor.core.publisher.Flux <R> findAll(PreparedQuery<T, R> preparedQuery) Finds all results for the given query.<T,R> reactor.core.publisher.Mono <R> findOne(PreparedQuery<T, R> preparedQuery) Find one by Query.<T> reactor.core.publisher.Mono<T> Find one by ID.<T,R> reactor.core.publisher.Mono <R> findOptional(PreparedQuery<T, R> preparedQuery) Find one by Query.<T> reactor.core.publisher.Mono<T> findOptional(Class<T> type, Object id) Find one by ID.<R> reactor.core.publisher.Mono<Page<R>> findPage(PagedQuery<R> pagedQuery) Find a page for the given entity and pageable.protected org.bson.codecs.configuration.CodecRegistrygetCodecRegistry(com.mongodb.reactivestreams.client.MongoDatabase mongoDatabase) protected com.mongodb.reactivestreams.client.MongoDatabasegetDatabase(PersistentEntity persistentEntity, @Nullable Class<?> repository) protected final com.mongodb.client.model.DeleteOptionsgetDeleteOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) protected final com.mongodb.client.model.InsertManyOptionsgetInsertManyOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) protected final com.mongodb.client.model.InsertOneOptionsgetInsertOneOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) protected <E,R> MongoPreparedQuery <E, R> getMongoPreparedQuery(PreparedQuery<E, R> preparedQuery) protected <E,R> MongoStoredQuery <E, R> getMongoStoredQuery(StoredQuery<E, R> storedQuery) protected final com.mongodb.client.model.ReplaceOptionsgetReplaceOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) protected voidlogAggregate(MongoAggregation aggregation) protected void<T> reactor.core.publisher.Mono<T> persist(InsertOperation<T> operation) Persist the entity returning a possibly new entity.<T> reactor.core.publisher.Flux<T> persistAll(InsertBatchOperation<T> operation) Persist all the given entities.<T> reactor.core.publisher.Flux<T> persistBatch(DefaultReactiveMongoRepositoryOperations.MongoOperationContext ctx, Iterable<T> values, RuntimePersistentEntity<T> persistentEntity, @Nullable Predicate<T> predicate) Persist multiple entities in batch during cascade.reactor.core.publisher.Mono<Void> persistManyAssociation(DefaultReactiveMongoRepositoryOperations.MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, Object value, RuntimePersistentEntity<Object> persistentEntity, Object child, RuntimePersistentEntity<Object> childPersistentEntity) Persist JOIN table relationship.reactor.core.publisher.Mono<Void> persistManyAssociationBatch(DefaultReactiveMongoRepositoryOperations.MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, Object value, RuntimePersistentEntity<Object> persistentEntity, Iterable<Object> child, RuntimePersistentEntity<Object> childPersistentEntity, Predicate<Object> veto) Persist JOIN table relationships in batch.<T> reactor.core.publisher.Mono<T> persistOne(DefaultReactiveMongoRepositoryOperations.MongoOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity) Persist one entity during cascade.<T> reactor.core.publisher.Mono<T> update(UpdateOperation<T> operation) Updates the entity returning a possibly new entity.<T> reactor.core.publisher.Flux<T> updateAll(UpdateBatchOperation<T> operation) Updates the entities for the given operation.<T> reactor.core.publisher.Mono<T> updateOne(DefaultReactiveMongoRepositoryOperations.MongoOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity) Update one entity during cascade.<T> reactor.core.publisher.Mono<T> withClientSession(Function<com.mongodb.reactivestreams.client.ClientSession, reactor.core.publisher.Mono<T>> function) Starts a new session or reuses one from the context.<T> reactor.core.publisher.Flux<T> withClientSessionMany(Function<com.mongodb.reactivestreams.client.ClientSession, reactor.core.publisher.Flux<T>> function) Starts a new session or reuses one from the context.Methods inherited from class AbstractRepositoryOperations
checkOptimisticLocking, getApplicationContext, getConversionService, getEntity, getIdReader, isOnlySingleEndedJoins, triggerPostLoadMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.core.convert.ConversionServiceProvider
getConversionServiceMethods inherited from interface HintsCapableRepository
getQueryHintsMethods inherited from interface ReactiveCascadeOperations.ReactiveCascadeOperationsHelper
isSupportsBatchDelete, isSupportsBatchInsert, isSupportsBatchUpdateMethods inherited from interface ReactorReactiveRepositoryOperations
execute
-
Field Details
-
EMPTY
protected static final org.bson.BsonDocument EMPTY -
collectionNameProvider
-
databaseNameProvider
-
-
Method Details
-
findOne
Description copied from interface:ReactiveRepositoryOperationsFind one by ID.- Specified by:
findOnein interfaceReactiveRepositoryOperations- Specified by:
findOnein interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
type- The typeid- The id- Returns:
- A publisher that emits the result
-
findOne
Description copied from interface:ReactiveRepositoryOperationsFind one by Query.- Specified by:
findOnein interfaceReactiveRepositoryOperations- Specified by:
findOnein interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The generic resultTypeR- The result type- Parameters:
preparedQuery- The prepared query- Returns:
- A publisher that emits the result
-
exists
Description copied from interface:ReactiveRepositoryOperationsCheck with a record exists for the given query.- Specified by:
existsin interfaceReactiveRepositoryOperations- Specified by:
existsin interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The declaring type- Parameters:
preparedQuery- The query- Returns:
- True if it exists
-
findAll
Description copied from interface:ReactiveRepositoryOperationsFinds all results for the given query.- Specified by:
findAllin interfaceReactiveRepositoryOperations- Specified by:
findAllin interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
query- The paged query- Returns:
- A publisher that emits the results
-
count
Description copied from interface:ReactiveRepositoryOperationsCounts all results for the given query.- Specified by:
countin interfaceReactiveRepositoryOperations- Specified by:
countin interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
pagedQuery- The paged query- Returns:
- A publisher that emits the count as a long
-
findAll
Description copied from interface:ReactiveRepositoryOperationsFinds all results for the given query.- Specified by:
findAllin interfaceReactiveRepositoryOperations- Specified by:
findAllin interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The entity typeR- The result type- Parameters:
preparedQuery- The prepared query- Returns:
- A publisher that emits an iterable with all results
-
findOptional
Description copied from interface:ReactiveRepositoryOperationsFind one by ID.- Specified by:
findOptionalin interfaceReactiveRepositoryOperations- Specified by:
findOptionalin interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
type- The typeid- The id- Returns:
- A publisher that emits zero or one result
-
findOptional
Description copied from interface:ReactiveRepositoryOperationsFind one by Query.- Specified by:
findOptionalin interfaceReactiveRepositoryOperations- Specified by:
findOptionalin interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The generic resultTypeR- The result type- Parameters:
preparedQuery- The prepared query- Returns:
- A publisher that emits the zero or one result
-
findPage
Description copied from interface:ReactiveRepositoryOperationsFind a page for the given entity and pageable.- Specified by:
findPagein interfaceReactiveRepositoryOperations- Specified by:
findPagein interfaceReactorReactiveRepositoryOperations- Type Parameters:
R- The entity generic type- Parameters:
pagedQuery- The paged query- Returns:
- The page type
-
persist
Description copied from interface:ReactiveRepositoryOperationsPersist the entity returning a possibly new entity.- Specified by:
persistin interfaceReactiveRepositoryOperations- Specified by:
persistin interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The entity operation- Returns:
- A publisher that emits the entity
-
persistAll
Description copied from interface:ReactiveRepositoryOperationsPersist all the given entities.- Specified by:
persistAllin interfaceReactiveRepositoryOperations- Specified by:
persistAllin interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The batch operation- Returns:
- The entities, possibly mutated
-
update
Description copied from interface:ReactiveRepositoryOperationsUpdates the entity returning a possibly new entity.- Specified by:
updatein interfaceReactiveRepositoryOperations- Specified by:
updatein interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The entity operation- Returns:
- A publisher that emits the entity
-
updateAll
Description copied from interface:ReactiveRepositoryOperationsUpdates the entities for the given operation.- Specified by:
updateAllin interfaceReactiveRepositoryOperations- Specified by:
updateAllin interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The updated entities
-
delete
Description copied from interface:ReactiveRepositoryOperationsDeletes the entity.- Specified by:
deletein interfaceReactiveRepositoryOperations- Specified by:
deletein interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The batch operation- Returns:
- A publisher that emits the number of entities deleted
-
deleteAll
Description copied from interface:ReactiveRepositoryOperationsDeletes all the entities of the given type.- Specified by:
deleteAllin interfaceReactiveRepositoryOperations- Specified by:
deleteAllin interfaceReactorReactiveRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The batch operation- Returns:
- A publisher that emits the number of entities deleted
-
executeUpdate
Description copied from interface:ReactiveRepositoryOperationsExecutes an update for the given query and parameter values. If it is possible to return the number of objects updated, then do so.- Specified by:
executeUpdatein interfaceReactiveRepositoryOperations- Specified by:
executeUpdatein interfaceReactorReactiveRepositoryOperations- Parameters:
preparedQuery- The prepared query- Returns:
- A publisher that emits a boolean true if the update was successful
-
executeDelete
Description copied from interface:ReactiveRepositoryOperationsExecutes a batch delete for the given query and parameter values. If it is possible to return the number of objects updated, then do so.- Specified by:
executeDeletein interfaceReactiveRepositoryOperations- Specified by:
executeDeletein interfaceReactorReactiveRepositoryOperations- Parameters:
preparedQuery- The prepared query- Returns:
- A publisher that emits a boolean true if the update was successful
-
persistOne
public <T> reactor.core.publisher.Mono<T> persistOne(DefaultReactiveMongoRepositoryOperations.MongoOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity) Description copied from interface:ReactiveCascadeOperations.ReactiveCascadeOperationsHelperPersist one entity during cascade.- Specified by:
persistOnein interfaceReactiveCascadeOperations.ReactiveCascadeOperationsHelper<DefaultReactiveMongoRepositoryOperations.MongoOperationContext>- Type Parameters:
T- The entity type- Parameters:
ctx- The contextvalue- The entity valuepersistentEntity- The persistent entity- Returns:
- The entity value
-
persistBatch
public <T> reactor.core.publisher.Flux<T> persistBatch(DefaultReactiveMongoRepositoryOperations.MongoOperationContext ctx, Iterable<T> values, RuntimePersistentEntity<T> persistentEntity, @Nullable Predicate<T> predicate) Description copied from interface:ReactiveCascadeOperations.ReactiveCascadeOperationsHelperPersist multiple entities in batch during cascade.- Specified by:
persistBatchin interfaceReactiveCascadeOperations.ReactiveCascadeOperationsHelper<DefaultReactiveMongoRepositoryOperations.MongoOperationContext>- Type Parameters:
T- The entity type- Parameters:
ctx- The contextvalues- The entity valuespersistentEntity- The persistent entitypredicate- The veto predicate- Returns:
- The entity values
-
updateOne
public <T> reactor.core.publisher.Mono<T> updateOne(DefaultReactiveMongoRepositoryOperations.MongoOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity) Description copied from interface:ReactiveCascadeOperations.ReactiveCascadeOperationsHelperUpdate one entity during cascade.- Specified by:
updateOnein interfaceReactiveCascadeOperations.ReactiveCascadeOperationsHelper<DefaultReactiveMongoRepositoryOperations.MongoOperationContext>- Type Parameters:
T- The entity type- Parameters:
ctx- The contextvalue- The entity valuepersistentEntity- The persistent entity- Returns:
- The entity value
-
getDatabase
protected com.mongodb.reactivestreams.client.MongoDatabase getDatabase(PersistentEntity persistentEntity, @Nullable Class<?> repository) -
getCodecRegistry
protected org.bson.codecs.configuration.CodecRegistry getCodecRegistry(com.mongodb.reactivestreams.client.MongoDatabase mongoDatabase) -
persistManyAssociation
public reactor.core.publisher.Mono<Void> persistManyAssociation(DefaultReactiveMongoRepositoryOperations.MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, Object value, RuntimePersistentEntity<Object> persistentEntity, Object child, RuntimePersistentEntity<Object> childPersistentEntity) Description copied from interface:ReactiveCascadeOperations.ReactiveCascadeOperationsHelperPersist JOIN table relationship.- Specified by:
persistManyAssociationin interfaceReactiveCascadeOperations.ReactiveCascadeOperationsHelper<DefaultReactiveMongoRepositoryOperations.MongoOperationContext>- Parameters:
ctx- The contextruntimeAssociation- The associationvalue- The parent entity valuepersistentEntity- The parent persistent entitychild- The child entity valuechildPersistentEntity- The child persistent entity- Returns:
- The empty mono
-
persistManyAssociationBatch
public reactor.core.publisher.Mono<Void> persistManyAssociationBatch(DefaultReactiveMongoRepositoryOperations.MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, Object value, RuntimePersistentEntity<Object> persistentEntity, Iterable<Object> child, RuntimePersistentEntity<Object> childPersistentEntity, Predicate<Object> veto) Description copied from interface:ReactiveCascadeOperations.ReactiveCascadeOperationsHelperPersist JOIN table relationships in batch.- Specified by:
persistManyAssociationBatchin interfaceReactiveCascadeOperations.ReactiveCascadeOperationsHelper<DefaultReactiveMongoRepositoryOperations.MongoOperationContext>- Parameters:
ctx- The contextruntimeAssociation- The associationvalue- The parent entity valuepersistentEntity- The parent persistent entitychild- The child entity valueschildPersistentEntity- The child persistent entityveto- The veto predicate- Returns:
- The empty mono
-
withClientSession
public <T> reactor.core.publisher.Mono<T> withClientSession(Function<com.mongodb.reactivestreams.client.ClientSession, reactor.core.publisher.Mono<T>> function) Description copied from interface:MongoReactorRepositoryOperationsStarts a new session or reuses one from the context.- Specified by:
withClientSessionin interfaceMongoReactorRepositoryOperations- Type Parameters:
T- The emitted type- Parameters:
function- The function- Returns:
- The processed publisher
-
withClientSessionMany
public <T> reactor.core.publisher.Flux<T> withClientSessionMany(Function<com.mongodb.reactivestreams.client.ClientSession, reactor.core.publisher.Flux<T>> function) Description copied from interface:MongoReactorRepositoryOperationsStarts a new session or reuses one from the context.- Specified by:
withClientSessionManyin interfaceMongoReactorRepositoryOperations- Type Parameters:
T- The emitted type- Parameters:
function- The function- Returns:
- The processed publisher
-
getReplaceOptions
protected final com.mongodb.client.model.ReplaceOptions getReplaceOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) -
getInsertOneOptions
protected final com.mongodb.client.model.InsertOneOptions getInsertOneOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) -
getInsertManyOptions
protected final com.mongodb.client.model.InsertManyOptions getInsertManyOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) -
getDeleteOptions
protected final com.mongodb.client.model.DeleteOptions getDeleteOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) -
getMongoStoredQuery
-
getMongoPreparedQuery
-
decorate
Description copied from interface:PreparedQueryDecoratorDecorate prepared query.- Specified by:
decoratein interfacePreparedQueryDecorator- Type Parameters:
E- The entity typeR- The result type- Parameters:
preparedQuery- The query to be decorated- Returns:
- decorated prepared query
-
decorate
public <E,R> StoredQuery<E,R> decorate(io.micronaut.aop.MethodInvocationContext<?, ?> context, StoredQuery<E, R> storedQuery) Description copied from interface:MethodContextAwareStoredQueryDecoratorDecorate stored query.- Specified by:
decoratein interfaceMethodContextAwareStoredQueryDecorator- Type Parameters:
E- The entity typeR- The result type- Parameters:
context- The contextstoredQuery- The query to be decorated- Returns:
- decorated stored query
-
convertResult
protected <R> R convertResult(PreparedQuery<?, ?> preparedQuery, org.bson.codecs.configuration.CodecRegistry codecRegistry, Class<R> resultType, org.bson.BsonDocument result, boolean isDtoProjection) -
convertUsingIntrospected
protected <R> Optional<R> convertUsingIntrospected(PreparedQuery<?, ?> preparedQuery, org.bson.BsonDocument result, Class<R> resultType) Attempts to convert a BSON document into an instance of the specified result type using introspection.If the result type has been annotated with `@Introspection`, this method will attempt to use the provided `BeanIntrospection` to map the BSON document onto an instance of the result type.
If the mapping fails or if no `BeanIntrospection` is found for the result type, an empty `Optional` is returned.
- Type Parameters:
R- The type parameter representing the result type- Parameters:
preparedQuery- The preparedQueryresult- The BSON document containing the data to be mappedresultType- The type of the object being mapped- Returns:
- An `Optional` containing the mapped object, or an empty `Optional` if mapping failed or no `BeanIntrospection` was found
-
association
protected org.bson.BsonDocument association(org.bson.codecs.configuration.CodecRegistry codecRegistry, Object value, RuntimePersistentEntity<Object> persistentEntity, Object child, RuntimePersistentEntity<Object> childPersistentEntity) -
createFilterIdAndVersion
protected final <T> org.bson.conversions.Bson createFilterIdAndVersion(RuntimePersistentEntity<T> persistentEntity, T entity, org.bson.codecs.configuration.CodecRegistry codecRegistry) -
logFind
-
logAggregate
-