Skip to content

Commit 229d564

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

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,19 @@ private RepositoryFactoryInformation<Object, Serializable> getRepositoryFactoryI
139139

140140
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
141141

142-
Class<?> classToInspect = domainClass;
143-
RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos
144-
.get(ClassUtils.getUserClass(classToInspect));
142+
Class<?> userType = ClassUtils.getUserClass(domainClass);
143+
RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos.get(userType);
145144

146-
while (repositoryInfo == null && !classToInspect.equals(Object.class)) {
147-
classToInspect = classToInspect.getSuperclass();
148-
repositoryInfo = repositoryFactoryInfos.get(ClassUtils.getUserClass(classToInspect));
145+
if (repositoryInfo != null) {
146+
return repositoryInfo;
149147
}
150148

151-
return repositoryInfo == null ? EMPTY_REPOSITORY_FACTORY_INFO : repositoryInfo;
152-
}
149+
if (!userType.equals(Object.class)) {
150+
return getRepositoryFactoryInfoFor(userType.getSuperclass());
151+
}
153152

153+
return EMPTY_REPOSITORY_FACTORY_INFO;
154+
}
154155

155156
/**
156157
* Returns the {@link EntityInformation} for the given domain class.

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

+2-4
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)