Browse Source

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
pull/2065/head
Mark Paluch 7 months ago
parent
commit
cd17bb2da8
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 11
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactory.java
  2. 10
      spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/repository/support/R2dbcRepositoryFactory.java
  3. 4
      spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/R2dbcRepositoryFactoryUnitTests.java

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

@ -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.dialect.Dialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext; import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; 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.RepositoryInformation;
import org.springframework.data.repository.core.RepositoryMetadata; 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.core.support.RepositoryFactorySupport;
import org.springframework.data.repository.query.CachingValueExpressionDelegate; import org.springframework.data.repository.query.CachingValueExpressionDelegate;
import org.springframework.data.repository.query.QueryLookupStrategy; import org.springframework.data.repository.query.QueryLookupStrategy;
@ -104,13 +104,12 @@ public class JdbcRepositoryFactory extends RepositoryFactorySupport {
this.queryMappingConfiguration = queryMappingConfiguration; this.queryMappingConfiguration = queryMappingConfiguration;
} }
@SuppressWarnings("unchecked")
@Override @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 @Override

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

@ -104,7 +104,8 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport {
@Override @Override
protected Object getTargetRepository(RepositoryInformation information) { protected Object getTargetRepository(RepositoryInformation information) {
RelationalEntityInformation<?, ?> entityInformation = getEntityInformation(information.getDomainType()); RelationalEntityInformation<?, ?> entityInformation = getEntityInformation(information);
return getTargetRepositoryViaReflection(information, entityInformation, operations, this.converter); return getTargetRepositoryViaReflection(information, entityInformation, operations, this.converter);
} }
@ -116,10 +117,11 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport {
} }
@Override @Override
public <T, ID> RelationalEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) { public RelationalEntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
RelationalPersistentEntity<?> entity = this.mappingContext.getRequiredPersistentEntity(metadata.getDomainType());
RelationalPersistentEntity<?> entity = this.mappingContext.getRequiredPersistentEntity(domainClass); return new MappingRelationalEntityInformation<>(entity);
return new MappingRelationalEntityInformation<>((RelationalPersistentEntity<T>) entity);
} }
/** /**

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

@ -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.query.RelationalEntityInformation;
import org.springframework.data.relational.repository.support.MappingRelationalEntityInformation; import org.springframework.data.relational.repository.support.MappingRelationalEntityInformation;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.AbstractRepositoryMetadata;
import org.springframework.r2dbc.core.DatabaseClient; import org.springframework.r2dbc.core.DatabaseClient;
/** /**
@ -60,7 +61,8 @@ public class R2dbcRepositoryFactoryUnitTests {
public void usesMappingRelationalEntityInformationIfMappingContextSet() { public void usesMappingRelationalEntityInformationIfMappingContextSet() {
R2dbcRepositoryFactory factory = new R2dbcRepositoryFactory(databaseClient, dataAccessStrategy); 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); assertThat(entityInformation).isInstanceOf(MappingRelationalEntityInformation.class);
} }

Loading…
Cancel
Save