Skip to content

Register reflection hints for Querydsl Q types. #2743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

christophstrobl
Copy link
Member

This PR 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

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.
private final static Log logger = LogFactory.getLog(QTypeContributor.class);
private static Function<ClassLoader, Class<?>> entityPathType = cacheOf(QTypeContributor::getEntityPathType);

public static void contributeEntityPath(Class<?> type, GenerationContext context, @Nullable ClassLoader classLoader) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making the entire code conditional based on the presence of com.querydsl.core.types.EntityPath?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what happens here, just taking the ClassLoader into account.


TypeContributor.contribute(repositoryInformation.getDomainType(), contribution);
QTypeContributor.contributeEntityPath(repositoryInformation.getDomainType(), contribution,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check for QTypeContributor.QUERYDSL_PRESENT or similar.

}

@Nullable
private static Class<?> getEntityPathType(ClassLoader classLoader) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a case where we see multiple class loaders through which we cannot see Querydsl? (Other than testing).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use the same class loader that is used for AOT processing.

* @param domainClass
* @return
*/
private static String getQueryClassName(Class<?> domainClass) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a similar computation in our other Querydsl utils. It would make sense to reuse those parts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, but that created cycles between the packages.

@mp911de mp911de added this to the 3.0.1 (2022.0.1) milestone Dec 12, 2022
mp911de pushed a commit that referenced this pull request Dec 12, 2022
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.
mp911de added a commit that referenced this pull request Dec 12, 2022
Avoid caching. Expand exception handling to all reflective exceptions. Fix since tags.

See: #2721
Original pull request: #2743.
mp911de pushed a commit that referenced this pull request Dec 12, 2022
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.
mp911de added a commit that referenced this pull request Dec 12, 2022
Avoid caching. Expand exception handling to all reflective exceptions. Fix since tags.

See: #2721
Original pull request: #2743.
@mp911de mp911de closed this Dec 12, 2022
@mp911de mp911de deleted the issue/2721 branch December 12, 2022 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider reflection hints for generated Querydsl Q classes
2 participants