DATACMNS-1117 - Fixed creation of RepositoryInformation in RepositoryFactoryBeanSupport.
RepositoryFactoryBeanSupport.getRepositoryInformation() previously didn't consider any store-specific compositions (incl. store-specific fragments like the Querydsl support) as it just handed a fragment with the custom implementation to RepositoryFactorySupport. This is now fixed by improving the API in RepositoryFactorySupport which now exposes a getRepositoryInformation(RepositoryMetadata, RepositoryFragments) which creates a fresh RepositoryComposition from the given RepositoryMetadata. Intermediate setup methods are still kept around but private as RepositoryFactorySupport.getRepository(…) still needs to forward the base RepositoryComposition to method interceptors for query result mapping.
This commit is contained in:
@@ -22,10 +22,12 @@ import java.util.Optional;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.repository.core.EntityInformation;
|
||||
import org.springframework.data.repository.core.NamedQueries;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactorySupportUnitTests.MyRepositoryQuery;
|
||||
import org.springframework.data.repository.query.EvaluationContextProvider;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
@@ -44,6 +46,8 @@ public class DummyRepositoryFactory extends RepositoryFactorySupport {
|
||||
public final RepositoryQuery queryTwo = mock(RepositoryQuery.class);
|
||||
public final QueryLookupStrategy strategy = mock(QueryLookupStrategy.class);
|
||||
|
||||
@SuppressWarnings("unchecked") private final QuerydslPredicateExecutor<Object> querydsl = mock(
|
||||
QuerydslPredicateExecutor.class);
|
||||
private final Object repository;
|
||||
|
||||
public DummyRepositoryFactory(Object repository) {
|
||||
@@ -91,4 +95,18 @@ public class DummyRepositoryFactory extends RepositoryFactorySupport {
|
||||
EvaluationContextProvider evaluationContextProvider) {
|
||||
return Optional.of(strategy);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getRepositoryFragments(org.springframework.data.repository.core.RepositoryMetadata)
|
||||
*/
|
||||
@Override
|
||||
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) {
|
||||
|
||||
RepositoryFragments fragments = super.getRepositoryFragments(metadata);
|
||||
|
||||
return QuerydslPredicateExecutor.class.isAssignableFrom(metadata.getRepositoryInterface()) //
|
||||
? fragments.append(RepositoryFragments.just(querydsl)) //
|
||||
: fragments;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,9 @@ import static org.mockito.Mockito.*;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
@@ -59,5 +60,19 @@ public class RepositoryFactoryBeanSupportUnitTests {
|
||||
.withMessageContaining("Repository interface");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1117
|
||||
public void returnsRepositoryInformationForFragmentSetup() {
|
||||
|
||||
RepositoryFactoryBeanSupport<SampleWithQuerydslRepository, Object, Long> factoryBean = //
|
||||
new DummyRepositoryFactoryBean<>(SampleWithQuerydslRepository.class);
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
RepositoryInformation information = factoryBean.getRepositoryInformation();
|
||||
|
||||
assertThat(information.getQueryMethods()).isEmpty();
|
||||
}
|
||||
|
||||
interface SampleRepository extends Repository<Object, Long> {}
|
||||
|
||||
interface SampleWithQuerydslRepository extends Repository<Object, Long>, QuerydslPredicateExecutor<Object> {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user