spring-projects / spring-data-commons

Spring Data Commons. Interfaces and code shared between the various datastore specific implementations.
https://spring.io/projects/spring-data
Apache License 2.0
785 stars 677 forks source link

Configure default QueryDSL customizers [DATACMNS-930] #1383

Open spring-projects-issues opened 8 years ago

spring-projects-issues commented 8 years ago

Kirill Voronin opened DATACMNS-930 and commented

It will be nice to be able to configure some common QuerydslBinderCustomizer s for each repository in one place, probably as a bean(s). For example one to query by any Date using range.

Currently I achieve this using an interface CommonCustomizer that is extended by all repos. But if I want to customize them further, then repo's customize method should include CommonCustomizer.super.customize(bindings, root) call. I wonder if it will be better/cleaner to have an annotation such as QuerydslPredicate(bindings=CommonCustomizer.class) but on a repo interface.

Does I miss something? Maybe even both configuration methods can be useful. If so, I can implement it with a little advice


No further details from DATACMNS-930

spring-projects-issues commented 8 years ago

Oliver Drotbohm commented

What I am wondering is how would that annotation actually help the use case you've identified as problematic: the repository wanting to customize the defaults? I'd love to see a concrete code example of which part of the configuration you'd like to avoid. I'd argue that explicitly calling the super-method from within an overridden one is also good practice as it makes obvious what actually gets applied, doesn't it?

spring-projects-issues commented 8 years ago

Kirill Voronin commented

the repository wanting to customize the defaults Actually I'm talking about a use case when all repos want to apply the same customization. Probably the best way to achieve this is to configure it somewhere in context.

And annotation is just an alternative to configure customizations for a single repo to make it easier to apply more than one customization. I wonder if it's possible to pass multiple customization classes using it and then apply them in sequence instead of using multiple inheritance of interfaces. One problem with this is that you need to do both - inherit interface and make super call. And if you forget the last one, there would be no errors and queries would return wrong results. I mentioned this idea too because it helps a bit.

I've made a repo to demonstrate the issue

spring-projects-issues commented 3 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.