Class AbstractQueryInterceptor<T,R>

java.lang.Object
io.micronaut.data.runtime.intercept.AbstractQueryInterceptor<T,R>
Type Parameters:
T - The declaring type
R - The return type
All Implemented Interfaces:
DataInterceptor<T,R>
Direct Known Subclasses:
AbstractAsyncInterceptor, AbstractReactiveInterceptor, AbstractSpecificationInterceptor, AbstractSpecificationInterceptor, DefaultCountInterceptor, DefaultDeleteAllInterceptor, DefaultDeleteAllReturningInterceptor, DefaultDeleteOneInterceptor, DefaultDeleteReturningManyInterceptor, DefaultDeleteReturningOneInterceptor, DefaultExistsByInterceptor, DefaultFindAllInterceptor, DefaultFindByIdInterceptor, DefaultFindOneInterceptor, DefaultFindOptionalInterceptor, DefaultFindPageInterceptor, DefaultFindSliceInterceptor, DefaultFindStreamInterceptor, DefaultInsertReturningManyInterceptor, DefaultInsertReturningOneInterceptor, DefaultProcedureReturningManyAsyncInterceptor, DefaultProcedureReturningManyInterceptor, DefaultProcedureReturningOneInterceptor, DefaultSaveAllInterceptor, DefaultSaveEntityInterceptor, DefaultSaveOneInterceptor, DefaultUpdateAllEntitiesInterceptor, DefaultUpdateEntityInterceptor, DefaultUpdateInterceptor, DefaultUpdateReturningManyInterceptor, DefaultUpdateReturningOneInterceptor, FindPageSpecificationInterceptor, FlushInterceptor, LoadInterceptor, MergeInterceptor

public abstract class AbstractQueryInterceptor<T,R> extends Object implements DataInterceptor<T,R>
Abstract interceptor that executes a Query.
Since:
1.0
Author:
graemerocher
  • Field Details

    • conversionService

      protected final io.micronaut.core.convert.ConversionService conversionService
    • operations

      protected final RepositoryOperations operations
    • preparedQueryResolver

      protected final PreparedQueryResolver preparedQueryResolver
  • Constructor Details

    • AbstractQueryInterceptor

      protected AbstractQueryInterceptor(@NonNull @NonNull RepositoryOperations operations)
      Default constructor.
      Parameters:
      operations - The operations
  • Method Details

    • getParameterValueMap

      @NonNull protected @NonNull Map<String,Object> getParameterValueMap(io.micronaut.aop.MethodInvocationContext<?,?> context)
      Returns parameter values with respect of Parameter annotation.
      Parameters:
      context - The method invocation context
      Returns:
      The parameters value map
    • 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

      @Nullable protected final @Nullable Object convertOne(io.micronaut.aop.MethodInvocationContext<?,?> context, @Nullable @Nullable Object o)
    • convertOne

      protected final Object convertOne(Object o, io.micronaut.core.type.Argument<?> argumentType)
    • prepareQuery

      @NonNull protected final @NonNull PreparedQuery<?,?> prepareQuery(RepositoryMethodKey key, io.micronaut.aop.MethodInvocationContext<T,R> context)
      Prepares a query for the given context.
      Parameters:
      key - The method key
      context - The context
      Returns:
      The query
    • prepareQuery

      @NonNull protected final <RT> @NonNull PreparedQuery<?,RT> prepareQuery(RepositoryMethodKey methodKey, io.micronaut.aop.MethodInvocationContext<T,R> context, Class<RT> resultType)
      Prepares a query for the given context.
      Type Parameters:
      RT - The result generic type
      Parameters:
      methodKey - The method key
      context - The context
      resultType - The result type
      Returns:
      The query
    • prepareQuery

      @NonNull protected final <RT> @NonNull PreparedQuery<?,RT> prepareQuery(RepositoryMethodKey methodKey, io.micronaut.aop.MethodInvocationContext<T,R> context, Class<RT> resultType, boolean isCount)
      Prepares a query for the given context.
      Type Parameters:
      RT - The result generic type
      Parameters:
      methodKey - The method key
      context - The context
      resultType - The result type
      isCount - Is count query
      Returns:
      The query
    • prepareCountQuery

      @NonNull protected final @NonNull PreparedQuery<?,Number> prepareCountQuery(RepositoryMethodKey methodKey, @NonNull @NonNull io.micronaut.aop.MethodInvocationContext<T,R> context)
      Prepares a query for the given context.
      Parameters:
      methodKey - The method key
      context - The context
      Returns:
      The query
    • getRequiredRootEntity

      @NonNull 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 @NonNull Class<RT> type)
      Retrieve an entity parameter value in role.
      Type Parameters:
      RT - The generic type
      Parameters:
      context - The context
      type - The type
      Returns:
      An result
    • getEntitiesParameter

      protected <RT> Iterable<RT> getEntitiesParameter(io.micronaut.aop.MethodInvocationContext<?,?> context, @NonNull @NonNull Class<RT> type)
      Retrieve an entities parameter value in role.
      Type Parameters:
      RT - The generic type
      Parameters:
      context - The context
      type - The type
      Returns:
      An result
    • findEntityParameter

      protected <RT> Optional<RT> findEntityParameter(io.micronaut.aop.MethodInvocationContext<?,?> context, @NonNull @NonNull Class<RT> type)
      Find an entity parameter value in role.
      Type Parameters:
      RT - The generic type
      Parameters:
      context - The context
      type - The type
      Returns:
      An result
    • findEntitiesParameter

      protected <RT> Optional<Iterable<RT>> findEntitiesParameter(io.micronaut.aop.MethodInvocationContext<?,?> context, @NonNull @NonNull Class<RT> type)
      Fid an entities parameter value in role.
      Type Parameters:
      RT - The generic type
      Parameters:
      context - The context
      type - The type
      Returns:
      An result
    • getPageable

      @NonNull protected @NonNull Pageable getPageable(io.micronaut.aop.MethodInvocationContext<?,?> context)
      Resolves the Pageable for the given context.
      Parameters:
      context - The pageable
      Returns:
      The pageable or null
    • isNullable

      protected boolean isNullable(@NonNull @NonNull io.micronaut.core.annotation.AnnotationMetadata metadata)
      Return whether the metadata indicates the instance is nullable.
      Parameters:
      metadata - The metadata
      Returns:
      True if it is nullable
    • getRequiredEntity

      @NonNull protected @NonNull Object getRequiredEntity(io.micronaut.aop.MethodInvocationContext<T,?> context)
      Looks up the entity to persist from the execution context, or throws an exception.
      Parameters:
      context - The context
      Returns:
      The entity
    • instantiateEntity

      @NonNull protected @NonNull Object instantiateEntity(@NonNull @NonNull Class<?> rootEntity, @NonNull @NonNull Map<String,Object> parameterValues)
      Instantiate the given entity for the given parameter values.
      Parameters:
      rootEntity - The entity
      parameterValues - The parameter values
      Returns:
      The entity
      Throws:
      IllegalArgumentException - if the entity cannot be instantiated due to an illegal argument
    • getPagedQuery

      @NonNull protected <E> @NonNull PagedQuery<E> getPagedQuery(@NonNull @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

      @NonNull protected <E> @NonNull InsertBatchOperation<E> getInsertBatchOperation(@NonNull @NonNull io.micronaut.aop.MethodInvocationContext context, @NonNull @NonNull Iterable<E> iterable)
      Get the insert batch operation for the given context.
      Type Parameters:
      E - The entity type
      Parameters:
      context - The context
      iterable - The iterable
      Returns:
      The paged query
    • getInsertBatchOperation

      @NonNull protected <E> @NonNull InsertBatchOperation<E> getInsertBatchOperation(@NonNull @NonNull io.micronaut.aop.MethodInvocationContext context, Class<E> rootEntity, @NonNull @NonNull Iterable<E> iterable)
      Get the insert batch operation for the given context.
      Type Parameters:
      E - The entity type
      Parameters:
      context - The context
      rootEntity - The root entity
      iterable - The iterable
      Returns:
      The paged query
    • getInsertOperation

      @NonNull protected <E> @NonNull InsertOperation<E> getInsertOperation(@NonNull @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

      @NonNull protected <E> @NonNull UpdateOperation<E> getUpdateOperation(@NonNull @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

      @NonNull protected <E> @NonNull UpdateOperation<E> getUpdateOperation(@NonNull @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 context
      entity - The entity instance
      Returns:
      The paged query
    • getUpdateAllBatchOperation

      @NonNull protected <E> @NonNull UpdateBatchOperation<E> getUpdateAllBatchOperation(@NonNull @NonNull io.micronaut.aop.MethodInvocationContext<T,?> context, Class<E> rootEntity, @NonNull @NonNull Iterable<E> iterable)
      Get the update all batch operation for the given context.
      Type Parameters:
      E - The entity type
      Parameters:
      rootEntity - The root entitry
      context - The context
      iterable - The iterable
      Returns:
      The paged query
    • getDeleteOperation

      @NonNull protected <E> @NonNull DeleteOperation<E> getDeleteOperation(@NonNull @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 context
      entity - The entity
      Returns:
      The paged query
    • getDeleteReturningOperation

      @NonNull protected <E, K> @NonNull DeleteReturningOperation<E,K> getDeleteReturningOperation(@NonNull @NonNull io.micronaut.aop.MethodInvocationContext<T,?> context, @NonNull E entity)
      Get the delete operation for the given context.
      Type Parameters:
      E - The entity type
      K - The result type
      Parameters:
      context - The context
      entity - The entity
      Returns:
      The paged query
    • getDeleteAllBatchOperation

      @NonNull protected <E> @NonNull DeleteBatchOperation<E> getDeleteAllBatchOperation(@NonNull @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

      @NonNull protected <E> @NonNull DeleteBatchOperation<E> getDeleteBatchOperation(@NonNull @NonNull io.micronaut.aop.MethodInvocationContext<T,?> context, @NonNull @NonNull Iterable<E> iterable)
      Get the delete batch operation for the given context.
      Type Parameters:
      E - The entity type
      Parameters:
      context - The context
      iterable - The iterable
      Returns:
      The paged query
    • getDeleteReturningBatchOperation

      @NonNull protected <E, K> @NonNull DeleteReturningBatchOperation<E,K> getDeleteReturningBatchOperation(@NonNull @NonNull io.micronaut.aop.MethodInvocationContext<T,?> context, @NonNull @NonNull Iterable<E> iterable)
      Get the delete returning batch operation for the given context.
      Type Parameters:
      E - The entity type
      K - The result type
      Parameters:
      context - The context
      iterable - The iterable
      Returns:
      The paged query
    • getDeleteBatchOperation

      @NonNull protected <E> @NonNull DeleteBatchOperation<E> getDeleteBatchOperation(@NonNull @NonNull io.micronaut.aop.MethodInvocationContext<T,?> context, Class<E> rootEntity, @NonNull @NonNull Iterable<E> iterable)
      Get the delete batch operation for the given context.
      Type Parameters:
      E - The entity type
      Parameters:
      context - The context
      rootEntity - The root entity
      iterable - The iterable
      Returns:
      The paged query
    • getInsertOperation

      @NonNull protected <E> @NonNull InsertOperation<E> getInsertOperation(@NonNull @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 context
      entity - The entity
      Returns:
      The paged query
    • validateNullArguments

      protected final void validateNullArguments(io.micronaut.aop.MethodInvocationContext<T,R> context)
      Validates null arguments ensuring no argument is null unless declared so.
      Parameters:
      context - The context
    • count

      protected int count(Iterable<?> iterable)
      Count the items.
      Parameters:
      iterable - the iterable
      Returns:
      the size
    • isNumber

      protected boolean isNumber(@Nullable @Nullable Class<?> type)
      Is the type a number.
      Parameters:
      type - The type
      Returns:
      True if is a number