From 112127d35f8ecd158104ec98d8f4a2b2f6f54f4d Mon Sep 17 00:00:00 2001 From: Phil Webb Date: Thu, 1 Sep 2011 12:45:49 +0100 Subject: [PATCH] DATACMNS-69 - Updated cache key to bean name rather than class. --- ...sitoryInterfaceAwareBeanPostProcessor.java | 55 ++++++++----------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryInterfaceAwareBeanPostProcessor.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryInterfaceAwareBeanPostProcessor.java index cba461c59..5cdc46d15 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryInterfaceAwareBeanPostProcessor.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/core/support/RepositoryInterfaceAwareBeanPostProcessor.java @@ -27,28 +27,22 @@ import org.springframework.beans.factory.config.InstantiationAwareBeanPostProces import org.springframework.beans.factory.config.TypedStringValue; import org.springframework.util.ClassUtils; - /** - * A - * {@link org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor} - * implementing {@code #predictBeanType(Class, String)} to return the configured - * repository interface from {@link RepositoryFactoryBeanSupport}s. This is done - * as shortcut to prevent the need of instantiating - * {@link RepositoryFactoryBeanSupport}s just to find out what repository - * interface they actually create. - * + * A {@link org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor} implementing + * {@code #predictBeanType(Class, String)} to return the configured repository interface from + * {@link RepositoryFactoryBeanSupport}s. This is done as shortcut to prevent the need of instantiating + * {@link RepositoryFactoryBeanSupport}s just to find out what repository interface they actually create. + * * @author Oliver Gierke */ -class RepositoryInterfaceAwareBeanPostProcessor extends - InstantiationAwareBeanPostProcessorAdapter implements BeanFactoryAware { +class RepositoryInterfaceAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter implements + BeanFactoryAware { - private static final Class REPOSITORY_TYPE = - RepositoryFactoryBeanSupport.class; + private static final Class REPOSITORY_TYPE = RepositoryFactoryBeanSupport.class; - private final Map, Class> cache = new ConcurrentHashMap, Class>(); + private final Map> cache = new ConcurrentHashMap>(); private ConfigurableListableBeanFactory context; - /* * (non-Javadoc) * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory) @@ -60,7 +54,6 @@ class RepositoryInterfaceAwareBeanPostProcessor extends } } - /* * (non-Javadoc) * @see org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter#predictBeanType(java.lang.Class, java.lang.String) @@ -73,26 +66,24 @@ class RepositoryInterfaceAwareBeanPostProcessor extends } BeanDefinition definition = context.getBeanDefinition(beanName); - PropertyValue value = - definition.getPropertyValues().getPropertyValue( - "repositoryInterface"); - - if (cache.containsKey(beanClass)) { - return cache.get(beanClass); + PropertyValue value = definition.getPropertyValues().getPropertyValue("repositoryInterface"); + + Class resolvedBeanClass = cache.get(beanName); + + if (cache.containsKey(beanName)) { + return cache.get(beanName); } - - Class resolvedBeanClass = getClassForPropertyValue(value); - cache.put(beanClass, resolvedBeanClass); + + resolvedBeanClass = getClassForPropertyValue(value); + cache.put(beanName, resolvedBeanClass); return resolvedBeanClass; } - /** - * Returns the class which is configured in the given {@link PropertyValue}. - * In case it is not a {@link TypedStringValue} or the value contained - * cannot be interpreted as {@link Class} it will return null. - * + * Returns the class which is configured in the given {@link PropertyValue}. In case it is not a + * {@link TypedStringValue} or the value contained cannot be interpreted as {@link Class} it will return null. + * * @param propertyValue * @return */ @@ -112,9 +103,7 @@ class RepositoryInterfaceAwareBeanPostProcessor extends } try { - return ClassUtils.resolveClassName(className, - RepositoryInterfaceAwareBeanPostProcessor.class - .getClassLoader()); + return ClassUtils.resolveClassName(className, RepositoryInterfaceAwareBeanPostProcessor.class.getClassLoader()); } catch (IllegalArgumentException ex) { return null; }