From ed7853d2d0f617f09c886b831427fa39f4ef7e5b Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Mon, 20 Jun 2022 15:06:14 +0200 Subject: [PATCH] Polishing. Original pull request #1231 See #537 --- .../data/jdbc/core/convert/DataAccessStrategy.java | 8 ++++---- .../jdbc/core/convert/DefaultDataAccessStrategy.java | 2 +- .../data/jdbc/core/convert/SqlGenerator.java | 12 ++---------- .../core/JdbcAggregateTemplateIntegrationTests.java | 3 ++- .../data/relational/core/conversion/DbAction.java | 3 ++- .../conversion/DeleteBatchingAggregateChange.java | 8 -------- 6 files changed, 11 insertions(+), 25 deletions(-) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DataAccessStrategy.java index 3e5974fb7..94a39e559 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DataAccessStrategy.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DataAccessStrategy.java @@ -48,7 +48,7 @@ public interface DataAccessStrategy extends RelationResolver { * @param instance the instance to be stored. Must not be {@code null}. * @param domainType the type of the instance. Must not be {@code null}. * @param identifier information about data that needs to be considered for the insert but which is not part of the - * entity. Namely references back to a parent entity and key/index columns for entities that are stored in a + * entity. Namely, references back to a parent entity and key/index columns for entities that are stored in a * {@link Map} or {@link List}. * @return the id generated by the database if any. * @since 1.1 @@ -66,7 +66,7 @@ public interface DataAccessStrategy extends RelationResolver { * @param instance the instance to be stored. Must not be {@code null}. * @param domainType the type of the instance. Must not be {@code null}. * @param identifier information about data that needs to be considered for the insert but which is not part of the - * entity. Namely references back to a parent entity and key/index columns for entities that are stored in a + * entity. Namely, references back to a parent entity and key/index columns for entities that are stored in a * {@link Map} or {@link List}. * @param idValueSource the {@link IdValueSource} for the insert. * @return the id generated by the database if any. @@ -111,7 +111,7 @@ public interface DataAccessStrategy extends RelationResolver { * @param previousVersion The previous version assigned to the instance being saved. * @param the type of the instance to save. * @return whether the update actually updated a row. - * @throws OptimisticLockingFailureException if the update fails to update at least one row assuming the the + * @throws OptimisticLockingFailureException if the update fails to update at least one row assuming the * optimistic locking version check failed. * @since 2.0 */ @@ -152,7 +152,7 @@ public interface DataAccessStrategy extends RelationResolver { * @param domainType the type of entity to be deleted. Implicitly determines the table to operate on. Must not be * {@code null}. * @param previousVersion The previous version assigned to the instance being saved. - * @throws OptimisticLockingFailureException if the update fails to update at least one row assuming the the + * @throws OptimisticLockingFailureException if the update fails to update at least one row assuming the * optimistic locking version check failed. * @since 2.0 */ 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 334060dac..461beb6b1 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 @@ -42,7 +42,7 @@ import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** - * The default {@link DataAccessStrategy} is to generate SQL statements based on meta data from the entity. + * The default {@link DataAccessStrategy} is to generate SQL statements based on metadata from the entity. * * @author Jens Schauder * @author Mark Paluch 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 e1228fe10..df0844f83 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 @@ -82,7 +82,6 @@ class SqlGenerator { private final Lazy deleteByIdSql = Lazy.of(this::createDeleteByIdSql); private final Lazy deleteByIdInSql = Lazy.of(this::createDeleteByIdInSql); private final Lazy deleteByIdAndVersionSql = Lazy.of(this::createDeleteByIdAndVersionSql); - private final Lazy deleteByIdInAndVersionSql = Lazy.of(this::createDeleteByIdInAndVersionSql); private final Lazy deleteByListSql = Lazy.of(this::createDeleteByListSql); /** @@ -342,15 +341,6 @@ class SqlGenerator { return deleteByIdAndVersionSql.get(); } - /** - * Create a {@code DELETE FROM … WHERE :id In … and :___oldOptimisticLockingVersion = ...} statement. - * - * @return the statement as a {@link String}. Guaranteed to be not {@literal null}. - */ - String getDeleteByIdInAndVersion() { - return deleteByIdInAndVersionSql.get(); - } - /** * Create a {@code DELETE FROM … WHERE :ids in (…)} statement. * @@ -682,11 +672,13 @@ class SqlGenerator { } private DeleteBuilder.DeleteWhereAndOr createBaseDeleteById(Table table) { + return Delete.builder().from(table) .where(getIdColumn().isEqualTo(SQL.bindMarker(":" + renderReference(ID_SQL_PARAMETER)))); } private DeleteBuilder.DeleteWhereAndOr createBaseDeleteByIdIn(Table table) { + return Delete.builder().from(table) .where(getIdColumn().in(SQL.bindMarker(":" + renderReference(IDS_SQL_PARAMETER)))); } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java index ad75859de..08e86cf77 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java @@ -364,8 +364,9 @@ class JdbcAggregateTemplateIntegrationTests { }); } - @Test + @Test // GH-537 void saveAndDeleteAllByAggregateRootsWithVersion() { + AggregateWithImmutableVersion aggregate1 = new AggregateWithImmutableVersion(null, null); AggregateWithImmutableVersion aggregate2 = new AggregateWithImmutableVersion(null, null); AggregateWithImmutableVersion aggregate3 = new AggregateWithImmutableVersion(null, null); diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DbAction.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DbAction.java index dc96ac7c9..56fe5f6d6 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DbAction.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DbAction.java @@ -439,7 +439,8 @@ public interface DbAction { * @since 3.0 */ final class BatchDeleteRoot extends BatchWithValue, Class> { - public BatchDeleteRoot(List> actions) { + + BatchDeleteRoot(List> actions) { super(actions, DeleteRoot::getEntityType); } } diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DeleteBatchingAggregateChange.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DeleteBatchingAggregateChange.java index fe7a02a3b..b916dfe9d 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DeleteBatchingAggregateChange.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DeleteBatchingAggregateChange.java @@ -1,17 +1,9 @@ package org.springframework.data.relational.core.conversion; import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.function.Consumer; -import org.springframework.data.mapping.PersistentPropertyPath; -import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; - -import static java.util.Collections.*; - /** * A {@link BatchingAggregateChange} implementation for delete changes that can contain actions for one or more delete * operations. When consumed, actions are yielded in the appropriate entity tree order with deletes carried out from