DATACMNS-1255 - Extend configuration of CDI repository settings.
We now extended CDI repository configuration to allow configuration of EvaluationContextProvider, NamedQueries, QueryLookupStrategy keys and the repository base class. CdiRepositoryConfiguration is now an interface with default-methods only providing default configuration values. Original pull request: #272.
This commit is contained in:
committed by
Oliver Gierke
parent
036ccde5ce
commit
919090bf20
@@ -41,9 +41,9 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.data.repository.config.CustomRepositoryImplementationDetector;
|
||||
import org.springframework.data.repository.config.DefaultRepositoryConfiguration;
|
||||
import org.springframework.data.repository.config.RepositoryBeanNameGenerator;
|
||||
import org.springframework.data.repository.config.SpringDataAnnotationBeanNameGenerator;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -407,6 +407,34 @@ public abstract class CdiRepositoryBean<T> implements Bean<T>, PassivationCapabl
|
||||
+ "in order to use custom repository implementations");
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the configuration from {@link CdiRepositoryConfiguration} to {@link RepositoryFactorySupport} by looking up
|
||||
* the actual configuration.
|
||||
*
|
||||
* @param repositoryFactory will never be {@literal null}.
|
||||
* @since 2.1
|
||||
*/
|
||||
protected void applyConfiguration(RepositoryFactorySupport repositoryFactory) {
|
||||
applyConfiguration(repositoryFactory, lookupConfiguration(beanManager, qualifiers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the configuration from {@link CdiRepositoryConfiguration} to {@link RepositoryFactorySupport} by looking up
|
||||
* the actual configuration.
|
||||
*
|
||||
* @param repositoryFactory will never be {@literal null}.
|
||||
* @param configuration will never be {@literal null}.
|
||||
* @since 2.1
|
||||
*/
|
||||
protected static void applyConfiguration(RepositoryFactorySupport repositoryFactory,
|
||||
CdiRepositoryConfiguration configuration) {
|
||||
|
||||
configuration.getEvaluationContextProvider().ifPresent(repositoryFactory::setEvaluationContextProvider);
|
||||
configuration.getNamedQueries().ifPresent(repositoryFactory::setNamedQueries);
|
||||
configuration.getQueryLookupStrategy().ifPresent(repositoryFactory::setQueryLookupStrategyKey);
|
||||
configuration.getRepositoryBeanClass().ifPresent(repositoryFactory::setRepositoryBaseClass);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
@@ -417,17 +445,7 @@ public abstract class CdiRepositoryBean<T> implements Bean<T>, PassivationCapabl
|
||||
qualifiers.toString());
|
||||
}
|
||||
|
||||
static enum DefaultCdiRepositoryConfiguration implements CdiRepositoryConfiguration {
|
||||
|
||||
enum DefaultCdiRepositoryConfiguration implements CdiRepositoryConfiguration {
|
||||
INSTANCE;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.cdi.CdiRepositoryConfiguration#getRepositoryImplementationPostfix()
|
||||
*/
|
||||
@Override
|
||||
public String getRepositoryImplementationPostfix() {
|
||||
return DefaultRepositoryConfiguration.DEFAULT_REPOSITORY_IMPLEMENTATION_POSTFIX;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
package org.springframework.data.repository.cdi;
|
||||
|
||||
import org.springframework.data.repository.config.DefaultRepositoryConfiguration;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.repository.core.NamedQueries;
|
||||
import org.springframework.data.repository.query.EvaluationContextProvider;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
|
||||
/**
|
||||
@@ -27,20 +30,53 @@ import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
*/
|
||||
public interface CdiRepositoryConfiguration {
|
||||
|
||||
/**
|
||||
* Return the {@link EvaluationContextProvider} to use. Can be {@link Optional#empty()} .
|
||||
*
|
||||
* @return the optional {@link EvaluationContextProvider} base to use, can be {@link Optional#empty()}, must not be
|
||||
* {@literal null}.
|
||||
* @since 2.1
|
||||
*/
|
||||
default Optional<EvaluationContextProvider> getEvaluationContextProvider() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link NamedQueries} to use. Can be {@link Optional#empty()}.
|
||||
*
|
||||
* @return the optional named queries to use, can be {@link Optional#empty()}, must not be {@literal null}.
|
||||
* @since 2.1
|
||||
*/
|
||||
default Optional<NamedQueries> getNamedQueries() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link QueryLookupStrategy.Key} to lookup queries. Can be {@link Optional#empty()}.
|
||||
*
|
||||
* @return the lookup strategy to use, can be {@link Optional#empty()}, must not be {@literal null}.
|
||||
* @since 2.1
|
||||
*/
|
||||
default Optional<QueryLookupStrategy.Key> getQueryLookupStrategy() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link Class repository base class} to use. Can be {@link Optional#empty()} .
|
||||
*
|
||||
* @return the optional repository base to use, can be {@link Optional#empty()}, must not be {@literal null}.
|
||||
* @since 2.1
|
||||
*/
|
||||
default Optional<Class<?>> getRepositoryBeanClass() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configured postfix to be used for looking up custom implementation classes.
|
||||
*
|
||||
* @return the postfix to use, must not be {@literal null}.
|
||||
*/
|
||||
String getRepositoryImplementationPostfix();
|
||||
|
||||
/**
|
||||
* Return the strategy to lookup queries.
|
||||
*
|
||||
* @return the lookup strategy to use.
|
||||
* @since 2.1
|
||||
*/
|
||||
default QueryLookupStrategy.Key getQueryLookupStrategy() {
|
||||
return DefaultRepositoryConfiguration.DEFAULT_QUERY_LOOKUP_STRATEGY;
|
||||
default String getRepositoryImplementationPostfix() {
|
||||
return "Impl";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user