From cf6e174088e9e4883ed5273f00818087bf60906e Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Wed, 1 Jun 2022 14:48:11 +0200 Subject: [PATCH] Polishing. Original pull request #1229 --- .../data/jdbc/core/convert/DefaultDataAccessStrategy.java | 1 + .../data/jdbc/core/convert/SqlGenerator.java | 1 + .../core/conversion/SaveBatchingAggregateChange.java | 8 +++----- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java index 54b37046..3652bbd5 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java @@ -203,6 +203,7 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy { .getRequiredPersistentEntity(propertyPath.getBaseProperty().getOwner().getType()); RelationalPersistentProperty referencingProperty = propertyPath.getLeafProperty(); + Assert.notNull(referencingProperty, "No property found matching the PropertyPath " + propertyPath); String delete = sql(rootEntity.getType()).createDeleteInByPath(propertyPath); diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java index 8ad6cf4a..b84c1923 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java @@ -379,6 +379,7 @@ class SqlGenerator { * @return the statement as a {@link String}. Guaranteed to be not {@literal null}. */ String createDeleteInByPath(PersistentPropertyPath path) { + return createDeleteByPathAndCriteria(new PersistentPropertyPathExtension(mappingContext, path), filterColumn -> filterColumn.in(getBindMarker(IDS_SQL_PARAMETER))); } diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/SaveBatchingAggregateChange.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/SaveBatchingAggregateChange.java index 00126fa9..64713437 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/SaveBatchingAggregateChange.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/SaveBatchingAggregateChange.java @@ -51,8 +51,7 @@ public class SaveBatchingAggregateChange implements BatchingAggregateChange> insertRootBatchCandidates = new ArrayList<>(); private final Map, Map>>> insertActions = // new HashMap<>(); - private final Map, List>> deleteActions = // - new HashMap<>(); + private final Map, List>> deleteActions = new HashMap<>(); SaveBatchingAggregateChange(Class entityType) { this.entityType = entityType; @@ -88,9 +87,8 @@ public class SaveBatchingAggregateChange implements BatchingAggregateChange entry.getValue().forEach((idValueSource, inserts) -> - consumer.accept(new DbAction.BatchInsert<>(inserts)))); + insertActions.entrySet().stream().sorted(Map.Entry.comparingByKey(pathLengthComparator)).forEach((entry) -> entry + .getValue().forEach((idValueSource, inserts) -> consumer.accept(new DbAction.BatchInsert<>(inserts)))); } @Override