Skip to content

Commit f359e93

Browse files
committed
DATACMNS-634 - Polishing.
Simplified type traversal in Repositories.getRepositoryFactoryInfoFor(…) and unit tests. Original pull request: #110.
1 parent 297688c commit f359e93

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/main/java/org/springframework/data/repository/support/Repositories.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,19 @@ private RepositoryFactoryInformation<Object, Serializable> getRepositoryFactoryI
136136

137137
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
138138

139-
Class<?> classToInspect = domainClass;
140-
RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos
141-
.get(ClassUtils.getUserClass(classToInspect));
139+
Class<?> userType = ClassUtils.getUserClass(domainClass);
140+
RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos.get(userType);
142141

143-
while (repositoryInfo == null && !classToInspect.equals(Object.class)) {
144-
classToInspect = classToInspect.getSuperclass();
145-
repositoryInfo = repositoryFactoryInfos.get(ClassUtils.getUserClass(classToInspect));
142+
if (repositoryInfo != null) {
143+
return repositoryInfo;
146144
}
147145

148-
return repositoryInfo == null ? EMPTY_REPOSITORY_FACTORY_INFO : repositoryInfo;
149-
}
146+
if (!userType.equals(Object.class)) {
147+
return getRepositoryFactoryInfoFor(userType.getSuperclass());
148+
}
150149

150+
return EMPTY_REPOSITORY_FACTORY_INFO;
151+
}
151152

152153
/**
153154
* Returns the {@link EntityInformation} for the given domain class.

src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2013 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except
@@ -130,9 +130,7 @@ public void shouldThrowMeaningfulExceptionWhenTheRepositoryForAGivenDomainClassC
130130
*/
131131
@Test
132132
public void findsRepositoryForSubTypes() {
133-
134-
Repositories repositories = new Repositories(context);
135-
assertThat(repositories.getPersistentEntity(AdvancedAddress.class), is(notNullValue()));
133+
assertThat(new Repositories(context).getPersistentEntity(AdvancedAddress.class), is(notNullValue()));
136134
}
137135

138136
class EntityWithoutRepository {}

0 commit comments

Comments
 (0)