DATACMNS-1215 - Fixed repository lookup for proxy domain classes.
We now consistently use the user class for repository (metadata) lookup in Repositories.
This commit is contained in:
@@ -121,7 +121,9 @@ public class Repositories implements Iterable<Class<?>> {
|
|||||||
|
|
||||||
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
|
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
|
||||||
|
|
||||||
return repositoryFactoryInfos.containsKey(domainClass);
|
Class<?> userClass = ClassUtils.getUserClass(domainClass);
|
||||||
|
|
||||||
|
return repositoryFactoryInfos.containsKey(userClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,7 +136,9 @@ public class Repositories implements Iterable<Class<?>> {
|
|||||||
|
|
||||||
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
|
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
|
||||||
|
|
||||||
String repositoryBeanName = repositoryBeanNames.get(domainClass);
|
Class<?> userClass = ClassUtils.getUserClass(domainClass);
|
||||||
|
String repositoryBeanName = repositoryBeanNames.get(userClass);
|
||||||
|
|
||||||
return repositoryBeanName == null || beanFactory == null ? null : beanFactory.getBean(repositoryBeanName);
|
return repositoryBeanName == null || beanFactory == null ? null : beanFactory.getBean(repositoryBeanName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
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.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
@@ -139,6 +140,23 @@ public class RepositoriesUnitTests {
|
|||||||
assertThat(information.getRepositoryInterface(), is(typeCompatibleWith(PersonRepository.class)));
|
assertThat(information.getRepositoryInterface(), is(typeCompatibleWith(PersonRepository.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // DATACMNS-1215
|
||||||
|
public void exposesRepositoryForProxyType() {
|
||||||
|
|
||||||
|
ProxyFactory factory = new ProxyFactory();
|
||||||
|
factory.setTarget(new Person());
|
||||||
|
factory.setProxyTargetClass(true);
|
||||||
|
|
||||||
|
Object proxy = factory.getProxy();
|
||||||
|
|
||||||
|
assertThat(ClassUtils.isCglibProxy(proxy), is(true));
|
||||||
|
|
||||||
|
Repositories repositories = new Repositories(context);
|
||||||
|
|
||||||
|
assertThat(repositories.hasRepositoryFor(proxy.getClass()), is(true));
|
||||||
|
assertThat(repositories.getRepositoryFor(proxy.getClass()), is(notNullValue()));
|
||||||
|
}
|
||||||
|
|
||||||
class Person {}
|
class Person {}
|
||||||
|
|
||||||
class Address {}
|
class Address {}
|
||||||
|
|||||||
Reference in New Issue
Block a user