From 2c772d60dea27b6990aa360f53c497842caeb369 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 20 Jan 2015 17:46:00 +0100 Subject: [PATCH] DATACMNS-634 - Polishing. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplified type traversal in Repositories.getRepositoryFactoryInfoFor(…) and unit tests. Original pull request: #110. --- .../data/repository/support/Repositories.java | 17 +++++++++-------- .../support/RepositoriesUnitTests.java | 6 ++---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/springframework/data/repository/support/Repositories.java b/src/main/java/org/springframework/data/repository/support/Repositories.java index 70d5f5d68..199a52ace 100644 --- a/src/main/java/org/springframework/data/repository/support/Repositories.java +++ b/src/main/java/org/springframework/data/repository/support/Repositories.java @@ -134,18 +134,19 @@ public class Repositories implements Iterable> { Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); - Class classToInspect = domainClass; - RepositoryFactoryInformation repositoryInfo = repositoryFactoryInfos - .get(ClassUtils.getUserClass(classToInspect)); + Class userType = ClassUtils.getUserClass(domainClass); + RepositoryFactoryInformation 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. diff --git a/src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java b/src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java index 09e47d423..1e8af754d 100644 --- a/src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java +++ b/src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java @@ -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 @@ -113,9 +113,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 Person {}