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,AbstractSpecificationInterceptor,DefaultCountInterceptor,DefaultDeleteAllInterceptor,DefaultDeleteOneInterceptor,DefaultExistsByInterceptor,DefaultFindAllInterceptor,DefaultFindByIdInterceptor,DefaultFindOneInterceptor,DefaultFindOptionalInterceptor,DefaultFindPageInterceptor,DefaultFindSliceInterceptor,DefaultFindStreamInterceptor,DefaultSaveAllInterceptor,DefaultSaveEntityInterceptor,DefaultSaveOneInterceptor,DefaultUpdateAllEntitiesInterceptor,DefaultUpdateEntityInterceptor,DefaultUpdateInterceptor,FindPageSpecificationInterceptor,FlushInterceptor,LoadInterceptor
public abstract class AbstractQueryInterceptor<T,R> extends java.lang.Object implements DataInterceptor<T,R>
Abstract interceptor that executes aQuery.- Since:
- 1.0
- Author:
- graemerocher
-
-
Field Summary
Fields Modifier and Type Field Description protected RepositoryOperationsoperationsprotected PreparedQueryResolverpreparedQueryResolver
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractQueryInterceptor(RepositoryOperations operations)Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected java.lang.NumberconvertNumberArgumentIfNecessary(java.lang.Number number, io.micronaut.core.type.Argument<?> argument)Deprecated.protected java.lang.ObjectconvertOne(io.micronaut.aop.MethodInvocationContext<?,?> context, java.lang.Object o)protected java.lang.ObjectconvertOne(java.lang.Object o, io.micronaut.core.type.Argument<?> argumentType)protected intcount(java.lang.Iterable<?> iterable)Count the items.protected <RT> java.util.Optional<java.lang.Iterable<RT>>findEntitiesParameter(io.micronaut.aop.MethodInvocationContext<?,?> context, java.lang.Class<RT> type)Fid an entities parameter value in role.protected <RT> java.util.Optional<RT>findEntityParameter(io.micronaut.aop.MethodInvocationContext<?,?> context, java.lang.Class<RT> type)Find an entity parameter value in role.protected <E> DeleteBatchOperation<E>getDeleteAllBatchOperation(io.micronaut.aop.MethodInvocationContext<T,?> context)Get the delete all batch operation for the given context.protected <E> DeleteBatchOperation<E>getDeleteBatchOperation(io.micronaut.aop.MethodInvocationContext<T,?> context, java.lang.Class<E> rootEntity, java.lang.Iterable<E> iterable)Get the delete batch operation for the given context.protected <E> DeleteBatchOperation<E>getDeleteBatchOperation(io.micronaut.aop.MethodInvocationContext<T,?> context, java.lang.Iterable<E> iterable)Get the delete batch operation for the given context.protected <E> DeleteOperation<E>getDeleteOperation(io.micronaut.aop.MethodInvocationContext<T,?> context, E entity)Get the delete operation for the given context.protected <RT> java.lang.Iterable<RT>getEntitiesParameter(io.micronaut.aop.MethodInvocationContext<?,?> context, java.lang.Class<RT> type)Retrieve an entities parameter value in role.protected <RT> RTgetEntityParameter(io.micronaut.aop.MethodInvocationContext<?,?> context, java.lang.Class<RT> type)Retrieve an entity parameter value in role.protected <E> InsertBatchOperation<E>getInsertBatchOperation(io.micronaut.aop.MethodInvocationContext context, java.lang.Class<E> rootEntity, java.lang.Iterable<E> iterable)Get the insert batch operation for the given context.protected <E> InsertBatchOperation<E>getInsertBatchOperation(io.micronaut.aop.MethodInvocationContext context, java.lang.Iterable<E> iterable)Get the insert batch operation for the given context.protected <E> InsertOperation<E>getInsertOperation(io.micronaut.aop.MethodInvocationContext context)Get the batch operation for the given context.protected <E> InsertOperation<E>getInsertOperation(io.micronaut.aop.MethodInvocationContext<T,?> context, E entity)Get the batch operation for the given context.protected PageablegetPageable(io.micronaut.aop.MethodInvocationContext<?,?> context)Resolves thePageablefor the given context.protected <E> PagedQuery<E>getPagedQuery(io.micronaut.aop.MethodInvocationContext context)Get the paged query for the given context.protected java.util.Map<java.lang.String,java.lang.Object>getParameterValueMap(io.micronaut.aop.MethodInvocationContext<?,?> context)Returns parameter values with respect ofParameterannotation.protected java.lang.ObjectgetRequiredEntity(io.micronaut.aop.MethodInvocationContext<T,?> context)Looks up the entity to persist from the execution context, or throws an exception.protected <E> java.lang.Class<E>getRequiredRootEntity(io.micronaut.aop.MethodInvocationContext context)Obtains the root entity or throws an exception if it not available.protected io.micronaut.core.type.Argument<?>getReturnType(io.micronaut.aop.MethodInvocationContext<?,?> context)Returns the return type.protected <E> UpdateBatchOperation<E>getUpdateAllBatchOperation(io.micronaut.aop.MethodInvocationContext<T,?> context, java.lang.Class<E> rootEntity, java.lang.Iterable<E> iterable)Get the update all batch operation for the given context.protected <E> UpdateOperation<E>getUpdateOperation(io.micronaut.aop.MethodInvocationContext<T,?> context)Get the batch operation for the given context.protected <E> UpdateOperation<E>getUpdateOperation(io.micronaut.aop.MethodInvocationContext<T,?> context, E entity)Get the batch operation for the given context.protected java.lang.ObjectinstantiateEntity(java.lang.Class<?> rootEntity, java.util.Map<java.lang.String,java.lang.Object> parameterValues)Instantiate the given entity for the given parameter values.protected booleanisNullable(io.micronaut.core.annotation.AnnotationMetadata metadata)Return whether the metadata indicates the instance is nullable.protected booleanisNumber(java.lang.Class<?> type)Is the type a number.protected PreparedQuery<?,java.lang.Number>prepareCountQuery(RepositoryMethodKey methodKey, io.micronaut.aop.MethodInvocationContext<T,R> context)Prepares a query for the given context.protected PreparedQuery<?,?>prepareQuery(RepositoryMethodKey key, io.micronaut.aop.MethodInvocationContext<T,R> context)Prepares a query for the given context.protected <RT> PreparedQuery<?,RT>prepareQuery(RepositoryMethodKey methodKey, io.micronaut.aop.MethodInvocationContext<T,R> context, java.lang.Class<RT> resultType)Prepares a query for the given context.protected <RT> PreparedQuery<?,RT>prepareQuery(RepositoryMethodKey methodKey, io.micronaut.aop.MethodInvocationContext<T,R> context, java.lang.Class<RT> resultType, boolean isCount)Prepares a query for the given context.protected voidvalidateNullArguments(io.micronaut.aop.MethodInvocationContext<T,R> context)Validates null arguments ensuring no argument is null unless declared so.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.micronaut.data.intercept.DataInterceptor
intercept
-
-
-
-
Field Detail
-
operations
protected final RepositoryOperations operations
-
preparedQueryResolver
protected final PreparedQueryResolver preparedQueryResolver
-
-
Constructor Detail
-
AbstractQueryInterceptor
protected AbstractQueryInterceptor(@NonNull RepositoryOperations operations)Default constructor.- Parameters:
operations- The operations
-
-
Method Detail
-
getParameterValueMap
@NonNull protected java.util.Map<java.lang.String,java.lang.Object> getParameterValueMap(io.micronaut.aop.MethodInvocationContext<?,?> context)
Returns parameter values with respect ofParameterannotation.- 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 java.lang.Object convertOne(io.micronaut.aop.MethodInvocationContext<?,?> context, @Nullable java.lang.Object o)
-
convertOne
protected final java.lang.Object convertOne(java.lang.Object o, io.micronaut.core.type.Argument<?> argumentType)
-
prepareQuery
@NonNull protected final PreparedQuery<?,?> prepareQuery(RepositoryMethodKey key, io.micronaut.aop.MethodInvocationContext<T,R> context)
Prepares a query for the given context.- Parameters:
key- The method keycontext- The context- Returns:
- The query
-
prepareQuery
@NonNull protected final <RT> PreparedQuery<?,RT> prepareQuery(RepositoryMethodKey methodKey, io.micronaut.aop.MethodInvocationContext<T,R> context, java.lang.Class<RT> resultType)
Prepares a query for the given context.- Type Parameters:
RT- The result generic type- Parameters:
methodKey- The method keycontext- The contextresultType- The result type- Returns:
- The query
-
prepareQuery
@NonNull protected final <RT> PreparedQuery<?,RT> prepareQuery(RepositoryMethodKey methodKey, io.micronaut.aop.MethodInvocationContext<T,R> context, java.lang.Class<RT> resultType, boolean isCount)
Prepares a query for the given context.- Type Parameters:
RT- The result generic type- Parameters:
methodKey- The method keycontext- The contextresultType- The result typeisCount- Is count query- Returns:
- The query
-
prepareCountQuery
@NonNull protected final PreparedQuery<?,java.lang.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
@NonNull protected <E> java.lang.Class<E> getRequiredRootEntity(io.micronaut.aop.MethodInvocationContext context)
Obtains the root entity or throws an exception if it not available.- Type Parameters:
E- The entity type- Parameters:
context- The context- Returns:
- The root entity type
- Throws:
java.lang.IllegalStateException- If the root entity is unavailable
-
getEntityParameter
protected <RT> RT getEntityParameter(io.micronaut.aop.MethodInvocationContext<?,?> context, @NonNull java.lang.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
protected <RT> java.lang.Iterable<RT> getEntitiesParameter(io.micronaut.aop.MethodInvocationContext<?,?> context, @NonNull java.lang.Class<RT> type)Retrieve an entities parameter value in role.- Type Parameters:
RT- The generic type- Parameters:
context- The contexttype- The type- Returns:
- An result
-
findEntityParameter
protected <RT> java.util.Optional<RT> findEntityParameter(io.micronaut.aop.MethodInvocationContext<?,?> context, @NonNull java.lang.Class<RT> type)Find an entity parameter value in role.- Type Parameters:
RT- The generic type- Parameters:
context- The contexttype- The type- Returns:
- An result
-
findEntitiesParameter
protected <RT> java.util.Optional<java.lang.Iterable<RT>> findEntitiesParameter(io.micronaut.aop.MethodInvocationContext<?,?> context, @NonNull java.lang.Class<RT> type)Fid an entities parameter value in role.- Type Parameters:
RT- The generic type- Parameters:
context- The contexttype- The type- Returns:
- An result
-
getPageable
@NonNull protected Pageable getPageable(io.micronaut.aop.MethodInvocationContext<?,?> context)
Resolves thePageablefor the given context.- Parameters:
context- The pageable- Returns:
- The pageable or null
-
isNullable
protected boolean isNullable(@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 java.lang.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 java.lang.Object instantiateEntity(@NonNull java.lang.Class<?> rootEntity, @NonNull java.util.Map<java.lang.String,java.lang.Object> parameterValues)Instantiate the given entity for the given parameter values.- Parameters:
rootEntity- The entityparameterValues- The parameter values- Returns:
- The entity
- Throws:
java.lang.IllegalArgumentException- if the entity cannot be instantiated due to an illegal argument
-
convertNumberArgumentIfNecessary
@Deprecated @Nullable protected java.lang.Number convertNumberArgumentIfNecessary(java.lang.Number number, io.micronaut.core.type.Argument<?> argument)Deprecated.Convert a number argument if necessary.- Parameters:
number- The numberargument- The argument- Returns:
- The result
-
getPagedQuery
@NonNull protected <E> 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
@NonNull protected <E> InsertBatchOperation<E> getInsertBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext context, @NonNull java.lang.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
@NonNull protected <E> InsertBatchOperation<E> getInsertBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext context, java.lang.Class<E> rootEntity, @NonNull java.lang.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
@NonNull protected <E> 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
@NonNull protected <E> 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
@NonNull protected <E> 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
@NonNull protected <E> UpdateBatchOperation<E> getUpdateAllBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T,?> context, java.lang.Class<E> rootEntity, @NonNull java.lang.Iterable<E> iterable)
Get the update all batch operation for the given context.- Type Parameters:
E- The entity type- Parameters:
rootEntity- The root entitrycontext- The contextiterable- The iterable- Returns:
- The paged query
-
getDeleteOperation
@NonNull protected <E> 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
-
getDeleteAllBatchOperation
@NonNull protected <E> 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
@NonNull protected <E> DeleteBatchOperation<E> getDeleteBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T,?> context, @NonNull java.lang.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
-
getDeleteBatchOperation
@NonNull protected <E> DeleteBatchOperation<E> getDeleteBatchOperation(@NonNull io.micronaut.aop.MethodInvocationContext<T,?> context, java.lang.Class<E> rootEntity, @NonNull java.lang.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
@NonNull protected <E> 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<T,R> context)
Validates null arguments ensuring no argument is null unless declared so.- Parameters:
context- The context
-
count
protected int count(java.lang.Iterable<?> iterable)
Count the items.- Parameters:
iterable- the iterable- Returns:
- the size
-
isNumber
protected boolean isNumber(@Nullable java.lang.Class<?> type)Is the type a number.- Parameters:
type- The type- Returns:
- True if is a number
-
-