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 class
DefaultMongoRepositoryOperations.MongoOperationContext
-
Field Summary
Fields Modifier and Type Field Description protected MongoCollectionNameProvider
collectionNameProvider
protected MongoDatabaseNameProvider
databaseNameProvider
protected static org.bson.BsonDocument
EMPTY
protected static org.slf4j.Logger
QUERY_LOG
-
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.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)
ExecutorAsyncOperations
async()
protected <R> R
convertResult(org.bson.codecs.configuration.CodecRegistry codecRegistry, java.lang.Class<R> resultType, org.bson.BsonDocument result, boolean isDtoProjection)
<T> long
count(PagedQuery<T> pagedQuery)
Counts all results for the given query.protected <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.<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> boolean
exists(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> T
findOne(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.CodecRegistry
getCodecRegistry(com.mongodb.client.MongoDatabase mongoDatabase)
protected com.mongodb.client.MongoDatabase
getDatabase(PersistentEntity persistentEntity, java.lang.Class<?> repositoryClass)
protected com.mongodb.client.model.DeleteOptions
getDeleteOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
protected com.mongodb.client.model.InsertManyOptions
getInsertManyOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
protected 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 com.mongodb.client.model.ReplaceOptions
getReplaceOptions(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
protected void
logAggregate(MongoAggregation aggregation)
protected void
logFind(MongoFind find)
<T> T
persist(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.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)
Persist JOIN table relationship.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)
Persist JOIN table relationships in batch.<T> T
persistOne(DefaultMongoRepositoryOperations.MongoOperationContext ctx, T value, RuntimePersistentEntity<T> persistentEntity)
Persist one entity during cascade.ReactiveRepositoryOperations
reactive()
<T> T
update(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> 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.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
-
-
-
-
Field Detail
-
EMPTY
protected static final org.bson.BsonDocument EMPTY
-
QUERY_LOG
protected static final org.slf4j.Logger QUERY_LOG
-
collectionNameProvider
protected final MongoCollectionNameProvider collectionNameProvider
-
databaseNameProvider
protected final MongoDatabaseNameProvider databaseNameProvider
-
-
Method Detail
-
findOne
public <T> T findOne(java.lang.Class<T> type, java.io.Serializable id)
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
public <T,R> R findOne(PreparedQuery<T,R> preparedQuery)
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
public <T> boolean exists(PreparedQuery<T,java.lang.Boolean> preparedQuery)
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
public <T> java.lang.Iterable<T> findAll(PagedQuery<T> query)
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
public <T> long count(PagedQuery<T> pagedQuery)
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
public <T> java.util.stream.Stream<T> findStream(PagedQuery<T> query)
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
public <R> Page<R> findPage(PagedQuery<R> query)
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
public <T,R> java.lang.Iterable<R> findAll(PreparedQuery<T,R> preparedQuery)
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
public <T,R> java.util.stream.Stream<R> findStream(PreparedQuery<T,R> preparedQuery)
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
public <T> T persist(InsertOperation<T> operation)
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
public <T> java.lang.Iterable<T> persistAll(InsertBatchOperation<T> operation)
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
public <T> T update(UpdateOperation<T> operation)
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
public <T> java.lang.Iterable<T> updateAll(UpdateBatchOperation<T> operation)
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
public <T> int delete(DeleteOperation<T> operation)
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
public <T> java.util.Optional<java.lang.Number> deleteAll(DeleteBatchOperation<T> operation)
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
public java.util.Optional<java.lang.Number> executeUpdate(PreparedQuery<?,java.lang.Number> preparedQuery)
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
public java.util.Optional<java.lang.Number> executeDelete(PreparedQuery<?,java.lang.Number> preparedQuery)
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, 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.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> 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.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, java.lang.Object value, RuntimePersistentEntity<java.lang.Object> persistentEntity, java.lang.Object child, RuntimePersistentEntity<java.lang.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, 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.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
@NonNull public ExecutorAsyncOperations async()
- Specified by:
async
in interfaceAsyncCapableRepository
- Returns:
- The async operations.
-
reactive
@NonNull public ReactiveRepositoryOperations 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
protected <E,R> MongoStoredQuery<E,R> getMongoStoredQuery(StoredQuery<E,R> storedQuery)
-
getMongoPreparedQuery
protected <E,R> MongoPreparedQuery<E,R> getMongoPreparedQuery(PreparedQuery<E,R> preparedQuery)
-
decorate
public <E,R> PreparedQuery<E,R> decorate(PreparedQuery<E,R> preparedQuery)
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, 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)
-
-