Skip to content

Commit e218bda

Browse files
committed
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
1 parent ed4edba commit e218bda

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactory.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
import org.springframework.data.relational.core.dialect.Dialect;
2828
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
2929
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
30-
import org.springframework.data.repository.core.EntityInformation;
30+
import org.springframework.data.relational.repository.query.RelationalEntityInformation;
31+
import org.springframework.data.relational.repository.support.MappingRelationalEntityInformation;
3132
import org.springframework.data.repository.core.RepositoryInformation;
3233
import org.springframework.data.repository.core.RepositoryMetadata;
33-
import org.springframework.data.repository.core.support.PersistentEntityInformation;
3434
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
3535
import org.springframework.data.repository.query.CachingValueExpressionDelegate;
3636
import org.springframework.data.repository.query.QueryLookupStrategy;
@@ -104,13 +104,12 @@ public void setQueryMappingConfiguration(QueryMappingConfiguration queryMappingC
104104
this.queryMappingConfiguration = queryMappingConfiguration;
105105
}
106106

107-
@SuppressWarnings("unchecked")
108107
@Override
109-
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> aClass) {
108+
public RelationalEntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
110109

111-
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(aClass);
110+
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(metadata.getDomainType());
112111

113-
return (EntityInformation<T, ID>) new PersistentEntityInformation<>(entity);
112+
return new MappingRelationalEntityInformation<>(entity);
114113
}
115114

116115
@Override

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/repository/support/R2dbcRepositoryFactory.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
104104
@Override
105105
protected Object getTargetRepository(RepositoryInformation information) {
106106

107-
RelationalEntityInformation<?, ?> entityInformation = getEntityInformation(information.getDomainType(),
108-
information);
107+
RelationalEntityInformation<?, ?> entityInformation = getEntityInformation(information);
109108

110109
return getTargetRepositoryViaReflection(information, entityInformation, operations, this.converter);
111110
}
@@ -117,17 +116,12 @@ protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable Key key
117116
new CachingValueExpressionDelegate(valueExpressionDelegate), converter, dataAccessStrategy));
118117
}
119118

120-
public <T, ID> RelationalEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
121-
return getEntityInformation(domainClass, null);
122-
}
123-
124-
@SuppressWarnings("unchecked")
125-
private <T, ID> RelationalEntityInformation<T, ID> getEntityInformation(Class<T> domainClass,
126-
@Nullable RepositoryInformation information) {
119+
@Override
120+
public RelationalEntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
127121

128-
RelationalPersistentEntity<?> entity = this.mappingContext.getRequiredPersistentEntity(domainClass);
122+
RelationalPersistentEntity<?> entity = this.mappingContext.getRequiredPersistentEntity(metadata.getDomainType());
129123

130-
return new MappingRelationalEntityInformation<>((RelationalPersistentEntity<T>) entity);
124+
return new MappingRelationalEntityInformation<>(entity);
131125
}
132126

133127
/**

spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/R2dbcRepositoryFactoryUnitTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.data.relational.repository.query.RelationalEntityInformation;
3434
import org.springframework.data.relational.repository.support.MappingRelationalEntityInformation;
3535
import org.springframework.data.repository.Repository;
36+
import org.springframework.data.repository.core.support.AbstractRepositoryMetadata;
3637
import org.springframework.r2dbc.core.DatabaseClient;
3738

3839
/**
@@ -60,7 +61,8 @@ public void before() {
6061
public void usesMappingRelationalEntityInformationIfMappingContextSet() {
6162

6263
R2dbcRepositoryFactory factory = new R2dbcRepositoryFactory(databaseClient, dataAccessStrategy);
63-
RelationalEntityInformation<Person, Long> entityInformation = factory.getEntityInformation(Person.class);
64+
RelationalEntityInformation<?, ?> entityInformation = factory
65+
.getEntityInformation(AbstractRepositoryMetadata.getMetadata(MyPersonRepository.class));
6466

6567
assertThat(entityInformation).isInstanceOf(MappingRelationalEntityInformation.class);
6668
}

0 commit comments

Comments
 (0)