Browse Source

Polishing.

Original pull request #1231
See #537
pull/1264/head
Jens Schauder 4 years ago
parent
commit
ed7853d2d0
No known key found for this signature in database
GPG Key ID: 45CC872F17423DBF
  1. 8
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DataAccessStrategy.java
  2. 2
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java
  3. 12
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java
  4. 3
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java
  5. 3
      spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DbAction.java
  6. 8
      spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DeleteBatchingAggregateChange.java

8
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DataAccessStrategy.java

@ -48,7 +48,7 @@ public interface DataAccessStrategy extends RelationResolver { @@ -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 { @@ -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 { @@ -111,7 +111,7 @@ public interface DataAccessStrategy extends RelationResolver {
* @param previousVersion The previous version assigned to the instance being saved.
* @param <T> 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 { @@ -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
*/

2
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java

@ -42,7 +42,7 @@ import org.springframework.lang.Nullable; @@ -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

12
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java

@ -82,7 +82,6 @@ class SqlGenerator { @@ -82,7 +82,6 @@ class SqlGenerator {
private final Lazy<String> deleteByIdSql = Lazy.of(this::createDeleteByIdSql);
private final Lazy<String> deleteByIdInSql = Lazy.of(this::createDeleteByIdInSql);
private final Lazy<String> deleteByIdAndVersionSql = Lazy.of(this::createDeleteByIdAndVersionSql);
private final Lazy<String> deleteByIdInAndVersionSql = Lazy.of(this::createDeleteByIdInAndVersionSql);
private final Lazy<String> deleteByListSql = Lazy.of(this::createDeleteByListSql);
/**
@ -342,15 +341,6 @@ class SqlGenerator { @@ -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 { @@ -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))));
}

3
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java

@ -364,8 +364,9 @@ class JdbcAggregateTemplateIntegrationTests { @@ -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);

3
spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DbAction.java

@ -439,7 +439,8 @@ public interface DbAction<T> { @@ -439,7 +439,8 @@ public interface DbAction<T> {
* @since 3.0
*/
final class BatchDeleteRoot<T> extends BatchWithValue<T, DeleteRoot<T>, Class<T>> {
public BatchDeleteRoot(List<DeleteRoot<T>> actions) {
BatchDeleteRoot(List<DeleteRoot<T>> actions) {
super(actions, DeleteRoot::getEntityType);
}
}

8
spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DeleteBatchingAggregateChange.java

@ -1,17 +1,9 @@ @@ -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

Loading…
Cancel
Save