Skip to content

Commit

Permalink
Rebase findings.
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Dec 12, 2024
1 parent debdeba commit 60a57dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 the original author or authors.
* Copyright 2018-2024 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 All @@ -18,7 +18,10 @@
/**
* Interface defining the contract to represent a declared query.
*
* @author Jens Schauder
* @author Diego Krupitza
* @author Mark Paluch
* @since 2.0.3
*/
public interface DeclaredQuery {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class JpaRepositoryFactoryBean<T extends Repository<S, ID>, S, ID>
private EntityPathResolver entityPathResolver;
private EscapeCharacter escapeCharacter = EscapeCharacter.DEFAULT;
private JpaQueryMethodFactory queryMethodFactory;
private @Nullable Function<BeanFactory, QueryEnhancerSelector> queryEnhancerSelector;
private @Nullable Function<BeanFactory, QueryEnhancerSelector> queryEnhancerSelectorSource;

/**
* Creates a new {@link JpaRepositoryFactoryBean} for the given repository interface.
Expand Down Expand Up @@ -118,35 +118,36 @@ public void setQueryMethodFactory(@Nullable JpaQueryMethodFactory factory) {
* Configures the {@link QueryEnhancerSelector} to be used. Defaults to
* {@link QueryEnhancerSelector#DEFAULT_SELECTOR}.
*
* @param queryEnhancerSelector must not be {@literal null}.
* @param queryEnhancerSelectorSource must not be {@literal null}.
*/
public void setQueryEnhancerSelector(QueryEnhancerSelector queryEnhancerSelector) {
this.queryEnhancerSelector = bf -> queryEnhancerSelector;
public void setQueryEnhancerSelectorSource(QueryEnhancerSelector queryEnhancerSelectorSource) {
this.queryEnhancerSelectorSource = bf -> queryEnhancerSelectorSource;
}

/**
* Configures the {@link QueryEnhancerSelector} to be used.
*
* @param queryEnhancerSelector must not be {@literal null}.
* @param queryEnhancerSelectorType must not be {@literal null}.
*/
public void setQueryEnhancerSelector(Class<? extends QueryEnhancerSelector> queryEnhancerSelector) {
this.queryEnhancerSelector = bf -> {
public void setQueryEnhancerSelector(Class<? extends QueryEnhancerSelector> queryEnhancerSelectorType) {

this.queryEnhancerSelectorSource = bf -> {

if (bf != null) {

ObjectProvider<? extends QueryEnhancerSelector> beanProvider = bf.getBeanProvider(queryEnhancerSelector);
ObjectProvider<? extends QueryEnhancerSelector> beanProvider = bf.getBeanProvider(queryEnhancerSelectorType);
QueryEnhancerSelector selector = beanProvider.getIfAvailable();

if (selector != null) {
return selector;
}

if (bf instanceof AutowireCapableBeanFactory acbf) {
return acbf.createBean(queryEnhancerSelector);
return acbf.createBean(queryEnhancerSelectorType);
}
}

return BeanUtils.instantiateClass(queryEnhancerSelector);
return BeanUtils.instantiateClass(queryEnhancerSelectorType);
};
}

Expand All @@ -171,8 +172,8 @@ protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityM
factory.setQueryMethodFactory(queryMethodFactory);
}

if (queryEnhancerSelector != null) {
factory.setQueryEnhancerSelector(queryEnhancerSelector.apply(beanFactory));
if (queryEnhancerSelectorSource != null) {
factory.setQueryEnhancerSelector(queryEnhancerSelectorSource.apply(beanFactory));
}

return factory;
Expand Down

0 comments on commit 60a57dd

Please sign in to comment.