Polishing.
Update exception messages, align method names, extract methods Original Pull Request: #2488
This commit is contained in:
@@ -108,27 +108,23 @@ public class CustomRepositoryImplementationDetector {
|
||||
.filter(lookup::matches) //
|
||||
.collect(StreamUtils.toUnmodifiableSet());
|
||||
|
||||
return selectImplementationCandidate(lookup, definitions, () -> {
|
||||
|
||||
if (definitions.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.of(definitions.iterator().next());
|
||||
});
|
||||
return selectImplementationCandidate(lookup, definitions);
|
||||
}
|
||||
|
||||
private static Optional<AbstractBeanDefinition> selectImplementationCandidate(
|
||||
ImplementationLookupConfiguration lookup, Set<BeanDefinition> definitions,
|
||||
Supplier<Optional<BeanDefinition>> fallback) {
|
||||
ImplementationLookupConfiguration lookup, Set<BeanDefinition> definitions) {
|
||||
|
||||
return SelectionSet //
|
||||
.of(definitions, c -> c.isEmpty() ? fallback.get() : throwAmbiguousCustomImplementationException(c)) //
|
||||
.of(definitions, c -> c.isEmpty() ? firstOrEmptyBeanDefinition(definitions) : throwAmbiguousCustomImplementationException(c)) //
|
||||
.filterIfNecessary(lookup::hasMatchingBeanName) //
|
||||
.uniqueResult() //
|
||||
.map(AbstractBeanDefinition.class::cast);
|
||||
}
|
||||
|
||||
static Optional<BeanDefinition> firstOrEmptyBeanDefinition(Set<BeanDefinition> definitions) {
|
||||
return definitions.isEmpty() ? Optional.empty() : Optional.of(definitions.iterator().next());
|
||||
}
|
||||
|
||||
private Set<BeanDefinition> findCandidateBeanDefinitions(ImplementationDetectionConfiguration config) {
|
||||
|
||||
String postfix = config.getImplementationPostfix();
|
||||
|
||||
@@ -46,7 +46,7 @@ class DefaultImplementationLookupConfiguration implements ImplementationLookupCo
|
||||
|
||||
Assert.notNull(config, "ImplementationDetectionConfiguration must not be null");
|
||||
Assert.hasText(interfaceName, "Interface name must not be null or empty");
|
||||
Assert.hasText(beanName, "Bean name must not be null or empty!");
|
||||
Assert.hasText(beanName, "Bean name must not be null or empty");
|
||||
|
||||
this.config = config;
|
||||
this.interfaceName = interfaceName;
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
@@ -195,31 +194,8 @@ class RepositoryBeanDefinitionBuilder {
|
||||
return Optional.of(configurationBeanName);
|
||||
}
|
||||
|
||||
Optional<AbstractBeanDefinition> beanDefinition = implementationDetector.detectCustomImplementation(lookup);
|
||||
|
||||
return beanDefinition.map(it -> {
|
||||
|
||||
String scannedBeanName = configuration.getConfigurationSource().generateBeanName(it);
|
||||
it.setSource(configuration.getSource());
|
||||
|
||||
if (registry.containsBeanDefinition(scannedBeanName)) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Custom repository implementation already registered: %s %s", scannedBeanName,
|
||||
it.getBeanClassName()));
|
||||
}
|
||||
} else {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Registering custom repository implementation: %s %s", scannedBeanName,
|
||||
it.getBeanClassName()));
|
||||
}
|
||||
|
||||
registry.registerBeanDefinition(scannedBeanName, it);
|
||||
}
|
||||
|
||||
return scannedBeanName;
|
||||
});
|
||||
return implementationDetector.detectCustomImplementation(lookup)
|
||||
.map(it -> potentiallyRegisterRepositoryImplementation(configuration, it));
|
||||
}
|
||||
|
||||
private String registerRepositoryFragments(RepositoryConfiguration<?> configuration) {
|
||||
@@ -264,6 +240,31 @@ class RepositoryBeanDefinitionBuilder {
|
||||
configuration.getConfigurationSource().generateBeanName(bd)));
|
||||
}
|
||||
|
||||
private String potentiallyRegisterRepositoryImplementation(RepositoryConfiguration<?> configuration,
|
||||
AbstractBeanDefinition beanDefinition) {
|
||||
|
||||
String targetBeanName = configuration.getConfigurationSource().generateBeanName(beanDefinition);
|
||||
beanDefinition.setSource(configuration.getSource());
|
||||
|
||||
if (registry.containsBeanDefinition(targetBeanName)) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Custom repository implementation already registered: %s %s", targetBeanName,
|
||||
beanDefinition.getBeanClassName()));
|
||||
}
|
||||
} else {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Registering custom repository implementation: %s %s", targetBeanName,
|
||||
beanDefinition.getBeanClassName()));
|
||||
}
|
||||
|
||||
registry.registerBeanDefinition(targetBeanName, beanDefinition);
|
||||
}
|
||||
|
||||
return targetBeanName;
|
||||
}
|
||||
|
||||
private void potentiallyRegisterFragmentImplementation(RepositoryConfiguration<?> repositoryConfiguration,
|
||||
RepositoryFragmentConfiguration fragmentConfiguration) {
|
||||
|
||||
|
||||
@@ -75,9 +75,9 @@ public final class RepositoryFragmentConfiguration {
|
||||
private RepositoryFragmentConfiguration(String interfaceName, String className,
|
||||
Optional<AbstractBeanDefinition> beanDefinition, String beanName) {
|
||||
|
||||
Assert.hasText(interfaceName, "Interface name must not be null or empty!");
|
||||
Assert.notNull(beanDefinition, "Bean definition must not be null!");
|
||||
Assert.notNull(beanName, "Bean name must not be null!");
|
||||
Assert.hasText(interfaceName, "Interface name must not be null or empty");
|
||||
Assert.notNull(beanDefinition, "Bean definition must not be null");
|
||||
Assert.notNull(beanName, "Bean name must not be null");
|
||||
|
||||
this.interfaceName = interfaceName;
|
||||
this.className = className;
|
||||
|
||||
@@ -46,8 +46,8 @@ public abstract class RepositoryInformationSupport implements RepositoryInformat
|
||||
|
||||
public RepositoryInformationSupport(Supplier<RepositoryMetadata> metadata, Supplier<Class<?>> repositoryBaseClass) {
|
||||
|
||||
Assert.notNull(metadata, "Repository metadata must not be null!");
|
||||
Assert.notNull(repositoryBaseClass, "Repository base class must not be null!");
|
||||
Assert.notNull(metadata, "Repository metadata must not be null");
|
||||
Assert.notNull(repositoryBaseClass, "Repository base class must not be null");
|
||||
|
||||
this.metadata = Lazy.of(metadata);
|
||||
this.repositoryBaseClass = Lazy.of(repositoryBaseClass);
|
||||
|
||||
Reference in New Issue
Block a user