Class DefaultMongoRepositoryOperations
java.lang.Object
io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperations
io.micronaut.data.mongodb.operations.DefaultMongoRepositoryOperations
- All Implemented Interfaces:
io.micronaut.context.ApplicationContextProvider
,io.micronaut.core.convert.ConversionServiceProvider
,MongoRepositoryOperations
,AsyncCapableRepository
,HintsCapableRepository
,ReactiveCapableRepository
,RepositoryOperations
,SyncCascadeOperations.SyncCascadeOperationsHelper<DefaultMongoRepositoryOperations.MongoOperationContext>
,MethodContextAwareStoredQueryDecorator
,PreparedQueryDecorator
@RequiresSyncMongo
@EachBean(com.mongodb.client.MongoClient.class)
@Internal
public final class DefaultMongoRepositoryOperations
extends AbstractRepositoryOperations
implements MongoRepositoryOperations, AsyncCapableRepository, ReactiveCapableRepository, SyncCascadeOperations.SyncCascadeOperationsHelper<DefaultMongoRepositoryOperations.MongoOperationContext>
Default Mongo repository operations.
- Since:
- 3.3
- Author:
- Denis Stepanov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final MongoCollectionNameProvider
protected final MongoDatabaseNameProvider
protected static final org.bson.BsonDocument
protected static final org.slf4j.Logger
Fields inherited from class io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperations
attributeConverterRegistry, conversionService, dateTimeProvider, entityEventRegistry, runtimeEntityRegistry
-
Method Summary
Modifier and TypeMethodDescriptionprotected org.bson.BsonDocument
association
(org.bson.codecs.configuration.CodecRegistry codecRegistry, Object value, RuntimePersistentEntity<Object> persistentEntity, Object child, RuntimePersistentEntity<Object> childPersistentEntity) async()
protected <R> R
convertResult
(org.bson.codecs.configuration.CodecRegistry codecRegistry, Class<R> resultType, org.bson.BsonDocument result, boolean isDtoProjection) <T> long
count
(PagedQuery<T> pagedQuery) Counts all results for the given query.protected final <T> org.bson.conversions.Bson
createFilterIdAndVersion
(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> int
delete
(DeleteOperation<T> operation) Deletes the entity.deleteAll
(DeleteBatchOperation<T> operation) Deletes all the entities of the given type.executeDelete
(PreparedQuery<?, Number> preparedQuery) Executes a delete for the given query and parameter values.executeUpdate
(PreparedQuery<?, Number> preparedQuery) Executes an update for the given query and parameter values.<T> boolean
exists
(PreparedQuery<T, Boolean> preparedQuery) Execute a query that checks for existence.<T> Iterable<T>
findAll
(PagedQuery<T> query) Finds all results for the given query.<T,
R> Iterable<R> findAll
(PreparedQuery<T, R> preparedQuery) Finds all results for the given query.<T,
R> R findOne
(PreparedQuery<T, R> preparedQuery) Find one by Query.<T> T
findOne
(Class<T> type, Serializable id) Find one by ID.<R> Page<R>
findPage
(PagedQuery<R> query) Find a page for the given entity and pageable.<T> Stream<T>
findStream
(PagedQuery<T> query) Finds a stream for the given arguments.<T,
R> Stream<R> findStream
(PreparedQuery<T, R> preparedQuery) Finds all results for the given query.protected org.bson.codecs.configuration.CodecRegistry
getCodecRegistry
(com.mongodb.client.MongoDatabase mongoDatabase) protected com.mongodb.client.MongoDatabase
getDatabase
(PersistentEntity persistentEntity, Class<?> repositoryClass) protected final com.mongodb.client.model.DeleteOptions
getDeleteOptions
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) protected final com.mongodb.client.model.InsertManyOptions
getInsertManyOptions
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) protected final com.mongodb.client.model.InsertOneOptions
getInsertOneOptions
(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.ReplaceOptions
getReplaceOptions
(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) protected void
logAggregate
(MongoAggregation aggregation) protected void
<T> T
persist
(InsertOperation<T> operation) Persist the operation returning a possibly new entity.<T> Iterable<T>
persistAll
(InsertBatchOperation<T> operation) Persist all the given entities.<T> List<T>
persistBatch
(DefaultMongoRepositoryOperations.MongoOperationContext ctx, Iterable<T> values, RuntimePersistentEntity<T> persistentEntity, Predicate<T> predicate) Persist multiple entities in batch during cascade.void
persistManyAssociation
(DefaultMongoRepositoryOperations.MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, Object value, RuntimePersistentEntity<Object> persistentEntity, Object child, RuntimePersistentEntity<Object> childPersistentEntity) Persist JOIN table relationship.void
persistManyAssociationBatch
(DefaultMongoRepositoryOperations.MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, Object value, RuntimePersistentEntity<Object> persistentEntity, Iterable<Object> child, RuntimePersistentEntity<Object> childPersistentEntity) Persist JOIN table relationships in batch.<T> T
persistOne
(DefaultMongoRepositoryOperations.MongoOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity) Persist one entity during cascade.reactive()
<T> T
update
(UpdateOperation<T> operation) Updates the entity for the given operation.<T> Iterable<T>
updateAll
(UpdateBatchOperation<T> operation) Updates the entities for the given operation.<T> T
updateOne
(DefaultMongoRepositoryOperations.MongoOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity) Update one entity during cascade.Methods inherited from class io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperations
checkOptimisticLocking, getApplicationContext, getConversionService, getEntity, getIdReader, isOnlySingleEndedJoins, triggerPostLoad
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.context.ApplicationContextProvider
getApplicationContext
Methods inherited from interface io.micronaut.core.convert.ConversionServiceProvider
getConversionService
Methods inherited from interface io.micronaut.data.operations.HintsCapableRepository
getQueryHints
Methods inherited from interface io.micronaut.data.operations.RepositoryOperations
getEntity
Methods inherited from interface io.micronaut.data.runtime.operations.internal.SyncCascadeOperations.SyncCascadeOperationsHelper
isSupportsBatchDelete, isSupportsBatchInsert, isSupportsBatchUpdate
-
Field Details
-
EMPTY
protected static final org.bson.BsonDocument EMPTY -
QUERY_LOG
protected static final org.slf4j.Logger QUERY_LOG -
collectionNameProvider
-
databaseNameProvider
-
-
Method Details
-
findOne
Description copied from interface:RepositoryOperations
Find one by ID.- Specified by:
findOne
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
type
- The typeid
- The id- Returns:
- A result or null
-
findOne
Description copied from interface:RepositoryOperations
Find one by Query.- Specified by:
findOne
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic resultTypeR
- The result type- Parameters:
preparedQuery
- The prepared query- Returns:
- A result or null
-
exists
Description copied from interface:RepositoryOperations
Execute a query that checks for existence.- Specified by:
exists
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic resultType- Parameters:
preparedQuery
- The prepared query- Returns:
- A result or null
-
findAll
Description copied from interface:RepositoryOperations
Finds all results for the given query.- Specified by:
findAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
query
- The root entity- Returns:
- An iterable result
-
count
Description copied from interface:RepositoryOperations
Counts all results for the given query.- Specified by:
count
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
pagedQuery
- The paged query- Returns:
- An iterable result
-
findStream
Description copied from interface:RepositoryOperations
Finds a stream for the given arguments.- Specified by:
findStream
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
query
- The query- Returns:
- The stream
-
findPage
Description copied from interface:RepositoryOperations
Find a page for the given entity and pageable.- Specified by:
findPage
in interfaceRepositoryOperations
- Type Parameters:
R
- The entity generic type- Parameters:
query
- The query- Returns:
- The page type
-
findAll
Description copied from interface:RepositoryOperations
Finds all results for the given query.- Specified by:
findAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The entity typeR
- The result type- Parameters:
preparedQuery
- The prepared query- Returns:
- An iterable result
-
findStream
Description copied from interface:RepositoryOperations
Finds all results for the given query.- Specified by:
findStream
in interfaceRepositoryOperations
- Type Parameters:
T
- The entity typeR
- The result type- Parameters:
preparedQuery
- The prepared query- Returns:
- An iterable result
-
persist
Description copied from interface:RepositoryOperations
Persist the operation returning a possibly new entity.- Specified by:
persist
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The operation
-
persistAll
Description copied from interface:RepositoryOperations
Persist all the given entities.- Specified by:
persistAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The entities, possibly mutated
-
update
Description copied from interface:RepositoryOperations
Updates the entity for the given operation.- Specified by:
update
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The operation
-
updateAll
Description copied from interface:RepositoryOperations
Updates the entities for the given operation.- Specified by:
updateAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The updated entities
-
delete
Description copied from interface:RepositoryOperations
Deletes the entity.- Specified by:
delete
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The number of entities deleted
-
deleteAll
Description copied from interface:RepositoryOperations
Deletes all the entities of the given type.- Specified by:
deleteAll
in interfaceRepositoryOperations
- Type Parameters:
T
- The generic type- Parameters:
operation
- The operation- Returns:
- The number of entities deleted
-
executeUpdate
Description copied from interface:RepositoryOperations
Executes 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:
executeUpdate
in interfaceRepositoryOperations
- Parameters:
preparedQuery
- The prepared query- Returns:
- An optional number with the count of the number of records updated
-
executeDelete
Description copied from interface:RepositoryOperations
Executes a delete for the given query and parameter values. If it is possible to return the number of objects deleted, then do so.- Specified by:
executeDelete
in interfaceRepositoryOperations
- Parameters:
preparedQuery
- The prepared query- Returns:
- An optional number with the count of the number of records updated
-
getDatabase
protected com.mongodb.client.MongoDatabase getDatabase(PersistentEntity persistentEntity, Class<?> repositoryClass) -
getCodecRegistry
protected org.bson.codecs.configuration.CodecRegistry getCodecRegistry(com.mongodb.client.MongoDatabase mongoDatabase) -
persistOne
public <T> T persistOne(DefaultMongoRepositoryOperations.MongoOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity) Description copied from interface:SyncCascadeOperations.SyncCascadeOperationsHelper
Persist one entity during cascade.- Specified by:
persistOne
in interfaceSyncCascadeOperations.SyncCascadeOperationsHelper<DefaultMongoRepositoryOperations.MongoOperationContext>
- Type Parameters:
T
- The entity type- Parameters:
ctx
- The contextvalue
- The entity valuepersistentEntity
- The persistent entity- Returns:
- The entity value
-
persistBatch
public <T> List<T> persistBatch(DefaultMongoRepositoryOperations.MongoOperationContext ctx, Iterable<T> values, RuntimePersistentEntity<T> persistentEntity, Predicate<T> predicate) Description copied from interface:SyncCascadeOperations.SyncCascadeOperationsHelper
Persist multiple entities in batch during cascade.- Specified by:
persistBatch
in interfaceSyncCascadeOperations.SyncCascadeOperationsHelper<DefaultMongoRepositoryOperations.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> T updateOne(DefaultMongoRepositoryOperations.MongoOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity) Description copied from interface:SyncCascadeOperations.SyncCascadeOperationsHelper
Update one entity during cascade.- Specified by:
updateOne
in interfaceSyncCascadeOperations.SyncCascadeOperationsHelper<DefaultMongoRepositoryOperations.MongoOperationContext>
- Type Parameters:
T
- The entity type- Parameters:
ctx
- The contextvalue
- The entity valuepersistentEntity
- The persistent entity- Returns:
- The entity value
-
persistManyAssociation
public void persistManyAssociation(DefaultMongoRepositoryOperations.MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, Object value, RuntimePersistentEntity<Object> persistentEntity, Object child, RuntimePersistentEntity<Object> childPersistentEntity) Description copied from interface:SyncCascadeOperations.SyncCascadeOperationsHelper
Persist JOIN table relationship.- Specified by:
persistManyAssociation
in interfaceSyncCascadeOperations.SyncCascadeOperationsHelper<DefaultMongoRepositoryOperations.MongoOperationContext>
- Parameters:
ctx
- The contextruntimeAssociation
- The associationvalue
- The parent entity valuepersistentEntity
- The parent persistent entitychild
- The child entity valuechildPersistentEntity
- The child persistent entity
-
persistManyAssociationBatch
public void persistManyAssociationBatch(DefaultMongoRepositoryOperations.MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, Object value, RuntimePersistentEntity<Object> persistentEntity, Iterable<Object> child, RuntimePersistentEntity<Object> childPersistentEntity) Description copied from interface:SyncCascadeOperations.SyncCascadeOperationsHelper
Persist JOIN table relationships in batch.- Specified by:
persistManyAssociationBatch
in interfaceSyncCascadeOperations.SyncCascadeOperationsHelper<DefaultMongoRepositoryOperations.MongoOperationContext>
- Parameters:
ctx
- The contextruntimeAssociation
- The associationvalue
- The parent entity valuepersistentEntity
- The parent persistent entitychild
- The child entity valueschildPersistentEntity
- The child persistent entity
-
async
- Specified by:
async
in interfaceAsyncCapableRepository
- Returns:
- The async operations.
-
reactive
- Specified by:
reactive
in interfaceReactiveCapableRepository
- Returns:
- The reactive operations instance.
-
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:PreparedQueryDecorator
Decorate prepared query.- Specified by:
decorate
in 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:MethodContextAwareStoredQueryDecorator
Decorate stored query.- Specified by:
decorate
in 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(org.bson.codecs.configuration.CodecRegistry codecRegistry, Class<R> resultType, org.bson.BsonDocument result, boolean isDtoProjection) -
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
-