Introduce ManagedTypes.
We now provide an abstraction to describe a collection of entity types that can be provided to the mapping context as improvement over `Set<Class>` for easier context setup. Original pull request: #2635. Closes #2634.
This commit is contained in:
committed by
Mark Paluch
parent
2a1a8f387f
commit
02bf260d6d
@@ -42,6 +42,7 @@ import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.core.KotlinDetector;
|
||||
import org.springframework.core.NativeDetector;
|
||||
import org.springframework.data.domain.ManagedTypes;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
@@ -101,7 +102,8 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
private @Nullable ApplicationEventPublisher applicationEventPublisher;
|
||||
private EvaluationContextProvider evaluationContextProvider = EvaluationContextProvider.DEFAULT;
|
||||
|
||||
private Set<? extends Class<?>> initialEntitySet = new HashSet<>();
|
||||
private ManagedTypes managedTypes = ManagedTypes.empty();
|
||||
|
||||
private boolean strict = false;
|
||||
private SimpleTypeHolder simpleTypeHolder = SimpleTypeHolder.DEFAULT;
|
||||
|
||||
@@ -141,9 +143,21 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
* Sets the {@link Set} of types to populate the context initially.
|
||||
*
|
||||
* @param initialEntitySet
|
||||
* @see #setManagedTypes(ManagedTypes)
|
||||
*
|
||||
*/
|
||||
public void setInitialEntitySet(Set<? extends Class<?>> initialEntitySet) {
|
||||
this.initialEntitySet = initialEntitySet;
|
||||
setManagedTypes(ManagedTypes.fromIterable(initialEntitySet));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the types to populate the context initially.
|
||||
*
|
||||
* @param managedTypes must not be {@literal null}. Use {@link ManagedTypes#empty()} instead;
|
||||
* @since 3.0
|
||||
*/
|
||||
public void setManagedTypes(ManagedTypes managedTypes) {
|
||||
this.managedTypes = managedTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -467,7 +481,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
* context.
|
||||
*/
|
||||
public void initialize() {
|
||||
initialEntitySet.forEach(this::addPersistentEntity);
|
||||
managedTypes.forEach(this::addPersistentEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user