Skip to content

Commit ccc0924

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 #1576
1 parent 9d3a186 commit ccc0924

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/CassandraRepositoryFactory.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,16 @@ protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
8484
@Override
8585
protected Object getTargetRepository(RepositoryInformation information) {
8686

87-
CassandraEntityInformation<?, Object> entityInformation = getEntityInformation(information.getDomainType());
87+
CassandraEntityInformation<?, ?> entityInformation = getEntityInformation(information);
8888

8989
return getTargetRepositoryViaReflection(information, entityInformation, operations);
9090
}
9191

9292
@Override
93-
@SuppressWarnings("unchecked")
94-
public <T, ID> CassandraEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
93+
public CassandraEntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
9594

96-
CassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
97-
98-
return new MappingCassandraEntityInformation<>((CassandraPersistentEntity<T>) entity, operations.getConverter());
95+
CassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(metadata.getDomainType());
96+
return new MappingCassandraEntityInformation<>(entity, operations.getConverter());
9997
}
10098

10199
@Override

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/ReactiveCassandraRepositoryFactory.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
8181
@Override
8282
protected Object getTargetRepository(RepositoryInformation information) {
8383

84-
CassandraEntityInformation<?, Object> entityInformation = getEntityInformation(information.getDomainType());
84+
CassandraEntityInformation<?, ?> entityInformation = getEntityInformation(information);
8585

8686
return getTargetRepositoryViaReflection(information, entityInformation, operations);
8787
}
@@ -93,12 +93,11 @@ protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable Key key
9393
new CachingValueExpressionDelegate(valueExpressionDelegate), mappingContext));
9494
}
9595

96-
@SuppressWarnings("unchecked")
97-
public <T, ID> CassandraEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
98-
99-
CassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
96+
@Override
97+
public CassandraEntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
10098

101-
return new MappingCassandraEntityInformation<>((CassandraPersistentEntity<T>) entity, operations.getConverter());
99+
CassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(metadata.getDomainType());
100+
return new MappingCassandraEntityInformation<>(entity, operations.getConverter());
102101
}
103102

104103
/**

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/CassandraRepositoryFactoryUnitTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@
1818
import static org.assertj.core.api.Assertions.*;
1919
import static org.mockito.Mockito.*;
2020

21-
import java.io.Serializable;
22-
2321
import org.junit.jupiter.api.BeforeEach;
2422
import org.junit.jupiter.api.Test;
2523
import org.junit.jupiter.api.extension.ExtendWith;
2624
import org.mockito.Mock;
2725
import org.mockito.junit.jupiter.MockitoExtension;
2826
import org.mockito.junit.jupiter.MockitoSettings;
2927
import org.mockito.quality.Strictness;
28+
3029
import org.springframework.data.cassandra.core.CassandraTemplate;
3130
import org.springframework.data.cassandra.core.convert.CassandraConverter;
3231
import org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentEntity;
3332
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
3433
import org.springframework.data.cassandra.domain.Person;
35-
import org.springframework.data.cassandra.repository.query.CassandraEntityInformation;
3634
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
3735
import org.springframework.data.repository.Repository;
36+
import org.springframework.data.repository.core.EntityInformation;
37+
import org.springframework.data.repository.core.support.AbstractRepositoryMetadata;
3838

3939
/**
4040
* Unit tests for {@link CassandraRepositoryFactory}.
@@ -66,8 +66,8 @@ void usesMappingCassandraEntityInformationIfMappingContextSet() {
6666

6767
CassandraRepositoryFactory repositoryFactory = new CassandraRepositoryFactory(template);
6868

69-
CassandraEntityInformation<Person, Serializable> entityInformation = repositoryFactory
70-
.getEntityInformation(Person.class);
69+
EntityInformation<?, ?> entityInformation = repositoryFactory
70+
.getEntityInformation(AbstractRepositoryMetadata.getMetadata(MyPersonRepository.class));
7171

7272
assertThat(entityInformation).isInstanceOf(MappingCassandraEntityInformation.class);
7373
}

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/ReactiveCassandraRepositoryFactoryUnitTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@
1818
import static org.assertj.core.api.Assertions.*;
1919
import static org.mockito.Mockito.*;
2020

21-
import java.io.Serializable;
22-
2321
import org.junit.jupiter.api.BeforeEach;
2422
import org.junit.jupiter.api.Test;
2523
import org.junit.jupiter.api.extension.ExtendWith;
2624
import org.mockito.Mock;
2725
import org.mockito.junit.jupiter.MockitoExtension;
2826
import org.mockito.junit.jupiter.MockitoSettings;
2927
import org.mockito.quality.Strictness;
28+
3029
import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
3130
import org.springframework.data.cassandra.core.convert.CassandraConverter;
3231
import org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentEntity;
3332
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
3433
import org.springframework.data.cassandra.domain.Person;
35-
import org.springframework.data.cassandra.repository.query.CassandraEntityInformation;
3634
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
3735
import org.springframework.data.repository.Repository;
36+
import org.springframework.data.repository.core.EntityInformation;
37+
import org.springframework.data.repository.core.support.AbstractRepositoryMetadata;
3838

3939
/**
4040
* Unit tests for {@link ReactiveCassandraRepositoryFactory}.
@@ -66,8 +66,8 @@ void usesMappingCassandraEntityInformationIfMappingContextSet() {
6666

6767
ReactiveCassandraRepositoryFactory repositoryFactory = new ReactiveCassandraRepositoryFactory(template);
6868

69-
CassandraEntityInformation<Person, Serializable> entityInformation =
70-
repositoryFactory.getEntityInformation(Person.class);
69+
EntityInformation<?, ?> entityInformation = repositoryFactory
70+
.getEntityInformation(AbstractRepositoryMetadata.getMetadata(MyPersonRepository.class));
7171

7272
assertThat(entityInformation).isInstanceOf(MappingCassandraEntityInformation.class);
7373
}

0 commit comments

Comments
 (0)