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,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 Classes Modifier and Type Class Description protected static classDefaultMongoRepositoryOperations.MongoOperationContext
-
Field Summary
Fields Modifier and Type Field Description protected static org.bson.BsonDocumentEMPTYprotected static org.slf4j.LoggerQUERY_LOGprotected java.util.Map<java.lang.Class,java.lang.String>repoDatabaseConfig-
Fields inherited from class io.micronaut.data.runtime.operations.internal.AbstractRepositoryOperations
attributeConverterRegistry, conversionService, dateTimeProvider, entityEventRegistry, jsonCodec, runtimeEntityRegistry
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.bson.BsonDocumentassociation(org.bson.codecs.configuration.CodecRegistry codecRegistry, java.lang.Object value, RuntimePersistentEntity<java.lang.Object> persistentEntity, java.lang.Object child, RuntimePersistentEntity<java.lang.Object> childPersistentEntity)ExecutorAsyncOperationsasync()protected <R> RconvertResult(org.bson.codecs.configuration.CodecRegistry codecRegistry, java.lang.Class<R> resultType, org.bson.BsonDocument result, boolean isDtoProjection)<T> longcount(PagedQuery<T> pagedQuery)Counts all results for the given query.protected <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.<T> java.util.Optional<java.lang.Number>deleteAll(DeleteBatchOperation<T> operation)Deletes all the entities of the given type.java.util.Optional<java.lang.Number>executeDelete(PreparedQuery<?,java.lang.Number> preparedQuery)Executes a delete for the given query and parameter values.java.util.Optional<java.lang.Number>executeUpdate(PreparedQuery<?,java.lang.Number> preparedQuery)Executes an update for the given query and parameter values.<T> booleanexists(PreparedQuery<T,java.lang.Boolean> preparedQuery)Execute a query that checks for existence.<T> java.lang.Iterable<T>findAll(PagedQuery<T> query)Finds all results for the given query.<T,R>
java.lang.Iterable<R>findAll(PreparedQuery<T,R> preparedQuery)Finds all results for the given query.<T,R>
RfindOne(PreparedQuery<T,R> preparedQuery)Find one by Query.<T> TfindOne(java.lang.Class<T> type, java.io.Serializable id)Find one by ID.<R> Page<R>findPage(PagedQuery<R> query)Find a page for the given entity and pageable.<T> java.util.stream.Stream<T>findStream(PagedQuery<T> query)Finds a stream for the given arguments.<T,R>
java.util.stream.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(RuntimePersistentEntity<?> persistentEntity, java.lang.Class<?> repositoryClass)protected com.mongodb.client.model.DeleteOptionsgetDeleteOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)protected com.mongodb.client.model.InsertManyOptionsgetInsertManyOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)protected com.mongodb.client.model.InsertOneOptionsgetInsertOneOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)protected <E,R>
MongoPreparedQuery<E,R,Dtb>getMongoPreparedQuery(PreparedQuery<E,R> preparedQuery)protected <E,R>
MongoStoredQuery<E,R,Dtb>getMongoStoredQuery(StoredQuery<E,R> storedQuery)protected com.mongodb.client.model.ReplaceOptionsgetReplaceOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)protected voidlogAggregate(MongoAggregation aggregation)protected voidlogFind(MongoFind find)<T> Tpersist(InsertOperation<T> operation)Persist the operation returning a possibly new entity.<T> java.lang.Iterable<T>persistAll(InsertBatchOperation<T> operation)Persist all the given entities.<T> java.util.List<T>persistBatch(DefaultMongoRepositoryOperations.MongoOperationContext ctx, java.lang.Iterable<T> values, RuntimePersistentEntity<T> persistentEntity, java.util.function.Predicate<T> predicate)Persist multiple entities in batch during cascade.voidpersistManyAssociation(DefaultMongoRepositoryOperations.MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, java.lang.Object value, RuntimePersistentEntity<java.lang.Object> persistentEntity, java.lang.Object child, RuntimePersistentEntity<java.lang.Object> childPersistentEntity)Persist JOIN table relationship.voidpersistManyAssociationBatch(DefaultMongoRepositoryOperations.MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, java.lang.Object value, RuntimePersistentEntity<java.lang.Object> persistentEntity, java.lang.Iterable<java.lang.Object> child, RuntimePersistentEntity<java.lang.Object> childPersistentEntity)Persist JOIN table relationships in batch.<T> TpersistOne(DefaultMongoRepositoryOperations.MongoOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity)Persist one entity during cascade.ReactiveRepositoryOperationsreactive()<T> Tupdate(UpdateOperation<T> operation)Updates the entity for the given operation.<T> java.lang.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, 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.data.operations.HintsCapableRepository
getQueryHints
-
Methods inherited from interface io.micronaut.data.operations.RepositoryOperations
getConversionService, getEntity
-
Methods inherited from interface io.micronaut.data.runtime.operations.internal.SyncCascadeOperations.SyncCascadeOperationsHelper
isSupportsBatchDelete, isSupportsBatchInsert, isSupportsBatchUpdate
-
-
-
-
Method Detail
-
findOne
public <T> T findOne(java.lang.Class<T> type, java.io.Serializable id)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
public <T,R> R findOne(PreparedQuery<T,R> preparedQuery)
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
public <T> boolean exists(PreparedQuery<T,java.lang.Boolean> preparedQuery)
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
public <T> java.lang.Iterable<T> findAll(PagedQuery<T> query)
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
public <T> long count(PagedQuery<T> pagedQuery)
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
public <T> java.util.stream.Stream<T> findStream(PagedQuery<T> query)
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
public <R> Page<R> findPage(PagedQuery<R> query)
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
public <T,R> java.lang.Iterable<R> findAll(PreparedQuery<T,R> preparedQuery)
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
public <T,R> java.util.stream.Stream<R> findStream(PreparedQuery<T,R> preparedQuery)
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
public <T> T persist(InsertOperation<T> operation)
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
public <T> java.lang.Iterable<T> persistAll(InsertBatchOperation<T> operation)
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
public <T> T update(UpdateOperation<T> operation)
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
public <T> java.lang.Iterable<T> updateAll(UpdateBatchOperation<T> operation)
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
public <T> int delete(DeleteOperation<T> operation)
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
public <T> java.util.Optional<java.lang.Number> deleteAll(DeleteBatchOperation<T> operation)
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
public java.util.Optional<java.lang.Number> executeUpdate(PreparedQuery<?,java.lang.Number> preparedQuery)
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
public java.util.Optional<java.lang.Number> executeDelete(PreparedQuery<?,java.lang.Number> preparedQuery)
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(RuntimePersistentEntity<?> persistentEntity, java.lang.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> java.util.List<T> persistBatch(DefaultMongoRepositoryOperations.MongoOperationContext ctx, java.lang.Iterable<T> values, RuntimePersistentEntity<T> persistentEntity, java.util.function.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, java.lang.Object value, RuntimePersistentEntity<java.lang.Object> persistentEntity, java.lang.Object child, RuntimePersistentEntity<java.lang.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, java.lang.Object value, RuntimePersistentEntity<java.lang.Object> persistentEntity, java.lang.Iterable<java.lang.Object> child, RuntimePersistentEntity<java.lang.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
@NonNull public ExecutorAsyncOperations async()
- Specified by:
asyncin interfaceAsyncCapableRepository- Returns:
- The async operations.
-
reactive
@NonNull public ReactiveRepositoryOperations 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
protected <E,R> MongoStoredQuery<E,R,Dtb> getMongoStoredQuery(StoredQuery<E,R> storedQuery)
-
getMongoPreparedQuery
protected <E,R> MongoPreparedQuery<E,R,Dtb> getMongoPreparedQuery(PreparedQuery<E,R> preparedQuery)
-
decorate
public <E,R> PreparedQuery<E,R> decorate(PreparedQuery<E,R> preparedQuery)
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, java.lang.Class<R> resultType, org.bson.BsonDocument result, boolean isDtoProjection)
-
association
protected org.bson.BsonDocument association(org.bson.codecs.configuration.CodecRegistry codecRegistry, java.lang.Object value, RuntimePersistentEntity<java.lang.Object> persistentEntity, java.lang.Object child, RuntimePersistentEntity<java.lang.Object> childPersistentEntity)
-
createFilterIdAndVersion
protected final <T> org.bson.conversions.Bson createFilterIdAndVersion(RuntimePersistentEntity<T> persistentEntity, T entity, org.bson.codecs.configuration.CodecRegistry codecRegistry)
-
logFind
protected void logFind(MongoFind find)
-
logAggregate
protected void logAggregate(MongoAggregation aggregation)
-
-