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 MongoCollectionNameProviderprotected final MongoDatabaseNameProviderprotected static final org.bson.BsonDocumentprotected static final org.slf4j.LoggerFields inherited from class io.micronaut.data.runtime.operations.internal.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) async()protected <R> RconvertResult(org.bson.codecs.configuration.CodecRegistry codecRegistry, Class<R> resultType, org.bson.BsonDocument result, boolean isDtoProjection) <T> longcount(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> intdelete(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> booleanexists(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> TfindOne(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.CodecRegistrygetCodecRegistry(com.mongodb.client.MongoDatabase mongoDatabase) protected com.mongodb.client.MongoDatabasegetDatabase(PersistentEntity persistentEntity, Class<?> repositoryClass) 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> Tpersist(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.voidpersistManyAssociation(DefaultMongoRepositoryOperations.MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, Object value, RuntimePersistentEntity<Object> persistentEntity, Object child, RuntimePersistentEntity<Object> childPersistentEntity) Persist JOIN table relationship.voidpersistManyAssociationBatch(DefaultMongoRepositoryOperations.MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, Object value, RuntimePersistentEntity<Object> persistentEntity, Iterable<Object> child, RuntimePersistentEntity<Object> childPersistentEntity) Persist JOIN table relationships in batch.<T> TpersistOne(DefaultMongoRepositoryOperations.MongoOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity) Persist one entity during cascade.reactive()<T> Tupdate(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> TupdateOne(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, triggerPostLoadMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.context.ApplicationContextProvider
getApplicationContextMethods inherited from interface io.micronaut.core.convert.ConversionServiceProvider
getConversionServiceMethods inherited from interface io.micronaut.data.operations.HintsCapableRepository
getQueryHintsMethods inherited from interface io.micronaut.data.operations.RepositoryOperations
getEntityMethods 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:RepositoryOperationsFind one by ID.- Specified by:
findOnein interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
type- The typeid- The id- Returns:
- A result or null
-
findOne
Description copied from interface:RepositoryOperationsFind one by Query.- Specified by:
findOnein 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:RepositoryOperationsExecute a query that checks for existence.- Specified by:
existsin interfaceRepositoryOperations- Type Parameters:
T- The generic resultType- Parameters:
preparedQuery- The prepared query- Returns:
- A result or null
-
findAll
Description copied from interface:RepositoryOperationsFinds all results for the given query.- Specified by:
findAllin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
query- The root entity- Returns:
- An iterable result
-
count
Description copied from interface:RepositoryOperationsCounts all results for the given query.- Specified by:
countin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
pagedQuery- The paged query- Returns:
- An iterable result
-
findStream
Description copied from interface:RepositoryOperationsFinds a stream for the given arguments.- Specified by:
findStreamin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
query- The query- Returns:
- The stream
-
findPage
Description copied from interface:RepositoryOperationsFind a page for the given entity and pageable.- Specified by:
findPagein interfaceRepositoryOperations- Type Parameters:
R- The entity generic type- Parameters:
query- The query- Returns:
- The page type
-
findAll
Description copied from interface:RepositoryOperationsFinds all results for the given query.- Specified by:
findAllin interfaceRepositoryOperations- Type Parameters:
T- The entity typeR- The result type- Parameters:
preparedQuery- The prepared query- Returns:
- An iterable result
-
findStream
Description copied from interface:RepositoryOperationsFinds all results for the given query.- Specified by:
findStreamin interfaceRepositoryOperations- Type Parameters:
T- The entity typeR- The result type- Parameters:
preparedQuery- The prepared query- Returns:
- An iterable result
-
persist
Description copied from interface:RepositoryOperationsPersist the operation returning a possibly new entity.- Specified by:
persistin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The operation
-
persistAll
Description copied from interface:RepositoryOperationsPersist all the given entities.- Specified by:
persistAllin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The entities, possibly mutated
-
update
Description copied from interface:RepositoryOperationsUpdates the entity for the given operation.- Specified by:
updatein interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The operation
-
updateAll
Description copied from interface:RepositoryOperationsUpdates the entities for the given operation.- Specified by:
updateAllin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The updated entities
-
delete
Description copied from interface:RepositoryOperationsDeletes the entity.- Specified by:
deletein interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The number of entities deleted
-
deleteAll
Description copied from interface:RepositoryOperationsDeletes all the entities of the given type.- Specified by:
deleteAllin interfaceRepositoryOperations- Type Parameters:
T- The generic type- Parameters:
operation- The operation- Returns:
- The number of entities deleted
-
executeUpdate
Description copied from interface:RepositoryOperationsExecutes 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 interfaceRepositoryOperations- Parameters:
preparedQuery- The prepared query- Returns:
- An optional number with the count of the number of records updated
-
executeDelete
Description copied from interface:RepositoryOperationsExecutes 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:
executeDeletein 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.SyncCascadeOperationsHelperPersist one entity during cascade.- Specified by:
persistOnein 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.SyncCascadeOperationsHelperPersist multiple entities in batch during cascade.- Specified by:
persistBatchin 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.SyncCascadeOperationsHelperUpdate one entity during cascade.- Specified by:
updateOnein 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.SyncCascadeOperationsHelperPersist JOIN table relationship.- Specified by:
persistManyAssociationin 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.SyncCascadeOperationsHelperPersist JOIN table relationships in batch.- Specified by:
persistManyAssociationBatchin 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:
asyncin interfaceAsyncCapableRepository- Returns:
- The async operations.
-
reactive
- Specified by:
reactivein 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: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(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
-