DATACMNS-634 - Polishing.

Simplified type traversal in Repositories.getRepositoryFactoryInfoFor(…) and unit tests.

Original pull request: #110.
This commit is contained in:
Oliver Gierke
2015-01-20 17:46:00 +01:00
parent 39556590c3
commit 229d5648df
2 changed files with 11 additions and 12 deletions

View File

@@ -139,18 +139,19 @@ public class Repositories implements Iterable<Class<?>> {
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
Class<?> classToInspect = domainClass;
RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos
.get(ClassUtils.getUserClass(classToInspect));
Class<?> userType = ClassUtils.getUserClass(domainClass);
RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos.get(userType);
while (repositoryInfo == null && !classToInspect.equals(Object.class)) {
classToInspect = classToInspect.getSuperclass();
repositoryInfo = repositoryFactoryInfos.get(ClassUtils.getUserClass(classToInspect));
if (repositoryInfo != null) {
return repositoryInfo;
}
return repositoryInfo == null ? EMPTY_REPOSITORY_FACTORY_INFO : repositoryInfo;
}
if (!userType.equals(Object.class)) {
return getRepositoryFactoryInfoFor(userType.getSuperclass());
}
return EMPTY_REPOSITORY_FACTORY_INFO;
}
/**
* Returns the {@link EntityInformation} for the given domain class.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except
@@ -130,9 +130,7 @@ public class RepositoriesUnitTests {
*/
@Test
public void findsRepositoryForSubTypes() {
Repositories repositories = new Repositories(context);
assertThat(repositories.getPersistentEntity(AdvancedAddress.class), is(notNullValue()));
assertThat(new Repositories(context).getPersistentEntity(AdvancedAddress.class), is(notNullValue()));
}
class EntityWithoutRepository {}