Skip to content
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

Add support for providing default querydsl bindings #206

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -44,6 +45,8 @@ public class QuerydslBindingsFactory implements ApplicationContextAware {
private final EntityPathResolver entityPathResolver;
private final Map<TypeInformation<?>, EntityPath<?>> entityPaths;

private QuerydslBinderCustomizer defaultBindings;

private AutowireCapableBeanFactory beanFactory;
private Repositories repositories;

Expand All @@ -60,6 +63,20 @@ public QuerydslBindingsFactory(EntityPathResolver entityPathResolver) {
this.entityPaths = new ConcurrentReferenceHashMap<TypeInformation<?>, 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)
Expand Down Expand Up @@ -97,6 +114,11 @@ public QuerydslBindings createBindingsFor(Class<? extends QuerydslBinderCustomiz
EntityPath<?> path = verifyEntityPathPresent(domainType);

QuerydslBindings bindings = new QuerydslBindings();

if (defaultBindings != null) {
defaultBindings.customize(bindings, path);
}

findCustomizerForDomainType(customizer, domainType.getType()).customize(bindings, path);

return bindings;
Expand Down