DATACMNS-1764 - Allow registration of RepositoryFactory customizers.
Original Pull Request: #455
This commit is contained in:
committed by
Christoph Strobl
parent
e77947f0a5
commit
35a3d3cde9
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.repository.core.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -71,6 +72,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
|
||||
private BeanFactory beanFactory;
|
||||
private boolean lazyInit = false;
|
||||
private Optional<QueryMethodEvaluationContextProvider> evaluationContextProvider = Optional.empty();
|
||||
private List<RepositoryFactoryCustomizer> repositoryFactoryCustomizers = new ArrayList<>();
|
||||
private ApplicationEventPublisher publisher;
|
||||
|
||||
private Lazy<T> repository;
|
||||
@@ -154,6 +156,19 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
|
||||
this.evaluationContextProvider = Optional.of(evaluationContextProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@link RepositoryFactoryCustomizer} to customize the {@link RepositoryFactorySupport repository factor}
|
||||
* before creating the repository.
|
||||
*
|
||||
* @param customizer must not be {@literal null}.
|
||||
* @since 2.4
|
||||
*/
|
||||
public void addRepositoryFactoryCustomizer(RepositoryFactoryCustomizer customizer) {
|
||||
|
||||
Assert.notNull(customizer, "RepositoryFactoryCustomizer must not be null");
|
||||
this.repositoryFactoryCustomizers.add(customizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures whether to initialize the repository proxy lazily. This defaults to {@literal false}.
|
||||
*
|
||||
@@ -293,6 +308,8 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
|
||||
|
||||
repositoryBaseClass.ifPresent(this.factory::setRepositoryBaseClass);
|
||||
|
||||
this.repositoryFactoryCustomizers.forEach(customizer -> customizer.customize(this.factory));
|
||||
|
||||
RepositoryFragments customImplementationFragment = customImplementation //
|
||||
.map(RepositoryFragments::just) //
|
||||
.orElseGet(RepositoryFragments::empty);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2020 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.repository.core.support;
|
||||
|
||||
/**
|
||||
* Callback interface that can be used to to customize a {@link RepositoryFactorySupport repository factory}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @since 2.4
|
||||
*/
|
||||
public interface RepositoryFactoryCustomizer {
|
||||
|
||||
/**
|
||||
* Callback to customize a {@link RepositoryFactorySupport} instance.
|
||||
*
|
||||
* @param repositoryFactory repository factory to customize.
|
||||
*/
|
||||
void customize(RepositoryFactorySupport repositoryFactory);
|
||||
}
|
||||
Reference in New Issue
Block a user