spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
2.93k stars 1.39k forks source link

Introduce `QueryEnhancerSelector` to configure which `QueryEnhancerFactory` to use #3527

Open mp911de opened 6 days ago

mp911de commented 6 days ago

This is a draft for configuring a QueryEnhancerSelector that selects a QueryEnhancerFactory based on a DeclaredQuery:

@EnableJpaRepositories(queryEnhancerSelector = MyQueryEnhancerSelector.class)

class MyQueryEnhancerSelector extends QueryEnhancerSelector.DefaultQueryEnhancerSelector {
    public MyQueryEnhancerSelector() {
        super(QueryEnhancerFactories.fallback(), DefaultQueryEnhancerSelector.jpql());
    }
}

This change requires decoupling of DeclaredQuery (the declaration aspect) and the introspected part (IntrospectedQuery) to avoid the logical cycle of introspecting a query upon DeclaredQuery creation.