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

fix: warning message about "not eligible ..." #73

Merged
merged 1 commit into from
Dec 20, 2023
Merged
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
Expand Up @@ -22,6 +22,8 @@

import static java.util.Optional.ofNullable;
import static java.util.stream.Stream.concat;
import static org.springframework.beans.factory.config.BeanDefinition.ROLE_INFRASTRUCTURE;
import static org.springframework.util.Assert.notNull;

import java.util.List;
import java.util.Optional;
Expand All @@ -36,6 +38,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
import org.springframework.data.repository.core.support.RepositoryFactoryCustomizer;
import tw.com.softleader.data.jpa.spec.SkippingStrategy;
Expand Down Expand Up @@ -89,6 +92,7 @@ SpecMapper specMapper(
return mapper.build();
}

@Role(ROLE_INFRASTRUCTURE)
@ConditionalOnBean(JpaRepositoryFactoryBean.class)
static class RepositoryFactoryCustomizerAutoConfiguration {

Expand All @@ -100,20 +104,31 @@ JpaRepositoryFactoryBeanPostProcessor jpaRepositoryFactoryBeanPostProcessor(
}

@Bean
RepositoryFactoryCustomizer repositoryBaseClassCustomizer(SpecMapperProperties properties) {
log.debug(
"Configuring repository-base-class with '{}'",
properties.getRepositoryBaseClass().getName());
return factory -> factory.setRepositoryBaseClass(properties.getRepositoryBaseClass());
@Role(ROLE_INFRASTRUCTURE)
RepositoryFactoryCustomizer repositoryBaseClassCustomizer(
ObjectProvider<SpecMapperProperties> propertiesProvider) {
return factory -> {
var properties = propertiesProvider.getIfAvailable();
notNull(properties, "SpecMapperProperties must not be null");
log.debug(
"Configuring repository-base-class with '{}'",
properties.getRepositoryBaseClass().getName());
factory.setRepositoryBaseClass(properties.getRepositoryBaseClass());
};
}

@Bean
RepositoryFactoryCustomizer specMapperCustomizer(SpecMapper specMapper) {
return factory ->
factory.addRepositoryProxyPostProcessor(
(proxyFactory, repositoryInformation) ->
getQueryBySpecExecutorAdapter(proxyFactory)
.ifPresent(target -> target.setSpecMapper(specMapper)));
@Role(ROLE_INFRASTRUCTURE)
RepositoryFactoryCustomizer specMapperCustomizer(
ObjectProvider<SpecMapper> specMapperProvider) {
return factory -> {
var specMapper = specMapperProvider.getIfAvailable();
notNull(specMapper, "SpecMapper must not be null");
factory.addRepositoryProxyPostProcessor(
(proxyFactory, repositoryInformation) ->
getQueryBySpecExecutorAdapter(proxyFactory)
.ifPresent(target -> target.setSpecMapper(specMapper)));
};
}

@SneakyThrows
Expand Down