Register reflection hints for Querydsl Q types.

This commit introduced support for registering GraalVM native reflection type hints for Querydsl Q types that target domain types used in the repository interface declaration.

At this point we only do a simple lookup for Q types based in the very same package that implement EntityPath.
More advanced configuration (eg. base package and type prefix), potentially available via EntityPathResolver are not taken into account as this would require eager bean resolution from the application context, which is likely to trigger additional infrastructure. In this case the user is required to register Q types manually.

Closes: #2721
Original pull request: #2743.
This commit is contained in:
Christoph Strobl
2022-12-05 14:51:10 +01:00
committed by Mark Paluch
parent 14d76ab148
commit 016e8c2779
7 changed files with 284 additions and 6 deletions

View File

@@ -31,6 +31,7 @@ import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.ResolvableType;
import org.springframework.data.domain.ManagedTypes;
import org.springframework.data.util.QTypeContributor;
import org.springframework.data.util.TypeContributor;
import org.springframework.data.util.TypeUtils;
import org.springframework.lang.Nullable;
@@ -134,9 +135,11 @@ public class ManagedTypesBeanRegistrationAotProcessor implements BeanRegistratio
Set<String> annotationNamespaces = Collections.singleton(TypeContributor.DATA_NAMESPACE);
TypeContributor.contribute(type.toClass(), annotationNamespaces, generationContext);
Class<?> resolvedType = type.toClass();
TypeContributor.contribute(resolvedType, annotationNamespaces, generationContext);
QTypeContributor.contributeEntityPath(resolvedType, generationContext, resolvedType.getClassLoader());
TypeUtils.resolveUsedAnnotations(type.toClass()).forEach(
TypeUtils.resolveUsedAnnotations(resolvedType).forEach(
annotation -> TypeContributor.contribute(annotation.getType(), annotationNamespaces, generationContext));
}