Skip to content

Commit 2c772d6

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

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
@@ -134,18 +134,19 @@ private RepositoryFactoryInformation<Object, Serializable> getRepositoryFactoryI
134134

135135
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
136136

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

141-
while (repositoryInfo == null && !classToInspect.equals(Object.class)) {
142-
classToInspect = classToInspect.getSuperclass();
143-
repositoryInfo = repositoryFactoryInfos.get(ClassUtils.getUserClass(classToInspect));
140+
if (repositoryInfo != null) {
141+
return repositoryInfo;
144142
}
145143

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

148+
return EMPTY_REPOSITORY_FACTORY_INFO;
149+
}
149150

150151
/**
151152
* 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
@@ -113,9 +113,7 @@ public void exposesPersistentEntityForDomainTypes() {
113113
*/
114114
@Test
115115
public void findsRepositoryForSubTypes() {
116-
117-
Repositories repositories = new Repositories(context);
118-
assertThat(repositories.getPersistentEntity(AdvancedAddress.class), is(notNullValue()));
116+
assertThat(new Repositories(context).getPersistentEntity(AdvancedAddress.class), is(notNullValue()));
119117
}
120118

121119
class Person {}

0 commit comments

Comments
 (0)