Skip to content

Commit e82befd

Browse files
committed
Polishing.
Formatting. Simplification of code. Original pull request #2065 See #2064
1 parent 712b180 commit e82befd

File tree

2 files changed

+19
-36
lines changed

2 files changed

+19
-36
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.stream.Stream;
2929
import java.util.stream.StreamSupport;
3030

31-
import org.jspecify.annotations.Nullable;
3231
import org.springframework.context.ApplicationContext;
3332
import org.springframework.context.ApplicationEventPublisher;
3433
import org.springframework.data.domain.Page;
@@ -51,22 +50,10 @@
5150
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
5251
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
5352
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
54-
import org.springframework.data.relational.core.mapping.event.AbstractRelationalEvent;
55-
import org.springframework.data.relational.core.mapping.event.AfterConvertCallback;
56-
import org.springframework.data.relational.core.mapping.event.AfterConvertEvent;
57-
import org.springframework.data.relational.core.mapping.event.AfterDeleteCallback;
58-
import org.springframework.data.relational.core.mapping.event.AfterDeleteEvent;
59-
import org.springframework.data.relational.core.mapping.event.AfterSaveCallback;
60-
import org.springframework.data.relational.core.mapping.event.AfterSaveEvent;
61-
import org.springframework.data.relational.core.mapping.event.BeforeConvertCallback;
62-
import org.springframework.data.relational.core.mapping.event.BeforeConvertEvent;
63-
import org.springframework.data.relational.core.mapping.event.BeforeDeleteCallback;
64-
import org.springframework.data.relational.core.mapping.event.BeforeDeleteEvent;
65-
import org.springframework.data.relational.core.mapping.event.BeforeSaveCallback;
66-
import org.springframework.data.relational.core.mapping.event.BeforeSaveEvent;
67-
import org.springframework.data.relational.core.mapping.event.Identifier;
53+
import org.springframework.data.relational.core.mapping.event.*;
6854
import org.springframework.data.relational.core.query.Query;
6955
import org.springframework.data.support.PageableExecutionUtils;
56+
import org.springframework.lang.Nullable;
7057
import org.springframework.util.Assert;
7158
import org.springframework.util.ClassUtils;
7259

@@ -82,6 +69,7 @@
8269
* @author Chirag Tailor
8370
* @author Diego Krupitza
8471
* @author Sergey Korotaev
72+
* @author Mikhail Polivakha
8573
*/
8674
public class JdbcAggregateTemplate implements JdbcAggregateOperations {
8775

@@ -708,16 +696,13 @@ private <T> T triggerBeforeDelete(@Nullable T aggregateRoot, Object id, MutableA
708696
return null;
709697
}
710698

711-
private record EntityAndPreviousVersion<T> (T entity, @Nullable Number version) {
699+
private record EntityAndPreviousVersion<T>(T entity, @Nullable Number version) {
712700
}
713701

714-
private record EntityAndChangeCreator<T> (T entity, AggregateChangeCreator<T> changeCreator) {
702+
private record EntityAndChangeCreator<T>(T entity, AggregateChangeCreator<T> changeCreator) {
715703
}
716704

717-
private interface AggregateChangeCreator<T> extends Function<T, RootAggregateChange<T>> {
718-
719-
default RootAggregateChange<T> createAggregateChange(T instance) {
720-
return this.apply(instance);
721-
}
705+
private interface AggregateChangeCreator<T> {
706+
RootAggregateChange<T> createAggregateChange(T instance);
722707
}
723708
}

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@
2929
import java.util.stream.IntStream;
3030
import java.util.stream.Stream;
3131

32-
import org.assertj.core.api.Assertions;
3332
import org.junit.jupiter.api.Test;
3433
import org.springframework.beans.factory.annotation.Autowired;
3534
import org.springframework.context.ApplicationContext;
36-
import org.springframework.context.ApplicationEventPublisher;
3735
import org.springframework.context.annotation.Bean;
3836
import org.springframework.context.annotation.Configuration;
3937
import org.springframework.context.annotation.Import;
@@ -54,7 +52,6 @@
5452
import org.springframework.data.jdbc.testing.TestClass;
5553
import org.springframework.data.jdbc.testing.TestConfiguration;
5654
import org.springframework.data.jdbc.testing.TestDatabaseFeatures;
57-
import org.springframework.data.mapping.callback.EntityCallbacks;
5855
import org.springframework.data.mapping.context.InvalidPersistentPropertyPath;
5956
import org.springframework.data.relational.core.mapping.Column;
6057
import org.springframework.data.relational.core.mapping.Embedded;
@@ -1375,20 +1372,20 @@ void mapWithEnumKey() {
13751372
assertThat(enumMapOwners).containsExactly(enumMapOwner);
13761373
}
13771374

1378-
@Test //GH-2064
1375+
@Test // GH-2064
13791376
void saveAllBeforeConvertCallback() {
1380-
var first = new BeforeConvertCallbackForSaveBatch("first");
1381-
var second = new BeforeConvertCallbackForSaveBatch("second");
1382-
var third = new BeforeConvertCallbackForSaveBatch("third");
1377+
1378+
BeforeConvertCallbackForSaveBatch first = new BeforeConvertCallbackForSaveBatch("first");
1379+
BeforeConvertCallbackForSaveBatch second = new BeforeConvertCallbackForSaveBatch("second");
1380+
BeforeConvertCallbackForSaveBatch third = new BeforeConvertCallbackForSaveBatch("third");
13831381

13841382
template.saveAll(List.of(first, second, third));
13851383

1386-
var allEntriesInTable = template.findAll(BeforeConvertCallbackForSaveBatch.class);
1384+
List<BeforeConvertCallbackForSaveBatch> allEntriesInTable = template
1385+
.findAll(BeforeConvertCallbackForSaveBatch.class);
13871386

1388-
Assertions.assertThat(allEntriesInTable)
1389-
.hasSize(3)
1390-
.extracting(BeforeConvertCallbackForSaveBatch::getName)
1391-
.containsOnly("first", "second", "third");
1387+
assertThat(allEntriesInTable).hasSize(3).extracting(BeforeConvertCallbackForSaveBatch::getName)
1388+
.containsExactlyInAnyOrder("first", "second", "third");
13921389
}
13931390

13941391
@Test // GH-1684
@@ -2218,9 +2215,8 @@ public String getId() {
22182215
return id;
22192216
}
22202217

2221-
public BeforeConvertCallbackForSaveBatch setId(String id) {
2218+
public void setId(String id) {
22222219
this.id = id;
2223-
return this;
22242220
}
22252221

22262222
public String getName() {
@@ -2258,12 +2254,14 @@ static class WithIdOnly {
22582254

22592255
@Table
22602256
static class WithInsertOnly {
2257+
22612258
@Id Long id;
22622259
@InsertOnlyProperty String insertOnly;
22632260
}
22642261

22652262
@Table
22662263
static class MultipleCollections {
2264+
22672265
@Id Long id;
22682266
String name;
22692267
List<ListElement> listElements = new ArrayList<>();

0 commit comments

Comments
 (0)