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
This commit is contained in:
@@ -84,18 +84,16 @@ public class CassandraRepositoryFactory extends RepositoryFactorySupport {
|
||||
@Override
|
||||
protected Object getTargetRepository(RepositoryInformation information) {
|
||||
|
||||
CassandraEntityInformation<?, Object> entityInformation = getEntityInformation(information.getDomainType());
|
||||
CassandraEntityInformation<?, ?> entityInformation = getEntityInformation(information);
|
||||
|
||||
return getTargetRepositoryViaReflection(information, entityInformation, operations);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T, ID> CassandraEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
||||
public CassandraEntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
|
||||
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
|
||||
|
||||
return new MappingCassandraEntityInformation<>((CassandraPersistentEntity<T>) entity, operations.getConverter());
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(metadata.getDomainType());
|
||||
return new MappingCassandraEntityInformation<>(entity, operations.getConverter());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ReactiveCassandraRepositoryFactory extends ReactiveRepositoryFactor
|
||||
@Override
|
||||
protected Object getTargetRepository(RepositoryInformation information) {
|
||||
|
||||
CassandraEntityInformation<?, Object> entityInformation = getEntityInformation(information.getDomainType());
|
||||
CassandraEntityInformation<?, ?> entityInformation = getEntityInformation(information);
|
||||
|
||||
return getTargetRepositoryViaReflection(information, entityInformation, operations);
|
||||
}
|
||||
@@ -93,12 +93,11 @@ public class ReactiveCassandraRepositoryFactory extends ReactiveRepositoryFactor
|
||||
new CachingValueExpressionDelegate(valueExpressionDelegate), mappingContext));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T, ID> CassandraEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
||||
@Override
|
||||
public CassandraEntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
|
||||
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
|
||||
|
||||
return new MappingCassandraEntityInformation<>((CassandraPersistentEntity<T>) entity, operations.getConverter());
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(metadata.getDomainType());
|
||||
return new MappingCassandraEntityInformation<>(entity, operations.getConverter());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.data.cassandra.repository.support;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -27,14 +25,16 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.data.cassandra.core.CassandraTemplate;
|
||||
import org.springframework.data.cassandra.core.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentEntity;
|
||||
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
|
||||
import org.springframework.data.cassandra.domain.Person;
|
||||
import org.springframework.data.cassandra.repository.query.CassandraEntityInformation;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.EntityInformation;
|
||||
import org.springframework.data.repository.core.support.AbstractRepositoryMetadata;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CassandraRepositoryFactory}.
|
||||
@@ -66,8 +66,8 @@ public class CassandraRepositoryFactoryUnitTests {
|
||||
|
||||
CassandraRepositoryFactory repositoryFactory = new CassandraRepositoryFactory(template);
|
||||
|
||||
CassandraEntityInformation<Person, Serializable> entityInformation = repositoryFactory
|
||||
.getEntityInformation(Person.class);
|
||||
EntityInformation<?, ?> entityInformation = repositoryFactory
|
||||
.getEntityInformation(AbstractRepositoryMetadata.getMetadata(MyPersonRepository.class));
|
||||
|
||||
assertThat(entityInformation).isInstanceOf(MappingCassandraEntityInformation.class);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.data.cassandra.repository.support;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -27,14 +25,16 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
|
||||
import org.springframework.data.cassandra.core.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentEntity;
|
||||
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
|
||||
import org.springframework.data.cassandra.domain.Person;
|
||||
import org.springframework.data.cassandra.repository.query.CassandraEntityInformation;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.EntityInformation;
|
||||
import org.springframework.data.repository.core.support.AbstractRepositoryMetadata;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ReactiveCassandraRepositoryFactory}.
|
||||
@@ -66,8 +66,8 @@ public class ReactiveCassandraRepositoryFactoryUnitTests {
|
||||
|
||||
ReactiveCassandraRepositoryFactory repositoryFactory = new ReactiveCassandraRepositoryFactory(template);
|
||||
|
||||
CassandraEntityInformation<Person, Serializable> entityInformation =
|
||||
repositoryFactory.getEntityInformation(Person.class);
|
||||
EntityInformation<?, ?> entityInformation = repositoryFactory
|
||||
.getEntityInformation(AbstractRepositoryMetadata.getMetadata(MyPersonRepository.class));
|
||||
|
||||
assertThat(entityInformation).isInstanceOf(MappingCassandraEntityInformation.class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user