Search in sources :

Example 1 with Optionals

use of org.springframework.data.util.Optionals in project spring-data-commons by spring-projects.

the class RepositoryBeanDefinitionBuilder method registerRepositoryFragmentsImplementation.

private Stream<RepositoryFragmentConfiguration> registerRepositoryFragmentsImplementation(RepositoryConfiguration<?> configuration) {
    ClassMetadata classMetadata = getClassMetadata(configuration.getRepositoryInterface());
    RepositoryFragmentDiscovery fragmentConfiguration = new DefaultRepositoryFragmentDiscovery(configuration);
    return // 
    Arrays.stream(classMetadata.getInterfaceNames()).filter(// 
    it -> FragmentMetadata.isCandidate(it, metadataReaderFactory)).map(// 
    it -> FragmentMetadata.of(it, fragmentConfiguration)).map(// 
    it -> detectRepositoryFragmentConfiguration(it, configuration.getConfigurationSource())).flatMap(// 
    Optionals::toStream).peek(// 
    it -> potentiallyRegisterFragmentImplementation(configuration, it)).peek(it -> potentiallyRegisterRepositoryFragment(configuration, it));
}
Also used : ClassMetadata(org.springframework.core.type.ClassMetadata) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Arrays(java.util.Arrays) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) TypeFilter(org.springframework.core.type.filter.TypeFilter) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LoggerFactory(org.slf4j.LoggerFactory) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) ClassMetadata(org.springframework.core.type.ClassMetadata) ExtensionAwareEvaluationContextProvider(org.springframework.data.repository.query.ExtensionAwareEvaluationContextProvider) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) Optionals(org.springframework.data.util.Optionals) RepositoryFragmentsFactoryBean(org.springframework.data.repository.core.support.RepositoryFragmentsFactoryBean) Logger(org.slf4j.Logger) ResourceLoader(org.springframework.core.io.ResourceLoader) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) IOException(java.io.IOException) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) Collectors(java.util.stream.Collectors) List(java.util.List) ParsingUtils(org.springframework.data.config.ParsingUtils) Stream(java.util.stream.Stream) RepositoryFragment(org.springframework.data.repository.core.support.RepositoryFragment) MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) Environment(org.springframework.core.env.Environment) Streamable(org.springframework.data.util.Streamable) Optional(java.util.Optional) Assert(org.springframework.util.Assert) Optionals(org.springframework.data.util.Optionals)

Example 2 with Optionals

use of org.springframework.data.util.Optionals in project spring-data-commons by spring-projects.

the class CdiRepositoryContext method getRepositoryFragments.

/**
 * Discover {@link RepositoryFragmentConfiguration fragment configurations} for a {@link Class repository interface}.
 *
 * @param configuration must not be {@literal null}.
 * @param repositoryInterface must not be {@literal null}.
 * @return {@link Stream} of {@link RepositoryFragmentConfiguration fragment configurations}.
 */
Stream<RepositoryFragmentConfiguration> getRepositoryFragments(CdiRepositoryConfiguration configuration, Class<?> repositoryInterface) {
    ClassMetadata classMetadata = getClassMetadata(metadataReaderFactory, repositoryInterface.getName());
    RepositoryFragmentDiscovery fragmentConfiguration = new CdiRepositoryFragmentDiscovery(configuration);
    return // 
    Arrays.stream(classMetadata.getInterfaceNames()).filter(// 
    it -> FragmentMetadata.isCandidate(it, metadataReaderFactory)).map(// 
    it -> FragmentMetadata.of(it, fragmentConfiguration)).map(// 
    this::detectRepositoryFragmentConfiguration).flatMap(Optionals::toStream);
}
Also used : ClassMetadata(org.springframework.core.type.ClassMetadata) Arrays(java.util.Arrays) TypeFilter(org.springframework.core.type.filter.TypeFilter) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) ClassMetadata(org.springframework.core.type.ClassMetadata) NoRepositoryBean(org.springframework.data.repository.NoRepositoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) RepositoryFragmentDiscovery(org.springframework.data.repository.config.RepositoryFragmentDiscovery) Optionals(org.springframework.data.util.Optionals) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) CustomRepositoryImplementationDetector(org.springframework.data.repository.config.CustomRepositoryImplementationDetector) AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) RepositoryFragmentConfiguration(org.springframework.data.repository.config.RepositoryFragmentConfiguration) ResourceLoader(org.springframework.core.io.ResourceLoader) ClassUtils(org.springframework.util.ClassUtils) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) IOException(java.io.IOException) StandardEnvironment(org.springframework.core.env.StandardEnvironment) CreationException(javax.enterprise.inject.CreationException) FragmentMetadata(org.springframework.data.repository.config.FragmentMetadata) Stream(java.util.stream.Stream) MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) Environment(org.springframework.core.env.Environment) Streamable(org.springframework.data.util.Streamable) Optional(java.util.Optional) Collections(java.util.Collections) Assert(org.springframework.util.Assert) Optionals(org.springframework.data.util.Optionals) RepositoryFragmentDiscovery(org.springframework.data.repository.config.RepositoryFragmentDiscovery)

Aggregations

IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Optional (java.util.Optional)2 Stream (java.util.stream.Stream)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)2 Environment (org.springframework.core.env.Environment)2 ResourceLoader (org.springframework.core.io.ResourceLoader)2 ClassMetadata (org.springframework.core.type.ClassMetadata)2 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)2 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)2 TypeFilter (org.springframework.core.type.filter.TypeFilter)2 Optionals (org.springframework.data.util.Optionals)2 Streamable (org.springframework.data.util.Streamable)2 Assert (org.springframework.util.Assert)2 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 CreationException (javax.enterprise.inject.CreationException)1 UnsatisfiedResolutionException (javax.enterprise.inject.UnsatisfiedResolutionException)1