DATAJPA-1230 - Polishing.
Introduced JpaRepositoryImplementation interface to combine JpaRepository, JpaSpecificationExecutor and a callback to set CrudMethodMetadata on the implementation instance. Refactored JpaRepositoryFactory to only rely on that interface and avoid references to SimpleJpaRepository.
This commit is contained in:
@@ -86,13 +86,10 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport {
|
||||
* @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getTargetRepository(org.springframework.data.repository.core.RepositoryMetadata)
|
||||
*/
|
||||
@Override
|
||||
protected Object getTargetRepository(RepositoryInformation information) {
|
||||
protected final JpaRepositoryImplementation<?, ?> getTargetRepository(RepositoryInformation information) {
|
||||
|
||||
Object repository = getTargetRepository(information, entityManager);
|
||||
if (repository instanceof RepositoryMethodMetadataAware) {
|
||||
((RepositoryMethodMetadataAware) repository)
|
||||
.setRepositoryMethodMetadata(crudMethodMetadataPostProcessor.getCrudMethodMetadata());
|
||||
}
|
||||
JpaRepositoryImplementation<?, ?> repository = getTargetRepository(information, entityManager);
|
||||
repository.setRepositoryMethodMetadata(crudMethodMetadataPostProcessor.getCrudMethodMetadata());
|
||||
|
||||
return repository;
|
||||
}
|
||||
@@ -100,16 +97,19 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport {
|
||||
/**
|
||||
* Callback to create a {@link JpaRepository} instance with the given {@link EntityManager}
|
||||
*
|
||||
* @param <T>
|
||||
* @param <ID>
|
||||
* @param entityManager
|
||||
* @param information will never be {@literal null}.
|
||||
* @param entityManager will never be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
protected Object getTargetRepository(RepositoryInformation information, EntityManager entityManager) {
|
||||
protected JpaRepositoryImplementation<?, ?> getTargetRepository(RepositoryInformation information,
|
||||
EntityManager entityManager) {
|
||||
|
||||
JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(information.getDomainType());
|
||||
Object repository = getTargetRepositoryViaReflection(information, entityInformation, entityManager);
|
||||
|
||||
return getTargetRepositoryViaReflection(information, entityInformation, entityManager);
|
||||
Assert.isInstanceOf(JpaRepositoryImplementation.class, repository);
|
||||
|
||||
return (JpaRepositoryImplementation<?, ?>) repository;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -15,16 +15,23 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.support;
|
||||
|
||||
import org.springframework.data.jpa.repository.support.CrudMethodMetadata;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
|
||||
/**
|
||||
* implemented by {@link org.springframework.data.jpa.repository.JpaRepository} implementations requiring
|
||||
* {@link CrudMethodMetadata}
|
||||
* SPI interface to be implemented by {@link JpaRepository} implementations.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Stefan Fussenegger
|
||||
*/
|
||||
public interface RepositoryMethodMetadataAware {
|
||||
@NoRepositoryBean
|
||||
public interface JpaRepositoryImplementation<T, ID> extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> {
|
||||
|
||||
/**
|
||||
* Configures the {@link CrudMethodMetadata} to be used with the repository.
|
||||
*
|
||||
* @param crudMethodMetadata must not be {@literal null}.
|
||||
*/
|
||||
void setRepositoryMethodMetadata(CrudMethodMetadata crudMethodMetadata);
|
||||
|
||||
}
|
||||
@@ -48,8 +48,6 @@ import org.springframework.data.jpa.convert.QueryByExamplePredicateBuilder;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.provider.PersistenceProvider;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.query.QueryUtils;
|
||||
import org.springframework.data.jpa.repository.support.QueryHints.NoHints;
|
||||
import org.springframework.data.repository.support.PageableExecutionUtils;
|
||||
@@ -73,8 +71,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
@Repository
|
||||
@Transactional(readOnly = true)
|
||||
public class SimpleJpaRepository<T, ID>
|
||||
implements JpaRepository<T, ID>, JpaSpecificationExecutor<T>, RepositoryMethodMetadataAware {
|
||||
public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T, ID> {
|
||||
|
||||
private static final String ID_MUST_NOT_BE_NULL = "The given id must not be null!";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user