diff --git a/src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jEntityConverter.java b/src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jEntityConverter.java index 3895b20ea..f3cab613e 100644 --- a/src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jEntityConverter.java +++ b/src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jEntityConverter.java @@ -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 propertyAccessor = concreteNodeDescription.getPropertyAccessor(mappedObject); Predicate 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 getParameterValue(PreferredConstructor.Parameter parameter) { + public T getParameterValue(Parameter parameter) { Neo4jPersistentProperty matchingProperty = nodeDescription.getRequiredPersistentProperty(parameter.getName()); Object result; diff --git a/src/main/java/org/springframework/data/neo4j/core/mapping/DtoInstantiatingConverter.java b/src/main/java/org/springframework/data/neo4j/core/mapping/DtoInstantiatingConverter.java index 28277a5ee..e98bc138f 100644 --- a/src/main/java/org/springframework/data/neo4j/core/mapping/DtoInstantiatingConverter.java +++ b/src/main/java/org/springframework/data/neo4j/core/mapping/DtoInstantiatingConverter.java @@ -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 targetEntity = context.addPersistentEntity(ClassTypeInformation.from(targetType)).orElse(null); Assert.notNull(targetEntity, "Target entity could not be created for a DTO"); - PreferredConstructor constructor = targetEntity - .getPersistenceConstructor(); + InstanceCreatorMetadata creator = targetEntity.getInstanceCreatorMetadata(); Object dto = context.getInstantiatorFor(targetEntity) .createInstance(targetEntity, @@ -89,7 +88,7 @@ public final class DtoInstantiatingConverter implements Converter 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 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> constructor = targetEntity - .getPersistenceConstructor(); + .orElseThrow(() -> new MappingException( + "Could not add a persistent entity for the projection target type '" + targetType.getName() + "'.")); + InstanceCreatorMetadata> creator = targetEntity.getInstanceCreatorMetadata(); Object dto = context.getInstantiatorFor(targetEntity) .createInstance(targetEntity, @@ -142,8 +141,8 @@ public final class DtoInstantiatingConverter implements Converter 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 sourceEntity, - PersistentPropertyAccessor sourceAccessor, @Nullable PreferredConstructor constructor, - PersistentPropertyAccessor dtoAccessor, Neo4jPersistentProperty property) { + private void setPropertyOnDtoObject(EntityInstanceWithSource entityInstanceAndSource, + PersistentEntity sourceEntity, PersistentPropertyAccessor sourceAccessor, + @Nullable InstanceCreatorMetadata creator, PersistentPropertyAccessor dtoAccessor, + Neo4jPersistentProperty property) { - if (constructor != null && constructor.isConstructorParameter(property)) { + if (creator != null && creator.isCreatorParameter(property)) { return; } diff --git a/src/main/java/org/springframework/data/neo4j/core/mapping/EntityFromDtoInstantiatingConverter.java b/src/main/java/org/springframework/data/neo4j/core/mapping/EntityFromDtoInstantiatingConverter.java index 32a02f4da..57d7ee09c 100644 --- a/src/main/java/org/springframework/data/neo4j/core/mapping/EntityFromDtoInstantiatingConverter.java +++ b/src/main/java/org/springframework/data/neo4j/core/mapping/EntityFromDtoInstantiatingConverter.java @@ -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 implements Converter sourceAccessor = sourceEntity.getPropertyAccessor(dtoInstance); PersistentEntity targetEntity = context.getPersistentEntity(targetEntityType); - PreferredConstructor> constructor = targetEntity - .getPersistenceConstructor(); + InstanceCreatorMetadata creator = targetEntity.getInstanceCreatorMetadata(); @SuppressWarnings({ "rawtypes", "unchecked" }) T entity = (T) context.getInstantiatorFor(targetEntity) @@ -93,7 +92,7 @@ public final class EntityFromDtoInstantiatingConverter implements Converter dtoAccessor = targetEntity.getPropertyAccessor(entity); targetEntity.doWithAll(property -> { - if (constructor.isConstructorParameter(property)) { + if (creator.isCreatorParameter(property)) { return; }