Polishing.
Formatting. Simplification of code. Original pull request #2065 See #2064
This commit is contained in:
@@ -27,7 +27,6 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -50,22 +49,10 @@ import org.springframework.data.relational.core.conversion.RootAggregateChange;
|
||||
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
|
||||
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
|
||||
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
|
||||
import org.springframework.data.relational.core.mapping.event.AbstractRelationalEvent;
|
||||
import org.springframework.data.relational.core.mapping.event.AfterConvertCallback;
|
||||
import org.springframework.data.relational.core.mapping.event.AfterConvertEvent;
|
||||
import org.springframework.data.relational.core.mapping.event.AfterDeleteCallback;
|
||||
import org.springframework.data.relational.core.mapping.event.AfterDeleteEvent;
|
||||
import org.springframework.data.relational.core.mapping.event.AfterSaveCallback;
|
||||
import org.springframework.data.relational.core.mapping.event.AfterSaveEvent;
|
||||
import org.springframework.data.relational.core.mapping.event.BeforeConvertCallback;
|
||||
import org.springframework.data.relational.core.mapping.event.BeforeConvertEvent;
|
||||
import org.springframework.data.relational.core.mapping.event.BeforeDeleteCallback;
|
||||
import org.springframework.data.relational.core.mapping.event.BeforeDeleteEvent;
|
||||
import org.springframework.data.relational.core.mapping.event.BeforeSaveCallback;
|
||||
import org.springframework.data.relational.core.mapping.event.BeforeSaveEvent;
|
||||
import org.springframework.data.relational.core.mapping.event.Identifier;
|
||||
import org.springframework.data.relational.core.mapping.event.*;
|
||||
import org.springframework.data.relational.core.query.Query;
|
||||
import org.springframework.data.support.PageableExecutionUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -80,6 +67,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @author Myeonghyeon Lee
|
||||
* @author Chirag Tailor
|
||||
* @author Diego Krupitza
|
||||
* @author Mikhail Polivakha
|
||||
*/
|
||||
public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
|
||||
@@ -674,16 +662,13 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
return null;
|
||||
}
|
||||
|
||||
private record EntityAndPreviousVersion<T> (T entity, @Nullable Number version) {
|
||||
private record EntityAndPreviousVersion<T>(T entity, @Nullable Number version) {
|
||||
}
|
||||
|
||||
private record EntityAndChangeCreator<T> (T entity, AggregateChangeCreator<T> changeCreator) {
|
||||
private record EntityAndChangeCreator<T>(T entity, AggregateChangeCreator<T> changeCreator) {
|
||||
}
|
||||
|
||||
private interface AggregateChangeCreator<T> extends Function<T, RootAggregateChange<T>> {
|
||||
|
||||
default RootAggregateChange<T> createAggregateChange(T instance) {
|
||||
return this.apply(instance);
|
||||
}
|
||||
private interface AggregateChangeCreator<T> {
|
||||
RootAggregateChange<T> createAggregateChange(T instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,12 +28,9 @@ import java.util.ArrayList;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.assertj.core.api.SoftAssertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@@ -54,7 +51,6 @@ import org.springframework.data.jdbc.testing.IntegrationTest;
|
||||
import org.springframework.data.jdbc.testing.TestClass;
|
||||
import org.springframework.data.jdbc.testing.TestConfiguration;
|
||||
import org.springframework.data.jdbc.testing.TestDatabaseFeatures;
|
||||
import org.springframework.data.mapping.callback.EntityCallbacks;
|
||||
import org.springframework.data.mapping.context.InvalidPersistentPropertyPath;
|
||||
import org.springframework.data.relational.core.conversion.DbActionExecutionException;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
@@ -1332,20 +1328,20 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests {
|
||||
assertThat(enumMapOwners).containsExactly(enumMapOwner);
|
||||
}
|
||||
|
||||
@Test //GH-2064
|
||||
@Test // GH-2064
|
||||
void saveAllBeforeConvertCallback() {
|
||||
var first = new BeforeConvertCallbackForSaveBatch("first");
|
||||
var second = new BeforeConvertCallbackForSaveBatch("second");
|
||||
var third = new BeforeConvertCallbackForSaveBatch("third");
|
||||
|
||||
BeforeConvertCallbackForSaveBatch first = new BeforeConvertCallbackForSaveBatch("first");
|
||||
BeforeConvertCallbackForSaveBatch second = new BeforeConvertCallbackForSaveBatch("second");
|
||||
BeforeConvertCallbackForSaveBatch third = new BeforeConvertCallbackForSaveBatch("third");
|
||||
|
||||
template.saveAll(List.of(first, second, third));
|
||||
|
||||
var allEntriesInTable = template.findAll(BeforeConvertCallbackForSaveBatch.class);
|
||||
List<BeforeConvertCallbackForSaveBatch> allEntriesInTable = template
|
||||
.findAll(BeforeConvertCallbackForSaveBatch.class);
|
||||
|
||||
Assertions.assertThat(allEntriesInTable)
|
||||
.hasSize(3)
|
||||
.extracting(BeforeConvertCallbackForSaveBatch::getName)
|
||||
.containsOnly("first", "second", "third");
|
||||
assertThat(allEntriesInTable).hasSize(3).extracting(BeforeConvertCallbackForSaveBatch::getName)
|
||||
.containsExactlyInAnyOrder("first", "second", "third");
|
||||
}
|
||||
|
||||
@Test // GH-1684
|
||||
@@ -2175,9 +2171,8 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests {
|
||||
return id;
|
||||
}
|
||||
|
||||
public BeforeConvertCallbackForSaveBatch setId(String id) {
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -2215,12 +2210,14 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests {
|
||||
|
||||
@Table
|
||||
static class WithInsertOnly {
|
||||
|
||||
@Id Long id;
|
||||
@InsertOnlyProperty String insertOnly;
|
||||
}
|
||||
|
||||
@Table
|
||||
static class MultipleCollections {
|
||||
|
||||
@Id Long id;
|
||||
String name;
|
||||
List<ListElement> listElements = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user