Implement RepositoryFactorySupport.getEntityInformation(RepositoryMetadata) instead of private overload.
Overriding the proper variant of EntityInformation is now possible because we no longer utilize a private method in addition to the public one leading to partial customization of EntityInformation. Closes #2053
This commit is contained in:
@@ -27,10 +27,10 @@ import org.springframework.data.mapping.callback.EntityCallbacks;
|
||||
import org.springframework.data.relational.core.dialect.Dialect;
|
||||
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
|
||||
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
|
||||
import org.springframework.data.repository.core.EntityInformation;
|
||||
import org.springframework.data.relational.repository.query.RelationalEntityInformation;
|
||||
import org.springframework.data.relational.repository.support.MappingRelationalEntityInformation;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.PersistentEntityInformation;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
||||
import org.springframework.data.repository.query.CachingValueExpressionDelegate;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
@@ -104,13 +104,12 @@ public class JdbcRepositoryFactory extends RepositoryFactorySupport {
|
||||
this.queryMappingConfiguration = queryMappingConfiguration;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> aClass) {
|
||||
public RelationalEntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
|
||||
|
||||
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(aClass);
|
||||
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(metadata.getDomainType());
|
||||
|
||||
return (EntityInformation<T, ID>) new PersistentEntityInformation<>(entity);
|
||||
return new MappingRelationalEntityInformation<>(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -104,7 +104,8 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport {
|
||||
@Override
|
||||
protected Object getTargetRepository(RepositoryInformation information) {
|
||||
|
||||
RelationalEntityInformation<?, ?> entityInformation = getEntityInformation(information.getDomainType());
|
||||
RelationalEntityInformation<?, ?> entityInformation = getEntityInformation(information);
|
||||
|
||||
return getTargetRepositoryViaReflection(information, entityInformation, operations, this.converter);
|
||||
}
|
||||
|
||||
@@ -116,10 +117,11 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, ID> RelationalEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
||||
public RelationalEntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
|
||||
|
||||
RelationalPersistentEntity<?> entity = this.mappingContext.getRequiredPersistentEntity(domainClass);
|
||||
return new MappingRelationalEntityInformation<>((RelationalPersistentEntity<T>) entity);
|
||||
RelationalPersistentEntity<?> entity = this.mappingContext.getRequiredPersistentEntity(metadata.getDomainType());
|
||||
|
||||
return new MappingRelationalEntityInformation<>(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.data.relational.core.dialect.AnsiDialect;
|
||||
import org.springframework.data.relational.repository.query.RelationalEntityInformation;
|
||||
import org.springframework.data.relational.repository.support.MappingRelationalEntityInformation;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.support.AbstractRepositoryMetadata;
|
||||
import org.springframework.r2dbc.core.DatabaseClient;
|
||||
|
||||
/**
|
||||
@@ -60,7 +61,8 @@ public class R2dbcRepositoryFactoryUnitTests {
|
||||
public void usesMappingRelationalEntityInformationIfMappingContextSet() {
|
||||
|
||||
R2dbcRepositoryFactory factory = new R2dbcRepositoryFactory(databaseClient, dataAccessStrategy);
|
||||
RelationalEntityInformation<Person, Long> entityInformation = factory.getEntityInformation(Person.class);
|
||||
RelationalEntityInformation<?, ?> entityInformation = factory
|
||||
.getEntityInformation(AbstractRepositoryMetadata.getMetadata(MyPersonRepository.class));
|
||||
|
||||
assertThat(entityInformation).isInstanceOf(MappingRelationalEntityInformation.class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user