DATAKV-87 - Allow definition of target Map type via @EnableMapRepositories.
We added the configuration attribute ‘mapType’ to @EnableMapRepositories which allows to change defaulting of the Map structure used by the MapKeyValueAdapter. To do so we now register a MapKeyValueAdapterFactory and delegate creation of the adapter to it. This also allows usage of interface types such as plain java.util.Map which will initialize the adapter with the approximated type resolved via CollectionFactory. Original pull request #2.
This commit is contained in:
committed by
Oliver Gierke
parent
5a14d7bc12
commit
b16a454c6c
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.data.keyvalue.core.KeyValueAdapter;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
import org.springframework.data.keyvalue.repository.KeyValueRepository;
|
||||
import org.springframework.data.keyvalue.repository.query.SpelQueryCreator;
|
||||
@@ -131,10 +132,12 @@ public abstract class KeyValueRepositoryConfigurationExtension extends Repositor
|
||||
|
||||
String keyValueTemplateName = configurationSource.getAttribute(KEY_VALUE_TEMPLATE_BEAN_REF_ATTRIBUTE);
|
||||
|
||||
// No custom template reference configured
|
||||
if (getDefaultKeyValueTemplateRef().equals(keyValueTemplateName)) {
|
||||
// No custom template reference configured and no matching bean definition found
|
||||
if (getDefaultKeyValueTemplateRef().equals(keyValueTemplateName)
|
||||
&& !registry.containsBeanDefinition(keyValueTemplateName)) {
|
||||
|
||||
RootBeanDefinition beanDefinition = getDefaultKeyValueTemplateBeanDefinition();
|
||||
registerTemplateInfrastructure(registry, configurationSource);
|
||||
RootBeanDefinition beanDefinition = getDefaultKeyValueTemplateBeanDefinition(configurationSource);
|
||||
|
||||
if (beanDefinition != null) {
|
||||
registerIfNotAlreadyRegistered(beanDefinition, registry, keyValueTemplateName, configurationSource.getSource());
|
||||
@@ -142,12 +145,24 @@ public abstract class KeyValueRepositoryConfigurationExtension extends Repositor
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register infrastructure components such as {@link KeyValueAdapter} required for default template.
|
||||
*
|
||||
* @param registry
|
||||
* @param configurationSource
|
||||
*/
|
||||
protected void registerTemplateInfrastructure(BeanDefinitionRegistry registry,
|
||||
RepositoryConfigurationSource configurationSource) {
|
||||
// nothing to register by default
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default {@link RootBeanDefinition} for {@link org.springframework.data.keyvalue.core.KeyValueTemplate}.
|
||||
*
|
||||
* @return {@literal null} to explicitly not register a template.
|
||||
*/
|
||||
protected RootBeanDefinition getDefaultKeyValueTemplateBeanDefinition() {
|
||||
protected RootBeanDefinition getDefaultKeyValueTemplateBeanDefinition(
|
||||
RepositoryConfigurationSource configurationSource) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user