Skip to content

DATACMNS-634 - Scan for repositories of superclasses. #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 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 in compliance with the License.
Expand Down Expand Up @@ -39,6 +39,7 @@
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Thomas Eizinger
*/
public class Repositories implements Iterable<Class<?>> {

Expand Down Expand Up @@ -133,11 +134,19 @@ private RepositoryFactoryInformation<Object, Serializable> getRepositoryFactoryI

Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);

RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos.get(ClassUtils
.getUserClass(domainClass));
Class<?> classToInspect = domainClass;
RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos
.get(ClassUtils.getUserClass(classToInspect));

while (repositoryInfo == null && !classToInspect.equals(Object.class)) {
classToInspect = classToInspect.getSuperclass();
repositoryInfo = repositoryFactoryInfos.get(ClassUtils.getUserClass(classToInspect));
}

return repositoryInfo == null ? EMPTY_REPOSITORY_FACTORY_INFO : repositoryInfo;
}


/**
* Returns the {@link EntityInformation} for the given domain class.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,22 @@ public void exposesPersistentEntityForDomainTypes() {
assertThat(repositories.getPersistentEntity(Address.class), is(notNullValue()));
}

/**
* @see DATAREST-321
*/
@Test
public void findsRepositoryForSubTypes() {

Repositories repositories = new Repositories(context);
assertThat(repositories.getPersistentEntity(AdvancedAddress.class), is(notNullValue()));
}

class Person {}

class Address {}

class AdvancedAddress extends Address { }

interface PersonRepository extends CrudRepository<Person, Long> {}

interface AddressRepository extends Repository<Address, Long> {}
Expand Down