Adapt to changes in entity creation metadata APIs in Spring Data Commons.
This commit is contained in:
@@ -46,8 +46,8 @@ import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.core.KotlinDetector;
|
||||
import org.springframework.data.mapping.AssociationHandler;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.Parameter;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.mapping.PropertyHandler;
|
||||
import org.springframework.data.mapping.model.EntityInstantiators;
|
||||
import org.springframework.data.mapping.model.ParameterValueProvider;
|
||||
@@ -328,7 +328,7 @@ final class DefaultNeo4jEntityConverter implements Neo4jEntityConverter {
|
||||
|
||||
PersistentPropertyAccessor<ET> propertyAccessor = concreteNodeDescription.getPropertyAccessor(mappedObject);
|
||||
Predicate<Neo4jPersistentProperty> isConstructorParameter = concreteNodeDescription
|
||||
.getPersistenceConstructor()::isConstructorParameter;
|
||||
.getInstanceCreatorMetadata()::isCreatorParameter;
|
||||
|
||||
// if the object were mapped before, we assume that at least all properties are populated
|
||||
if (!objectAlreadyMapped) {
|
||||
@@ -412,7 +412,7 @@ final class DefaultNeo4jEntityConverter implements Neo4jEntityConverter {
|
||||
|
||||
@SuppressWarnings("unchecked") // Needed for the last cast. It's easier that way than using the parameter type info and checking for primitives
|
||||
@Override
|
||||
public <T> T getParameterValue(PreferredConstructor.Parameter<T, Neo4jPersistentProperty> parameter) {
|
||||
public <T> T getParameterValue(Parameter<T, Neo4jPersistentProperty> parameter) {
|
||||
Neo4jPersistentProperty matchingProperty = nodeDescription.getRequiredPersistentProperty(parameter.getName());
|
||||
|
||||
Object result;
|
||||
|
||||
@@ -27,12 +27,12 @@ import org.neo4j.driver.types.TypeSystem;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.log.LogAccessor;
|
||||
import org.springframework.data.mapping.InstanceCreatorMetadata;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.Parameter;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.data.mapping.SimplePropertyHandler;
|
||||
import org.springframework.data.mapping.model.ParameterValueProvider;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
@@ -76,8 +76,7 @@ public final class DtoInstantiatingConverter implements Converter<EntityInstance
|
||||
|
||||
Neo4jPersistentEntity<?> targetEntity = context.addPersistentEntity(ClassTypeInformation.from(targetType)).orElse(null);
|
||||
Assert.notNull(targetEntity, "Target entity could not be created for a DTO");
|
||||
PreferredConstructor<?, Neo4jPersistentProperty> constructor = targetEntity
|
||||
.getPersistenceConstructor();
|
||||
InstanceCreatorMetadata<?> creator = targetEntity.getInstanceCreatorMetadata();
|
||||
|
||||
Object dto = context.getInstantiatorFor(targetEntity)
|
||||
.createInstance(targetEntity,
|
||||
@@ -89,7 +88,7 @@ public final class DtoInstantiatingConverter implements Converter<EntityInstance
|
||||
PersistentPropertyAccessor<Object> dtoAccessor = targetEntity.getPropertyAccessor(dto);
|
||||
targetEntity.doWithProperties((SimplePropertyHandler) property -> {
|
||||
|
||||
if (constructor != null && constructor.isConstructorParameter(property)) {
|
||||
if (creator != null && creator.isCreatorParameter(property)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -130,9 +129,9 @@ public final class DtoInstantiatingConverter implements Converter<EntityInstance
|
||||
PersistentPropertyAccessor<Object> sourceAccessor = sourceEntity.getPropertyAccessor(entityInstance);
|
||||
|
||||
Neo4jPersistentEntity<?> targetEntity = context.addPersistentEntity(ClassTypeInformation.from(targetType))
|
||||
.orElseThrow(() -> new MappingException("Could not add a persistent entity for the projection target type '" + targetType.getName() + "'."));
|
||||
PreferredConstructor<?, ? extends PersistentProperty<?>> constructor = targetEntity
|
||||
.getPersistenceConstructor();
|
||||
.orElseThrow(() -> new MappingException(
|
||||
"Could not add a persistent entity for the projection target type '" + targetType.getName() + "'."));
|
||||
InstanceCreatorMetadata<? extends PersistentProperty<?>> creator = targetEntity.getInstanceCreatorMetadata();
|
||||
|
||||
Object dto = context.getInstantiatorFor(targetEntity)
|
||||
.createInstance(targetEntity,
|
||||
@@ -142,8 +141,8 @@ public final class DtoInstantiatingConverter implements Converter<EntityInstance
|
||||
);
|
||||
|
||||
PersistentPropertyAccessor<Object> dtoAccessor = targetEntity.getPropertyAccessor(dto);
|
||||
targetEntity.doWithAll(property ->
|
||||
setPropertyOnDtoObject(entityInstanceAndSource, sourceEntity, sourceAccessor, constructor, dtoAccessor, property));
|
||||
targetEntity.doWithAll(property -> setPropertyOnDtoObject(entityInstanceAndSource, sourceEntity, sourceAccessor,
|
||||
creator, dtoAccessor, property));
|
||||
|
||||
return dto;
|
||||
}
|
||||
@@ -171,11 +170,12 @@ public final class DtoInstantiatingConverter implements Converter<EntityInstance
|
||||
};
|
||||
}
|
||||
|
||||
private void setPropertyOnDtoObject(EntityInstanceWithSource entityInstanceAndSource, PersistentEntity<?, ?> sourceEntity,
|
||||
PersistentPropertyAccessor<Object> sourceAccessor, @Nullable PreferredConstructor<?, ?> constructor,
|
||||
PersistentPropertyAccessor<Object> dtoAccessor, Neo4jPersistentProperty property) {
|
||||
private void setPropertyOnDtoObject(EntityInstanceWithSource entityInstanceAndSource,
|
||||
PersistentEntity<?, ?> sourceEntity, PersistentPropertyAccessor<Object> sourceAccessor,
|
||||
@Nullable InstanceCreatorMetadata<?> creator, PersistentPropertyAccessor<Object> dtoAccessor,
|
||||
Neo4jPersistentProperty property) {
|
||||
|
||||
if (constructor != null && constructor.isConstructorParameter(property)) {
|
||||
if (creator != null && creator.isCreatorParameter(property)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.apiguardian.api.API;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.mapping.InstanceCreatorMetadata;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.Parameter;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
||||
import org.springframework.data.mapping.model.ParameterValueProvider;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
@@ -74,8 +74,7 @@ public final class EntityFromDtoInstantiatingConverter<T> implements Converter<O
|
||||
PersistentPropertyAccessor<Object> sourceAccessor = sourceEntity.getPropertyAccessor(dtoInstance);
|
||||
|
||||
PersistentEntity<?, ?> targetEntity = context.getPersistentEntity(targetEntityType);
|
||||
PreferredConstructor<?, ? extends PersistentProperty<?>> constructor = targetEntity
|
||||
.getPersistenceConstructor();
|
||||
InstanceCreatorMetadata<?> creator = targetEntity.getInstanceCreatorMetadata();
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
T entity = (T) context.getInstantiatorFor(targetEntity)
|
||||
@@ -93,7 +92,7 @@ public final class EntityFromDtoInstantiatingConverter<T> implements Converter<O
|
||||
|
||||
PersistentPropertyAccessor<Object> dtoAccessor = targetEntity.getPropertyAccessor(entity);
|
||||
targetEntity.doWithAll(property -> {
|
||||
if (constructor.isConstructorParameter(property)) {
|
||||
if (creator.isCreatorParameter(property)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user