Class AbstractQueryInterceptor<T,R>
java.lang.Object
io.micronaut.data.runtime.intercept.AbstractQueryInterceptor<T,R>
- Type Parameters:
T- The declaring typeR- The return type
- All Implemented Interfaces:
DataInterceptor<T,R>
- Direct Known Subclasses:
AbstractAsyncInterceptor, AbstractReactiveInterceptor, AbstractSpecificationInterceptor, DefaultAbstractFindPageInterceptor, DefaultCountInterceptor, DefaultDeleteAllInterceptor, DefaultDeleteAllReturningInterceptor, DefaultDeleteOneInterceptor, DefaultDeleteReturningManyAsyncInterceptor, DefaultDeleteReturningManyInterceptor, DefaultDeleteReturningOneInterceptor, DefaultExistsByInterceptor, DefaultFindAllInterceptor, DefaultFindByIdInterceptor, DefaultFindOneInterceptor, DefaultFindOptionalInterceptor, DefaultFindSliceInterceptor, DefaultFindStreamInterceptor, DefaultInsertAllInterceptor, DefaultInsertEntityInterceptor, DefaultInsertOneInterceptor, DefaultInsertReturningManyAsyncInterceptor, DefaultInsertReturningManyInterceptor, DefaultInsertReturningOneInterceptor, DefaultProcedureReturningManyAsyncInterceptor, DefaultProcedureReturningManyInterceptor, DefaultProcedureReturningOneInterceptor, DefaultSaveAllInterceptor, DefaultSaveEntityInterceptor, DefaultSaveOneInterceptor, DefaultUpdateAllEntitiesInterceptor, DefaultUpdateEntityInterceptor, DefaultUpdateInterceptor, DefaultUpdateReturningManyAsyncInterceptor, DefaultUpdateReturningManyInterceptor, DefaultUpdateReturningOneInterceptor, DetachInterceptor, FlushInterceptor, LoadInterceptor, MergeInterceptor, PersistInterceptor, RefreshInterceptor, RemoveInterceptor
Abstract interceptor that executes a
Query.- Since:
- 1.0
- Author:
- graemerocher
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumThe operation selected for a save invocation. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.micronaut.core.convert.ConversionServiceprotected final RepositoryOperationsprotected final PreparedQueryResolver -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractQueryInterceptor(@NonNull RepositoryOperations operations) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected final @Nullable ObjectconvertOne(io.micronaut.aop.MethodInvocationContext<?, ?> context, @Nullable Object o) protected final ObjectconvertOne(Object o, io.micronaut.core.type.Argument<?> argumentType) protected intCount the items.findEntitiesParameter(io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull Class<RT> type) Fid an entities parameter value in role.protected <RT> Optional<RT> findEntityParameter(io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull Class<RT> type) Find an entity parameter value in role.protected final <O> @Nullable OfindRepositoryOperations(@NonNull Class<O> operationsType) Finds the requested repository operations from the root operations or one of its async/reactive variants.protected <E> @NonNull DeleteBatchOperation<E> getDeleteAllBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context) Get the delete all batch operation for the given context.protected <E> @NonNull DeleteBatchOperation<E> getDeleteBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, @NonNull Iterable<E> iterable) Get the delete batch operation for the given context.protected <E> @NonNull DeleteBatchOperation<E> getDeleteBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, Class<E> rootEntity, @NonNull Iterable<E> iterable) Get the delete batch operation for the given context.protected <E> @NonNull DeleteOperation<E> getDeleteOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, @NonNull E entity) Get the delete operation for the given context.protected <E,K> @NonNull DeleteReturningBatchOperation <E, K> getDeleteReturningBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, @NonNull Iterable<E> iterable) Get the delete returning batch operation for the given context.protected <E,K> @NonNull DeleteReturningOperation <E, K> getDeleteReturningOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, @NonNull E entity) Get the delete operation for the given context.protected <RT> Iterable<RT> getEntitiesParameter(io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull Class<RT> type) Retrieve an entities parameter value in role.protected <RT> RTgetEntityParameter(io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull Class<RT> type) Retrieve an entity parameter value in role.protected <E> @NonNull InsertBatchOperation<E> getInsertBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext context, @NonNull Iterable<E> iterable) Get the insert batch operation for the given context.protected <E> @NonNull InsertBatchOperation<E> getInsertBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext context, Class<E> rootEntity, @NonNull Iterable<E> iterable) Get the insert batch operation for the given context.protected <E> @NonNull InsertOperation<E> getInsertOperation(@NonNull io.micronaut.aop.MethodInvocationContext context) Get the batch operation for the given context.protected <E> @NonNull InsertOperation<E> getInsertOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, E entity) Get the batch operation for the given context.protected intgetLimit(io.micronaut.aop.MethodInvocationContext<?, ?> context) Resolves the limit.protected intgetOffset(io.micronaut.aop.MethodInvocationContext<?, ?> context) Resolves the offset.protected @NonNull PageablegetPageable(io.micronaut.aop.MethodInvocationContext<?, ?> context) Resolves thePageablefor the given context.protected @Nullable PageablegetPageableInRole(io.micronaut.aop.MethodInvocationContext<?, ?> context) Resolves thePageablefor the given context.protected <E> @NonNull PagedQuery<E> getPagedQuery(@NonNull io.micronaut.aop.MethodInvocationContext context) Get the paged query for the given context.protected <RT> Optional<RT> getParameterInRole(io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull String role, @NonNull io.micronaut.core.type.Argument<RT> type) Retrieve a parameter in the given role for the given type.protected <RT> Optional<RT> getParameterInRole(io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull String role, @NonNull Class<RT> type) Retrieve a parameter in the given role for the given type.protected <RT> @NonNull List<RT> getParametersInRole(@NonNull io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull String role, @NonNull io.micronaut.core.type.Argument<RT> type) Retrieve a parameter in the given role for the given type.protected <RT> @NonNull List<RT> getParametersInRole(@NonNull io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull String role, @NonNull Class<RT> type) Retrieve a parameter in the given role for the given type.getParameterValueMap(io.micronaut.aop.MethodInvocationContext<?, ?> context) Returns parameter values with respect ofParameterannotation.protected @NonNull ObjectgetRequiredEntity(io.micronaut.aop.MethodInvocationContext<T, ?> context) Looks up the entity to persist from the execution context, or throws an exception.protected <RT> RTgetRequiredParameterInRole(io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull String role, @NonNull Class<RT> type) Retrieve a parameter in the given role for the given type.protected <E> @NonNull Class<E> getRequiredRootEntity(io.micronaut.aop.MethodInvocationContext context) Obtains the root entity or throws an exception if it is not available.protected io.micronaut.core.type.Argument<?> getReturnType(io.micronaut.aop.MethodInvocationContext<?, ?> context) Returns the return type.protected <E> @NonNull UpdateBatchOperation<E> getUpdateAllBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, Class<E> rootEntity, @NonNull Iterable<E> iterable) Get the update all batch operation for the given context.protected <E> @NonNull UpdateOperation<E> getUpdateOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context) Get the batch operation for the given context.protected <E> @NonNull UpdateOperation<E> getUpdateOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, E entity) Get the batch operation for the given context.protected final booleanhasEntityId(io.micronaut.aop.MethodInvocationContext<?, ?> context, Object entity) Whether the entity has a non-null identity value.protected booleanhasReturnTypeInRole(@NonNull io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull String role, @NonNull Class<?> type) Check the return role from the method context.protected @NonNull ObjectinstantiateEntity(@NonNull Class<?> rootEntity, @NonNull Map<String, Object> parameterValues) Instantiate the given entity for the given parameter values.protected final booleanisEntityExistsException(io.micronaut.aop.MethodInvocationContext<?, ?> context, RuntimeException exception) protected final booleanisEntityUpdateCandidate(io.micronaut.aop.MethodInvocationContext<?, ?> context, Object entity) Whether the entity should be updated instead of inserted.protected booleanIs the type a number.protected final booleanprotected final booleanprotected final <E> EpersistOrUpdate(io.micronaut.aop.MethodInvocationContext<T, ?> context, E entity) Persists a new entity, or updates an entity that already has an identity.protected final <E> EpersistWithUpdateFallback(io.micronaut.aop.MethodInvocationContext<T, ?> context, E entity) Persists the entity and falls back to update when the configured exception conversion identifies that the insert failed because the entity already exists.protected final @NonNull PreparedQuery<?, Number> prepareCountQuery(RepositoryMethodKey methodKey, @NonNull io.micronaut.aop.MethodInvocationContext<T, R> context) Prepares a query for the given context.protected final <RT> @NonNull PreparedQuery<?, RT> prepareQuery(RepositoryMethodKey methodKey, io.micronaut.aop.MethodInvocationContext<T, R> context) Prepares a query for the given context.protected final RuntimeExceptionprotected final AbstractQueryInterceptor.SaveOperationresolveSaveOperation(io.micronaut.aop.MethodInvocationContext<?, ?> context, Object entity) Resolve whether save should insert or update the entity.protected final ThrowableunwrapCompletionException(Throwable throwable) protected final voidvalidateNullArguments(io.micronaut.aop.MethodInvocationContext<?, ?> context) Validates null arguments ensuring no argument is null unless declared so.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DataInterceptor
intercept
-
Field Details
-
conversionService
protected final io.micronaut.core.convert.ConversionService conversionService -
operations
-
preparedQueryResolver
-
-
Constructor Details
-
AbstractQueryInterceptor
Default constructor.- Parameters:
operations- The operations
-
-
Method Details
-
findRepositoryOperations
@Internal protected final <O> @Nullable O findRepositoryOperations(@NonNull Class<O> operationsType) Finds the requested repository operations from the root operations or one of its async/reactive variants.- Type Parameters:
O- The operations type- Parameters:
operationsType- The operations type- Returns:
- The operations, if available
- Since:
- 5.0.0
-
getParameterValueMap
-
getReturnType
protected io.micronaut.core.type.Argument<?> getReturnType(io.micronaut.aop.MethodInvocationContext<?, ?> context) Returns the return type.- Parameters:
context- The context- Returns:
- the return type
-
convertOne
-
convertOne
-
prepareQuery
protected final <RT> @NonNull PreparedQuery<?,RT> prepareQuery(RepositoryMethodKey methodKey, io.micronaut.aop.MethodInvocationContext<T, R> context) Prepares a query for the given context.- Type Parameters:
RT- The result generic type- Parameters:
methodKey- The method keycontext- The context- Returns:
- The query
-
prepareCountQuery
protected final @NonNull PreparedQuery<?,Number> prepareCountQuery(RepositoryMethodKey methodKey, @NonNull io.micronaut.aop.MethodInvocationContext<T, R> context) Prepares a query for the given context.- Parameters:
methodKey- The method keycontext- The context- Returns:
- The query
-
getRequiredRootEntity
protected <E> @NonNull Class<E> getRequiredRootEntity(io.micronaut.aop.MethodInvocationContext context) Obtains the root entity or throws an exception if it is not available.- Type Parameters:
E- The entity type- Parameters:
context- The context- Returns:
- The root entity type
- Throws:
IllegalStateException- If the root entity is unavailable
-
getEntityParameter
protected <RT> RT getEntityParameter(io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull Class<RT> type) Retrieve an entity parameter value in role.- Type Parameters:
RT- The generic type- Parameters:
context- The contexttype- The type- Returns:
- An result
-
getEntitiesParameter
-
findEntityParameter
-
findEntitiesParameter
-
getRequiredParameterInRole
protected <RT> RT getRequiredParameterInRole(io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull String role, @NonNull Class<RT> type) Retrieve a parameter in the given role for the given type.- Type Parameters:
RT- The generic type- Parameters:
context- The contextrole- The roletype- The type- Returns:
- An result
-
getParameterInRole
protected <RT> Optional<RT> getParameterInRole(io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull String role, @NonNull Class<RT> type) Retrieve a parameter in the given role for the given type.- Type Parameters:
RT- The generic type- Parameters:
context- The contextrole- The roletype- The type- Returns:
- An optional result
-
getParameterInRole
protected <RT> Optional<RT> getParameterInRole(io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull String role, @NonNull io.micronaut.core.type.Argument<RT> type) Retrieve a parameter in the given role for the given type.- Type Parameters:
RT- The generic type- Parameters:
context- The contextrole- The roletype- The type- Returns:
- An optional result
-
getParametersInRole
protected <RT> @NonNull List<RT> getParametersInRole(@NonNull io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull String role, @NonNull Class<RT> type) Retrieve a parameter in the given role for the given type.- Type Parameters:
RT- The generic type- Parameters:
context- The contextrole- The roletype- The type- Returns:
- An optional result
-
getParametersInRole
protected <RT> @NonNull List<RT> getParametersInRole(@NonNull io.micronaut.aop.MethodInvocationContext<?, ?> context, @NonNull String role, @NonNull io.micronaut.core.type.Argument<RT> type) Retrieve a parameter in the given role for the given type.- Type Parameters:
RT- The generic type- Parameters:
context- The contextrole- The roletype- The type- Returns:
- An optional result
-
hasReturnTypeInRole
-
getPageable
-
getPageableInRole
-
getOffset
protected int getOffset(io.micronaut.aop.MethodInvocationContext<?, ?> context) Resolves the offset.- Parameters:
context- The context- Returns:
- The offset or -1
- Since:
- 4.10
-
getLimit
protected int getLimit(io.micronaut.aop.MethodInvocationContext<?, ?> context) Resolves the limit.- Parameters:
context- The context- Returns:
- The limit or -1
- Since:
- 4.10
-
hasEntityId
protected final boolean hasEntityId(io.micronaut.aop.MethodInvocationContext<?, ?> context, Object entity) Whether the entity has a non-null identity value.- Parameters:
context- The method invocation contextentity- The entity instance- Returns:
- True if the entity has an ID value
-
isEntityUpdateCandidate
protected final boolean isEntityUpdateCandidate(io.micronaut.aop.MethodInvocationContext<?, ?> context, Object entity) Whether the entity should be updated instead of inserted.- Parameters:
context- The method invocation contextentity- The entity instance- Returns:
- True if the entity has enough state to use the update query
-
isSaveAsInsert
protected final boolean isSaveAsInsert()- Returns:
- Whether save methods should always perform insert operations.
-
isSaveAssignedIdFallbackToUpdate
protected final boolean isSaveAssignedIdFallbackToUpdate()- Returns:
- Whether save should fall back to update when insert detects an existing assigned-ID entity.
-
resolveSaveOperation
protected final AbstractQueryInterceptor.SaveOperation resolveSaveOperation(io.micronaut.aop.MethodInvocationContext<?, ?> context, Object entity) Resolve whether save should insert or update the entity.- Parameters:
context- The method invocation contextentity- The entity instance- Returns:
- The selected save operation
-
persistOrUpdate
protected final <E> E persistOrUpdate(io.micronaut.aop.MethodInvocationContext<T, ?> context, E entity) Persists a new entity, or updates an entity that already has an identity.- Type Parameters:
E- The entity type- Parameters:
context- The method invocation contextentity- The entity- Returns:
- The persisted or updated entity
-
persistWithUpdateFallback
protected final <E> E persistWithUpdateFallback(io.micronaut.aop.MethodInvocationContext<T, ?> context, E entity) Persists the entity and falls back to update when the configured exception conversion identifies that the insert failed because the entity already exists.- Type Parameters:
E- The entity type- Parameters:
context- The method invocation contextentity- The entity- Returns:
- The persisted or updated entity
-
isEntityExistsException
protected final boolean isEntityExistsException(io.micronaut.aop.MethodInvocationContext<?, ?> context, RuntimeException exception) -
unwrapCompletionException
-
propagate
-
getRequiredEntity
-
instantiateEntity
protected @NonNull Object instantiateEntity(@NonNull Class<?> rootEntity, @NonNull Map<String, Object> parameterValues) Instantiate the given entity for the given parameter values.- Parameters:
rootEntity- The entityparameterValues- The parameter values- Returns:
- The entity
- Throws:
IllegalArgumentException- if the entity cannot be instantiated due to an illegal argument
-
getPagedQuery
protected <E> @NonNull PagedQuery<E> getPagedQuery(@NonNull io.micronaut.aop.MethodInvocationContext context) Get the paged query for the given context.- Type Parameters:
E- The entity type- Parameters:
context- The context- Returns:
- The paged query
-
getInsertBatchOperation
protected <E> @NonNull InsertBatchOperation<E> getInsertBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext context, @NonNull Iterable<E> iterable) Get the insert batch operation for the given context.- Type Parameters:
E- The entity type- Parameters:
context- The contextiterable- The iterable- Returns:
- The paged query
-
getInsertBatchOperation
protected <E> @NonNull InsertBatchOperation<E> getInsertBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext context, Class<E> rootEntity, @NonNull Iterable<E> iterable) Get the insert batch operation for the given context.- Type Parameters:
E- The entity type- Parameters:
context- The contextrootEntity- The root entityiterable- The iterable- Returns:
- The paged query
-
getInsertOperation
protected <E> @NonNull InsertOperation<E> getInsertOperation(@NonNull io.micronaut.aop.MethodInvocationContext context) Get the batch operation for the given context.- Type Parameters:
E- The entity type- Parameters:
context- The context- Returns:
- The paged query
-
getUpdateOperation
protected <E> @NonNull UpdateOperation<E> getUpdateOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context) Get the batch operation for the given context.- Type Parameters:
E- The entity type- Parameters:
context- The context- Returns:
- The paged query
-
getUpdateOperation
protected <E> @NonNull UpdateOperation<E> getUpdateOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, E entity) Get the batch operation for the given context.- Type Parameters:
E- The entity type- Parameters:
context- The contextentity- The entity instance- Returns:
- The paged query
-
getUpdateAllBatchOperation
protected <E> @NonNull UpdateBatchOperation<E> getUpdateAllBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, Class<E> rootEntity, @NonNull Iterable<E> iterable) Get the update all batch operation for the given context.- Type Parameters:
E- The entity type- Parameters:
context- The contextrootEntity- The root entitryiterable- The iterable- Returns:
- The paged query
-
getDeleteOperation
protected <E> @NonNull DeleteOperation<E> getDeleteOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, @NonNull E entity) Get the delete operation for the given context.- Type Parameters:
E- The entity type- Parameters:
context- The contextentity- The entity- Returns:
- The paged query
-
getDeleteReturningOperation
protected <E,K> @NonNull DeleteReturningOperation<E,K> getDeleteReturningOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, @NonNull E entity) Get the delete operation for the given context.- Type Parameters:
E- The entity typeK- The result type- Parameters:
context- The contextentity- The entity- Returns:
- The paged query
-
getDeleteAllBatchOperation
protected <E> @NonNull DeleteBatchOperation<E> getDeleteAllBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context) Get the delete all batch operation for the given context.- Type Parameters:
E- The entity type- Parameters:
context- The context- Returns:
- The paged query
-
getDeleteBatchOperation
protected <E> @NonNull DeleteBatchOperation<E> getDeleteBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, @NonNull Iterable<E> iterable) Get the delete batch operation for the given context.- Type Parameters:
E- The entity type- Parameters:
context- The contextiterable- The iterable- Returns:
- The paged query
-
getDeleteReturningBatchOperation
protected <E,K> @NonNull DeleteReturningBatchOperation<E,K> getDeleteReturningBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, @NonNull Iterable<E> iterable) Get the delete returning batch operation for the given context.- Type Parameters:
E- The entity typeK- The result type- Parameters:
context- The contextiterable- The iterable- Returns:
- The paged query
-
getDeleteBatchOperation
protected <E> @NonNull DeleteBatchOperation<E> getDeleteBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, Class<E> rootEntity, @NonNull Iterable<E> iterable) Get the delete batch operation for the given context.- Type Parameters:
E- The entity type- Parameters:
context- The contextrootEntity- The root entityiterable- The iterable- Returns:
- The paged query
-
getInsertOperation
protected <E> @NonNull InsertOperation<E> getInsertOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T, ?> context, E entity) Get the batch operation for the given context.- Type Parameters:
E- The entity type- Parameters:
context- The contextentity- The entity- Returns:
- The paged query
-
validateNullArguments
protected final void validateNullArguments(io.micronaut.aop.MethodInvocationContext<?, ?> context) Validates null arguments ensuring no argument is null unless declared so.- Parameters:
context- The context
-
count
Count the items.- Parameters:
iterable- the iterable- Returns:
- the size
-
isNumber
Is the type a number.- Parameters:
type- The type- Returns:
- True if is a number
-