1515 */
1616package org .springframework .data .querydsl .binding ;
1717
18+ import java .util .List ;
1819import java .util .Map ;
1920import java .util .Optional ;
21+ import java .util .stream .Collectors ;
2022
2123import org .springframework .beans .BeanUtils ;
2224import org .springframework .beans .BeansException ;
3739 *
3840 * @author Oliver Gierke
3941 * @author Christoph Strobl
42+ * @author Mark Paluch
4043 * @since 1.11
4144 */
4245public class QuerydslBindingsFactory implements ApplicationContextAware {
@@ -48,6 +51,7 @@ public class QuerydslBindingsFactory implements ApplicationContextAware {
4851
4952 private Optional <AutowireCapableBeanFactory > beanFactory ;
5053 private Optional <Repositories > repositories ;
54+ private QuerydslBinderCustomizer <EntityPath <?>> defaultCustomizer ;
5155
5256 /**
5357 * Creates a new {@link QuerydslBindingsFactory} using the given {@link EntityPathResolver}.
@@ -62,6 +66,7 @@ public QuerydslBindingsFactory(EntityPathResolver entityPathResolver) {
6266 this .entityPaths = new ConcurrentReferenceHashMap <>();
6367 this .beanFactory = Optional .empty ();
6468 this .repositories = Optional .empty ();
69+ this .defaultCustomizer = NoOpCustomizer .INSTANCE ;
6570 }
6671
6772 /*
@@ -73,6 +78,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
7378
7479 this .beanFactory = Optional .of (applicationContext .getAutowireCapableBeanFactory ());
7580 this .repositories = Optional .of (new Repositories (applicationContext ));
81+ this .defaultCustomizer = findDefaultCustomizer ();
7682 }
7783
7884 /**
@@ -126,6 +132,7 @@ private QuerydslBindings createBindingsFor(TypeInformation<?> domainType,
126132 EntityPath <?> path = verifyEntityPathPresent (domainType );
127133
128134 QuerydslBindings bindings = new QuerydslBindings ();
135+ defaultCustomizer .customize (bindings , path );
129136 findCustomizerForDomainType (customizer , domainType .getType ()).customize (bindings , path );
130137
131138 return bindings ;
@@ -151,9 +158,32 @@ private EntityPath<?> verifyEntityPathPresent(TypeInformation<?> candidate) {
151158 });
152159 }
153160
161+ /**
162+ * Obtains registered {@link DefaultQuerydslBinderCustomizer} instances from the
163+ * {@link org.springframework.beans.factory.BeanFactory}.
164+ *
165+ * @return
166+ */
167+ private QuerydslBinderCustomizer <EntityPath <?>> findDefaultCustomizer () {
168+ return beanFactory .map (this ::getDefaultQuerydslBinderCustomizer ).orElse (NoOpCustomizer .INSTANCE );
169+ }
170+
171+ private QuerydslBinderCustomizer <EntityPath <?>> getDefaultQuerydslBinderCustomizer (
172+ AutowireCapableBeanFactory beanFactory ) {
173+
174+ List <DefaultQuerydslBinderCustomizer > customizers = beanFactory
175+ .getBeanProvider (DefaultQuerydslBinderCustomizer .class ).stream ().collect (Collectors .toList ());
176+
177+ return (bindings , root ) -> {
178+ for (DefaultQuerydslBinderCustomizer defaultQuerydslBinderCustomizer : customizers ) {
179+ defaultQuerydslBinderCustomizer .customize (bindings , root );
180+ }
181+ };
182+ }
183+
154184 /**
155185 * Obtains the {@link QuerydslBinderCustomizer} for the given domain type. Will inspect the given annotation for a
156- * dedicatedly configured one or consider the domain types 's repository.
186+ * dedicated configured one or consider the domain type 's repository.
157187 *
158188 * @param annotation
159189 * @param domainType
@@ -194,7 +224,7 @@ private QuerydslBinderCustomizer<EntityPath<?>> createQuerydslBinderCustomizer(
194224 }).orElseGet (() -> BeanUtils .instantiateClass (type ));
195225 }
196226
197- private static enum NoOpCustomizer implements QuerydslBinderCustomizer <EntityPath <?>> {
227+ private enum NoOpCustomizer implements QuerydslBinderCustomizer <EntityPath <?>> {
198228
199229 INSTANCE ;
200230
0 commit comments