diff --git a/src/main/java/org/springframework/data/querydsl/binding/QuerydslBindingsFactory.java b/src/main/java/org/springframework/data/querydsl/binding/QuerydslBindingsFactory.java index 1261daaadf..0ac7830bc9 100644 --- a/src/main/java/org/springframework/data/querydsl/binding/QuerydslBindingsFactory.java +++ b/src/main/java/org/springframework/data/querydsl/binding/QuerydslBindingsFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,7 @@ * Factory to create {@link QuerydslBindings} using an {@link EntityPathResolver}. * * @author Oliver Gierke + * @author Marcel Overdijk * @since 1.11 */ public class QuerydslBindingsFactory implements ApplicationContextAware { @@ -44,6 +45,8 @@ public class QuerydslBindingsFactory implements ApplicationContextAware { private final EntityPathResolver entityPathResolver; private final Map, EntityPath> entityPaths; + private QuerydslBinderCustomizer defaultBindings; + private AutowireCapableBeanFactory beanFactory; private Repositories repositories; @@ -60,6 +63,20 @@ public QuerydslBindingsFactory(EntityPathResolver entityPathResolver) { this.entityPaths = new ConcurrentReferenceHashMap, EntityPath>(); } + /** + * Creates a new {@link QuerydslBindingsFactory} using the given {@link EntityPathResolver} and default bindings + * {@link QuerydslBinderCustomizer}. + * + * @param entityPathResolver must not be {@literal null}. + * @param defaultBindings the default bindings {@link QuerydslBinderCustomizer} to apply to each {@link QuerydslBindings} + * created by this factory. + */ + public QuerydslBindingsFactory(EntityPathResolver entityPathResolver, QuerydslBinderCustomizer defaultBindings) { + this(entityPathResolver); + + this.defaultBindings = defaultBindings; + } + /* * (non-Javadoc) * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) @@ -97,6 +114,11 @@ public QuerydslBindings createBindingsFor(Class path = verifyEntityPathPresent(domainType); QuerydslBindings bindings = new QuerydslBindings(); + + if (defaultBindings != null) { + defaultBindings.customize(bindings, path); + } + findCustomizerForDomainType(customizer, domainType.getType()).customize(bindings, path); return bindings;