From d68605b6d8b7b1d09998e8793f2fa02633531166 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Tue, 4 Apr 2023 11:45:38 +0200 Subject: [PATCH] Adapt to API changes in Spring Data Common's PersistentPropertyPathAccessor. Fixes #1477. Related ticket: spring-projects/spring-data-commons#2813. --- .../jdbc/core/JdbcAggregateChangeExecutionContext.java | 5 +++-- .../data/jdbc/core/convert/QueryMapper.java | 2 +- .../core/conversion/BasicRelationalConverter.java | 7 ++++--- .../core/conversion/RelationalConverter.java | 3 ++- .../relational/core/conversion/WritingContext.java | 10 +++++----- .../core/mapping/PersistentPropertyPathExtension.java | 2 +- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutionContext.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutionContext.java index b57b1750..a29a61c2 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutionContext.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutionContext.java @@ -27,8 +27,8 @@ import org.springframework.data.jdbc.core.convert.InsertSubject; import org.springframework.data.jdbc.core.convert.JdbcConverter; import org.springframework.data.jdbc.core.convert.JdbcIdentifierBuilder; import org.springframework.data.mapping.PersistentProperty; -import org.springframework.data.mapping.PersistentPropertyAccessor; import org.springframework.data.mapping.PersistentPropertyPath; +import org.springframework.data.mapping.PersistentPropertyPathAccessor; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.relational.core.conversion.DbAction; import org.springframework.data.relational.core.conversion.DbActionExecutionResult; @@ -290,7 +290,8 @@ class JdbcAggregateChangeExecutionContext { RelationalPersistentEntity persistentEntity = (RelationalPersistentEntity) context .getRequiredPersistentEntity(action.getEntityType()); - PersistentPropertyAccessor propertyAccessor = converter.getPropertyAccessor(persistentEntity, originalEntity); + PersistentPropertyPathAccessor propertyAccessor = converter.getPropertyAccessor(persistentEntity, + originalEntity); if (IdValueSource.GENERATED.equals(action.getIdValueSource())) { propertyAccessor.setProperty(persistentEntity.getRequiredIdProperty(), generatedId); diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/QueryMapper.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/QueryMapper.java index 5abdf229..9a76f532 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/QueryMapper.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/QueryMapper.java @@ -754,7 +754,7 @@ public class QueryMapper { throw new IllegalStateException("Cannot obtain a single column name for embedded property"); } - if (this.property != null && this.path != null) { + if (this.property != null && this.path != null && this.path.getParentPath() != null) { RelationalPersistentProperty owner = this.path.getParentPath().getLeafProperty(); diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java index 91a862ea..710438ff 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java @@ -32,7 +32,7 @@ import org.springframework.data.convert.CustomConversions.StoreConversions; 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.PersistentPropertyPathAccessor; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.model.ConvertingPropertyAccessor; import org.springframework.data.mapping.model.EntityInstantiators; @@ -120,9 +120,10 @@ public class BasicRelationalConverter implements RelationalConverter { } @Override - public PersistentPropertyAccessor getPropertyAccessor(PersistentEntity persistentEntity, T instance) { + public PersistentPropertyPathAccessor getPropertyAccessor(PersistentEntity persistentEntity, + T instance) { - PersistentPropertyAccessor accessor = persistentEntity.getPropertyAccessor(instance); + PersistentPropertyPathAccessor accessor = persistentEntity.getPropertyPathAccessor(instance); return new ConvertingPropertyAccessor<>(accessor, conversionService); } diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/RelationalConverter.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/RelationalConverter.java index 638f554b..55c9cf4b 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/RelationalConverter.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/RelationalConverter.java @@ -21,6 +21,7 @@ import org.springframework.core.convert.ConversionService; import org.springframework.data.mapping.Parameter; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentPropertyAccessor; +import org.springframework.data.mapping.PersistentPropertyPathAccessor; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.model.EntityInstantiators; import org.springframework.data.mapping.model.ParameterValueProvider; @@ -72,7 +73,7 @@ public interface RelationalConverter { * @param instance the instance to operate on. Must not be {@code null}. * @return guaranteed to be not {@code null}. */ - PersistentPropertyAccessor getPropertyAccessor(PersistentEntity persistentEntity, T instance); + PersistentPropertyPathAccessor getPropertyAccessor(PersistentEntity persistentEntity, T instance); /** * Read a relational value into the desired {@link TypeInformation destination type}. diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/WritingContext.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/WritingContext.java index 8ed1763f..c0f1b296 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/WritingContext.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/WritingContext.java @@ -230,9 +230,9 @@ class WritingContext { PersistentPropertyPath currentPath = path.getParentPath(); - while (!currentPath.isEmpty()) { + while (currentPath != null) { - if (!currentPath.getRequiredLeafProperty().isEmbedded()) { + if (!currentPath.getLeafProperty().isEmbedded()) { return false; } currentPath = currentPath.getParentPath(); @@ -242,9 +242,9 @@ class WritingContext { } @Nullable - private Object getFromRootValue(PersistentPropertyPath path) { + private Object getFromRootValue(@Nullable PersistentPropertyPath path) { - if (path.getLength() == 0) { + if (path == null) { return root; } @@ -254,7 +254,7 @@ class WritingContext { } return context.getRequiredPersistentEntity(parent.getClass()).getPropertyAccessor(parent) - .getProperty(path.getRequiredLeafProperty()); + .getProperty(path.getLeafProperty()); } private List createNodes(PersistentPropertyPath path, diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java index 6693b359..b0251db4 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java @@ -83,7 +83,7 @@ public class PersistentPropertyPathExtension { public static boolean isWritable(PersistentPropertyPath path) { - return path.isEmpty() || (path.getRequiredLeafProperty().isWritable() && isWritable(path.getParentPath())); + return path == null || path.getLeafProperty().isWritable() && isWritable(path.getParentPath()); } /**