Closed
Description
If I have a class Id and a domain class Domain and I defined a repository as:
public interface StringDomainRepository extends CrudRepository<Id<String>, Domain<String>> {}
Then the RepositoryMetadata getIdType() and getDomainType() methods will return the erased types (Id and Domain) even though the information would be there and could be returned as Type rather than Class<?>.
I propose to change the interface as:
/**
* Metadata for repository interfaces.
*
* @author Oliver Gierke
* @author Mark Paluch
*/
public interface RepositoryMetadata {
/**
* Returns the id class the given class is declared for.
*
* @return the id class of the entity managed by the repository.
*/
TypeInformation<?> getIdType();
/**
* Returns the domain class the repository is declared for.
*
* @return the domain class the repository is handling.
*/
TypeInformation<?> getDomainType();
/**
* Returns the repository interface.
*
* @return
*/
Class<?> getRepositoryInterface();
/**
* Returns the type {@link Method} return type as it is declared in the repository. Considers suspended methods and
* does not unwrap component types but leaves those for further inspection.
*
* @param method
* @return
* @since 2.4
*/
TypeInformation<?> getReturnType(Method method);
/**
* Returns the domain class returned by the given {@link Method}. In contrast to {@link #getReturnType(Method)}, this
* method extracts the type from {@link Collection}s and {@link org.springframework.data.domain.Page} as well.
*
* @param method
* @return
* @see #getReturnType(Method)
*/
Class<?> getReturnedDomainClass(Method method);
/**
* Returns {@link CrudMethods} meta information for the repository.
*
* @return
*/
CrudMethods getCrudMethods();
/**
* Returns whether the repository is a paging one.
*
* @return
*/
boolean isPagingRepository();
/**
* Returns the set of types the repository shall be discoverable for when trying to look up a repository by domain
* type.
*
* @see Repositories#getRepositoryFor(Class)
* @return the set of types the repository shall be discoverable for when trying to look up a repository by domain
* type, must not be {@literal null}.
* @since 1.11
*/
Set<Class<?> getAlternativeDomainTypes();
/**
* Returns whether the repository is a reactive one, i.e. if it uses reactive types in one of its methods.
*
* @return
* @since 2.0
*/
boolean isReactiveRepository();
}
This way lower level components, like for example GenericConverters, would be able to have the full type information.