|
|
|
@ -15,16 +15,20 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.springframework.data.repository.config; |
|
|
|
package org.springframework.data.repository.config; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.beans.factory.config.BeanDefinition.*; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.config.RuntimeBeanReference; |
|
|
|
import org.springframework.beans.factory.support.AbstractBeanDefinition; |
|
|
|
import org.springframework.beans.factory.support.AbstractBeanDefinition; |
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; |
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
import org.springframework.core.io.ResourceLoader; |
|
|
|
import org.springframework.core.io.ResourceLoader; |
|
|
|
@ -35,6 +39,7 @@ import org.springframework.data.repository.core.support.RepositoryFragment; |
|
|
|
import org.springframework.data.repository.core.support.RepositoryFragmentsFactoryBean; |
|
|
|
import org.springframework.data.repository.core.support.RepositoryFragmentsFactoryBean; |
|
|
|
import org.springframework.data.util.Optionals; |
|
|
|
import org.springframework.data.util.Optionals; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
import org.springframework.util.ClassUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Builder to create {@link BeanDefinitionBuilder} instance to eventually create Spring Data repository instances. |
|
|
|
* Builder to create {@link BeanDefinitionBuilder} instance to eventually create Spring Data repository instances. |
|
|
|
@ -119,17 +124,8 @@ class RepositoryBeanDefinitionBuilder { |
|
|
|
builder.addDependsOn(it); |
|
|
|
builder.addDependsOn(it); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
BeanDefinitionBuilder fragmentsBuilder = BeanDefinitionBuilder |
|
|
|
String fragmentsBeanName = registerRepositoryFragments(configuration); |
|
|
|
.rootBeanDefinition(RepositoryFragmentsFactoryBean.class); |
|
|
|
builder.addPropertyValue("repositoryFragments", new RuntimeBeanReference(fragmentsBeanName)); |
|
|
|
|
|
|
|
|
|
|
|
List<String> fragmentBeanNames = registerRepositoryFragmentsImplementation(configuration) //
|
|
|
|
|
|
|
|
.map(RepositoryFragmentConfiguration::getFragmentBeanName) //
|
|
|
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fragmentsBuilder.addConstructorArgValue(fragmentBeanNames); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
builder.addPropertyValue("repositoryFragments", |
|
|
|
|
|
|
|
ParsingUtils.getSourceBeanDefinition(fragmentsBuilder, configuration.getSource())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return builder; |
|
|
|
return builder; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -161,6 +157,25 @@ class RepositoryBeanDefinitionBuilder { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String registerRepositoryFragments(RepositoryConfiguration<?> configuration) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BeanDefinitionBuilder fragmentsBuilder = BeanDefinitionBuilder |
|
|
|
|
|
|
|
.rootBeanDefinition(RepositoryFragmentsFactoryBean.class) //
|
|
|
|
|
|
|
|
.setRole(ROLE_INFRASTRUCTURE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> fragmentBeanNames = registerRepositoryFragmentsImplementation(configuration) //
|
|
|
|
|
|
|
|
.map(RepositoryFragmentConfiguration::getFragmentBeanName) //
|
|
|
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fragmentsBuilder.addConstructorArgValue(fragmentBeanNames); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String fragmentsBeanName = BeanDefinitionReaderUtils |
|
|
|
|
|
|
|
.uniqueBeanName(String.format("%s.%s.fragments", extension.getModuleName().toLowerCase(Locale.ROOT), |
|
|
|
|
|
|
|
ClassUtils.getShortName(configuration.getRepositoryInterface())), registry); |
|
|
|
|
|
|
|
registry.registerBeanDefinition(fragmentsBeanName, fragmentsBuilder.getBeanDefinition()); |
|
|
|
|
|
|
|
return fragmentsBeanName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Stream<RepositoryFragmentConfiguration> registerRepositoryFragmentsImplementation( |
|
|
|
private Stream<RepositoryFragmentConfiguration> registerRepositoryFragmentsImplementation( |
|
|
|
RepositoryConfiguration<?> configuration) { |
|
|
|
RepositoryConfiguration<?> configuration) { |
|
|
|
|
|
|
|
|
|
|
|
|