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 #4967
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository.support;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -120,14 +119,13 @@ public class MongoRepositoryFactory extends RepositoryFactorySupport {
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata, MongoOperations operations) {
|
||||
return fragmentsContributor.contribute(metadata, getEntityInformation(metadata.getDomainType()), operations);
|
||||
return fragmentsContributor.contribute(metadata, getEntityInformation(metadata), operations);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getTargetRepository(RepositoryInformation information) {
|
||||
|
||||
MongoEntityInformation<?, Serializable> entityInformation = getEntityInformation(information.getDomainType(),
|
||||
information);
|
||||
MongoEntityInformation<?, ?> entityInformation = getEntityInformation(information);
|
||||
Object targetRepository = getTargetRepositoryViaReflection(information, entityInformation, operations);
|
||||
|
||||
if (targetRepository instanceof SimpleMongoRepository<?, ?> repository) {
|
||||
@@ -143,16 +141,18 @@ public class MongoRepositoryFactory extends RepositoryFactorySupport {
|
||||
return Optional.of(new MongoQueryLookupStrategy(operations, mappingContext, valueExpressionDelegate));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public <T, ID> MongoEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
||||
return getEntityInformation(domainClass, null);
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
|
||||
return MongoEntityInformationSupport.entityInformationFor(entity, null);
|
||||
}
|
||||
|
||||
private <T, ID> MongoEntityInformation<T, ID> getEntityInformation(Class<T> domainClass,
|
||||
@Nullable RepositoryMetadata metadata) {
|
||||
@Override
|
||||
public MongoEntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
|
||||
return MongoEntityInformationSupport.<T, ID> entityInformationFor(entity,
|
||||
metadata != null ? metadata.getIdType() : null);
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(metadata.getDomainType());
|
||||
return MongoEntityInformationSupport.entityInformationFor(entity, metadata.getIdType());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository.support;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -118,14 +117,14 @@ public class ReactiveMongoRepositoryFactory extends ReactiveRepositoryFactorySup
|
||||
*/
|
||||
@Override
|
||||
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) {
|
||||
return fragmentsContributor.contribute(metadata, getEntityInformation(metadata.getDomainType(), metadata),
|
||||
return fragmentsContributor.contribute(metadata, getEntityInformation(metadata),
|
||||
operations);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getTargetRepository(RepositoryInformation information) {
|
||||
|
||||
MongoEntityInformation<?, Serializable> entityInformation = getEntityInformation(information.getDomainType(),
|
||||
MongoEntityInformation<?, ?> entityInformation = getEntityInformation(
|
||||
information);
|
||||
Object targetRepository = getTargetRepositoryViaReflection(information, entityInformation, operations);
|
||||
|
||||
@@ -143,19 +142,18 @@ public class ReactiveMongoRepositoryFactory extends ReactiveRepositoryFactorySup
|
||||
return Optional.of(new MongoQueryLookupStrategy(operations, mappingContext, valueExpressionDelegate));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public <T, ID> MongoEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
||||
return getEntityInformation(domainClass, null);
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
|
||||
return MongoEntityInformationSupport.entityInformationFor(entity, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T, ID> MongoEntityInformation<T, ID> getEntityInformation(Class<T> domainClass,
|
||||
@Nullable RepositoryMetadata metadata) {
|
||||
@Override
|
||||
public MongoEntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
|
||||
|
||||
return new MappingMongoEntityInformation<>((MongoPersistentEntity<T>) entity,
|
||||
metadata != null ? (Class<ID>) metadata.getIdType() : null);
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(metadata.getDomainType());
|
||||
return MongoEntityInformationSupport.entityInformationFor(entity, metadata.getIdType());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -408,7 +408,8 @@ public class ApplicationContextEventTests {
|
||||
template.save(new Person("Boba", "Fett", 40));
|
||||
|
||||
MongoRepositoryFactory factory = new MongoRepositoryFactory(template);
|
||||
MongoEntityInformation<Person, String> entityInformation = factory.getEntityInformation(Person.class);
|
||||
MongoEntityInformation<Person, String> entityInformation = factory
|
||||
.getEntityInformation(Person.class);
|
||||
QuerydslMongoPredicateExecutor executor = new QuerydslMongoPredicateExecutor<>(entityInformation, template);
|
||||
|
||||
executor.findOne(QPerson.person.lastname.startsWith("Fe"));
|
||||
|
||||
@@ -31,9 +31,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mongodb.core.MongoOperations;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
||||
import org.springframework.data.mongodb.core.convert.MongoConverter;
|
||||
import org.springframework.data.mongodb.core.convert.NoOpDbRefResolver;
|
||||
@@ -41,9 +39,8 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.repository.Person;
|
||||
import org.springframework.data.mongodb.repository.ReadPreference;
|
||||
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
|
||||
import org.springframework.data.repository.ListCrudRepository;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.EntityInformation;
|
||||
|
||||
/**
|
||||
* Unit test for {@link MongoRepositoryFactory}.
|
||||
@@ -69,7 +66,7 @@ public class MongoRepositoryFactoryUnitTests {
|
||||
public void usesMappingMongoEntityInformationIfMappingContextSet() {
|
||||
|
||||
MongoRepositoryFactory factory = new MongoRepositoryFactory(template);
|
||||
MongoEntityInformation<Person, Serializable> entityInformation = factory.getEntityInformation(Person.class);
|
||||
EntityInformation<Person, Serializable> entityInformation = factory.getEntityInformation(Person.class);
|
||||
assertThat(entityInformation instanceof MappingMongoEntityInformation).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,8 @@ public class QuerydslMongoPredicateExecutorIntegrationTests {
|
||||
public void setup() {
|
||||
|
||||
MongoRepositoryFactory factory = new MongoRepositoryFactory(operations);
|
||||
MongoEntityInformation<Person, String> entityInformation = factory.getEntityInformation(Person.class);
|
||||
MongoEntityInformation<Person, String> entityInformation = factory
|
||||
.getEntityInformation(Person.class);
|
||||
repository = new QuerydslMongoPredicateExecutor<>(entityInformation, operations);
|
||||
|
||||
operations.dropCollection(Person.class);
|
||||
@@ -246,7 +247,8 @@ public class QuerydslMongoPredicateExecutorIntegrationTests {
|
||||
};
|
||||
|
||||
MongoRepositoryFactory factory = new MongoRepositoryFactory(ops);
|
||||
MongoEntityInformation<Person, String> entityInformation = factory.getEntityInformation(Person.class);
|
||||
MongoEntityInformation<Person, String> entityInformation = factory
|
||||
.getEntityInformation(Person.class);
|
||||
repository = new QuerydslMongoPredicateExecutor<>(entityInformation, ops);
|
||||
|
||||
repository.findOne(person.firstname.contains("batman"));
|
||||
|
||||
@@ -111,7 +111,8 @@ public class ReactiveQuerydslMongoPredicateExecutorTests {
|
||||
public void setup() {
|
||||
|
||||
ReactiveMongoRepositoryFactory factory = new ReactiveMongoRepositoryFactory(operations);
|
||||
MongoEntityInformation<Person, String> entityInformation = factory.getEntityInformation(Person.class);
|
||||
MongoEntityInformation<Person, String> entityInformation = factory
|
||||
.getEntityInformation(Person.class);
|
||||
repository = new ReactiveQuerydslMongoPredicateExecutor<>(entityInformation, operations);
|
||||
|
||||
dave = new Person("Dave", "Matthews", 42);
|
||||
@@ -326,7 +327,8 @@ public class ReactiveQuerydslMongoPredicateExecutorTests {
|
||||
};
|
||||
|
||||
ReactiveMongoRepositoryFactory factory = new ReactiveMongoRepositoryFactory(ops);
|
||||
MongoEntityInformation<Person, String> entityInformation = factory.getEntityInformation(Person.class);
|
||||
MongoEntityInformation<Person, String> entityInformation = factory
|
||||
.getEntityInformation(Person.class);
|
||||
repository = new ReactiveQuerydslMongoPredicateExecutor<>(entityInformation, ops);
|
||||
|
||||
repository.findOne(person.firstname.contains("batman")) //
|
||||
|
||||
Reference in New Issue
Block a user