use of io.micronaut.data.processor.visitors.finders.criteria.QueryCriteriaMethodMatch in project micronaut-data by micronaut-projects.
the class FindMethodMatcher method match.
@Override
protected MethodMatch match(MethodMatchContext matchContext, java.util.regex.Matcher matcher) {
if (isCompatibleReturnType(matchContext)) {
return new QueryCriteriaMethodMatch(matcher) {
boolean hasIdMatch;
@Override
protected <T> void apply(MethodMatchContext matchContext, PersistentEntityRoot<T> root, PersistentEntityCriteriaQuery<T> query, SourcePersistentEntityCriteriaBuilder cb) {
super.apply(matchContext, root, query, cb);
if (query instanceof AbstractPersistentEntityCriteriaQuery) {
hasIdMatch = ((AbstractPersistentEntityCriteriaQuery<T>) query).hasOnlyIdRestriction();
}
}
@Override
protected Map.Entry<ClassElement, Class<? extends DataInterceptor>> resolveReturnTypeAndInterceptor(MethodMatchContext matchContext) {
Map.Entry<ClassElement, Class<? extends DataInterceptor>> e = super.resolveReturnTypeAndInterceptor(matchContext);
Class<? extends DataInterceptor> interceptorType = e.getValue();
ClassElement queryResultType = e.getKey();
if (isFindByIdQuery(matchContext, queryResultType)) {
if (interceptorType == FindOneInterceptor.class) {
interceptorType = FindByIdInterceptor.class;
} else if (interceptorType == FindOneAsyncInterceptor.class) {
interceptorType = FindByIdAsyncInterceptor.class;
} else if (interceptorType == FindOneReactiveInterceptor.class) {
interceptorType = FindByIdReactiveInterceptor.class;
}
}
return new AbstractMap.SimpleEntry<>(queryResultType, interceptorType);
}
private boolean isFindByIdQuery(@NonNull MethodMatchContext matchContext, @NonNull ClassElement queryResultType) {
return hasIdMatch && matchContext.supportsImplicitQueries() && queryResultType.getName().equals(matchContext.getRootEntity().getName()) && hasNoWhereAndJoinDeclaration(matchContext);
}
};
}
return null;
}
Aggregations