Skip to content

Commit f2dc64e

Browse files
committed
Polishing.
Formatting and comments. See #1201 See #1199 Original pull request #1208
1 parent 508791b commit f2dc64e

File tree

14 files changed

+63
-28
lines changed

14 files changed

+63
-28
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ class AggregateChangeExecutor {
4242
this.accessStrategy = accessStrategy;
4343
}
4444

45+
/**
46+
* Execute an aggregate change which has a root entity. It returns the root entity, with all changes that might apply.
47+
* This might be the original instance or a new instance, depending on its mutability.
48+
*
49+
* @param aggregateChange the aggregate change to be executed. Must not be {@literal null}.
50+
* @param <T> the type of the aggregate root.
51+
* @return the potentially modified aggregate root. Guaranteed to be not {@literal null}.
52+
* @since 3.0
53+
*/
4554
<T> T execute(AggregateChangeWithRoot<T> aggregateChange) {
4655

4756
JdbcAggregateChangeExecutionContext executionContext = new JdbcAggregateChangeExecutionContext(converter,
@@ -52,6 +61,13 @@ <T> T execute(AggregateChangeWithRoot<T> aggregateChange) {
5261
return executionContext.populateIdsIfNecessary();
5362
}
5463

64+
/**
65+
* Execute an aggregate change without a root entity.
66+
*
67+
* @param aggregateChange the aggregate change to be executed. Must not be {@literal null}.
68+
* @param <T> the type of the aggregate root.
69+
* @since 3.0
70+
*/
5571
<T> void execute(AggregateChange<T> aggregateChange) {
5672

5773
JdbcAggregateChangeExecutionContext executionContext = new JdbcAggregateChangeExecutionContext(converter,

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
import org.springframework.util.Assert;
4343

4444
/**
45+
* A container for the data required and produced by an aggregate change execution. Most importantly it holds the
46+
* results of the various actions performed.
47+
*
4548
* @author Jens Schauder
4649
* @author Umut Erturk
4750
* @author Myeonghyeon Lee
@@ -226,9 +229,9 @@ <T> T populateIdsIfNecessary() {
226229
DbAction.WithEntity<?> action = result.getAction();
227230

228231
Object newEntity = setIdAndCascadingProperties(action, result.getGeneratedId(), cascadingValues);
229-
232+
230233
if (action instanceof DbAction.InsertRoot || action instanceof DbAction.UpdateRoot) {
231-
//noinspection unchecked
234+
// noinspection unchecked
232235
return (T) newEntity;
233236
}
234237

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import lombok.AllArgsConstructor;
2222
import lombok.Data;
23+
import lombok.Value;
24+
import lombok.With;
25+
2326
import org.assertj.core.api.SoftAssertions;
2427
import org.junit.jupiter.api.Test;
2528
import org.junit.jupiter.api.extension.ExtendWith;
@@ -38,14 +41,12 @@
3841
import org.springframework.test.context.junit.jupiter.SpringExtension;
3942
import org.springframework.transaction.annotation.Transactional;
4043

41-
import lombok.Value;
42-
import lombok.With;
43-
4444
/**
4545
* Integration tests for {@link JdbcAggregateTemplate} and it's handling of immutable entities.
4646
*
4747
* @author Jens Schauder
4848
* @author Salim Achouche
49+
* @author Chirag Taylor
4950
*/
5051
@ContextConfiguration
5152
@Transactional
@@ -341,8 +342,7 @@ static class NonRoot {
341342
}
342343

343344
static class WithCopyConstructor {
344-
@Id
345-
private final Long id;
345+
@Id private final Long id;
346346
private final String name;
347347

348348
WithCopyConstructor(Long id, String name) {

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

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
4343
import org.springframework.lang.Nullable;
4444

45+
/**
46+
* Test for the {@link JdbcAggregateChangeExecutionContext} when operating on immutable classes.
47+
*
48+
* @author Jens Schauder
49+
* @author Chirag Taylor
50+
*/
4551
public class JdbcAggregateChangeExecutorContextImmutableUnitTests {
4652

4753
RelationalMappingContext context = new RelationalMappingContext();

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
import static org.assertj.core.api.Assertions.*;
2020
import static org.mockito.Mockito.*;
2121

22+
import lombok.Value;
23+
2224
import java.util.ArrayList;
2325
import java.util.List;
2426

25-
import lombok.Value;
2627
import org.junit.jupiter.api.Test;
2728
import org.springframework.data.annotation.Id;
28-
import org.springframework.data.annotation.Version;
2929
import org.springframework.data.jdbc.core.convert.BasicJdbcConverter;
3030
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
3131
import org.springframework.data.jdbc.core.convert.Identifier;
@@ -174,7 +174,8 @@ void updates_whenReferencesWithImmutableIdAreInserted() {
174174
ContentImmutableId contentImmutableId = new ContentImmutableId(null);
175175
root.contentImmutableId = contentImmutableId;
176176
Identifier identifier = Identifier.empty().withPart(SqlIdentifier.quoted("DUMMY_ENTITY"), 123L, Long.class);
177-
when(accessStrategy.insert(contentImmutableId, ContentImmutableId.class, identifier, IdValueSource.GENERATED)).thenReturn(456L);
177+
when(accessStrategy.insert(contentImmutableId, ContentImmutableId.class, identifier, IdValueSource.GENERATED))
178+
.thenReturn(456L);
178179
executionContext.executeInsert(createInsert(rootInsert, "contentImmutableId", contentImmutableId, null));
179180

180181
DummyEntity newRoot = executionContext.populateIdsIfNecessary();

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryBeforeSaveHsqlIntegrationTests.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20+
import lombok.AllArgsConstructor;
21+
import lombok.Data;
22+
import lombok.Value;
23+
import lombok.With;
24+
2025
import java.util.List;
2126

2227
import org.junit.jupiter.api.Test;
@@ -38,11 +43,6 @@
3843
import org.springframework.test.context.ContextConfiguration;
3944
import org.springframework.test.context.junit.jupiter.SpringExtension;
4045

41-
import lombok.AllArgsConstructor;
42-
import lombok.Data;
43-
import lombok.Value;
44-
import lombok.With;
45-
4646
/**
4747
* Integration tests for the {@link BeforeSaveCallback}.
4848
*
@@ -153,7 +153,8 @@ static class MutableEntity {
153153
private String name;
154154
}
155155

156-
private interface MutableWithImmutableIdEntityRepository extends ListCrudRepository<MutableWithImmutableIdEntity, Long> {}
156+
private interface MutableWithImmutableIdEntityRepository
157+
extends ListCrudRepository<MutableWithImmutableIdEntity, Long> {}
157158

158159
@Data
159160
@AllArgsConstructor
@@ -162,14 +163,14 @@ static class MutableWithImmutableIdEntity {
162163
private String name;
163164
}
164165

165-
private interface ImmutableWithMutableIdEntityRepository extends ListCrudRepository<ImmutableWithMutableIdEntity, Long> {}
166+
private interface ImmutableWithMutableIdEntityRepository
167+
extends ListCrudRepository<ImmutableWithMutableIdEntity, Long> {}
166168

167169
@Data
168170
@AllArgsConstructor
169171
static class ImmutableWithMutableIdEntity {
170172
@Id private Long id;
171-
@With
172-
private final String name;
173+
@With private final String name;
173174
}
174175

175176
@Configuration

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/ImmutableAggregateTemplateHsqlIntegrationTests-hsql.sql

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ ALTER TABLE AUTHOR
2626

2727
CREATE TABLE WITH_COPY_CONSTRUCTOR
2828
(
29-
ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY,
30-
NAME VARCHAR(30)
29+
ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY,
30+
NAME VARCHAR(30)
3131
);
3232

3333
CREATE TABLE ROOT
@@ -41,4 +41,5 @@ CREATE TABLE NON_ROOT
4141
ROOT BIGINT NOT NULL,
4242
NAME VARCHAR(30)
4343
);
44-
ALTER TABLE NON_ROOT ADD FOREIGN KEY (ROOT) REFERENCES ROOT (ID);
44+
ALTER TABLE NON_ROOT
45+
ADD FOREIGN KEY (ROOT) REFERENCES ROOT (ID);

spring-data-jdbc/src/test/resources/org/springframework/data/jdbc/mybatis/DummyEntityMapper.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
</insert>
1515
<select id="findById" resultType="MyBatisContext" resultMap="dummyEntityMap">
1616
SELECT
17-
id,
18-
'Name based on an id' || id AS name
17+
id,
18+
'Name based on an id' || id AS name
1919
FROM DummyEntity
2020
WHERE id = #{id}
2121
</select>

spring-data-jdbc/src/test/resources/org/springframework/data/jdbc/mybatis/mapper/DummyEntityMapper.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
</insert>
1515
<select id="findById" resultType="MyBatisContext" resultMap="dummyEntityMap">
1616
SELECT
17-
id,
18-
'name ' || id as name
17+
id,
18+
'name ' || id as name
1919
FROM DummyEntity
2020
WHERE id = #{id}
2121
</select>

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

+3
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ public String toString() {
209209
* Note that deletes for contained entities that reference the root are to be represented by separate
210210
* {@link DbAction}s.
211211
* </p>
212+
*
212213
* @param <T> type of the entity for which this represents a database interaction.
213214
*/
214215
final class DeleteRoot<T> implements DbAction<T> {
@@ -273,6 +274,7 @@ public String toString() {
273274
* Note that deletes for contained entities that reference the root are to be represented by separate
274275
* {@link DbAction}s.
275276
* </p>
277+
*
276278
* @param <T> type of the entity for which this represents a database interaction.
277279
*/
278280
final class DeleteAllRoot<T> implements DbAction<T> {
@@ -399,6 +401,7 @@ interface WithDependingOn<T> extends WithPropertyPath<T>, WithEntity<T> {
399401
* <p>
400402
* Values come from parent entities but one might also add values manually.
401403
* </p>
404+
*
402405
* @return guaranteed to be not {@code null}.
403406
*/
404407
Map<PersistentPropertyPath<RelationalPersistentProperty>, Object> getQualifiers();

spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityDeleteWriterUnitTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*
4040
* @author Jens Schauder
4141
* @author Myeonghyeon Lee
42+
* @author Chirag Taylor
4243
*/
4344
@ExtendWith(MockitoExtension.class)
4445
public class RelationalEntityDeleteWriterUnitTests {

spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityInsertWriterUnitTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* Unit tests for the {@link RelationalEntityInsertWriter}
3434
*
3535
* @author Thomas Lang
36+
* @author Chirag Taylor
3637
*/
3738
@ExtendWith(MockitoExtension.class)
3839
public class RelationalEntityInsertWriterUnitTests {

spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityUpdateWriterUnitTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@
3333
*
3434
* @author Thomas Lang
3535
* @author Myeonghyeon Lee
36+
* @author Chirag Taylor
3637
*/
3738
@ExtendWith(MockitoExtension.class)
3839
public class RelationalEntityUpdateWriterUnitTests {
3940

4041
public static final long SOME_ENTITY_ID = 23L;
41-
private RelationalMappingContext context = new RelationalMappingContext();
42+
private final RelationalMappingContext context = new RelationalMappingContext();
4243

4344
@Test // DATAJDBC-112
4445
public void existingEntityGetsConvertedToDeletePlusUpdate() {

spring-data-relational/src/test/java/org/springframework/data/relational/core/conversion/RelationalEntityWriterUnitTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,8 @@ public void multiLevelQualifiedReferencesWithOutId() {
669669
listMapContainer.maps.add(new NoIdMapContainer());
670670
listMapContainer.maps.get(0).elements.put("one", new NoIdElement());
671671

672-
AggregateChangeWithRoot<NoIdListMapContainer> aggregateChange = MutableAggregateChange.forSave(listMapContainer, 1L);
672+
AggregateChangeWithRoot<NoIdListMapContainer> aggregateChange = MutableAggregateChange.forSave(listMapContainer,
673+
1L);
673674

674675
new RelationalEntityWriter<NoIdListMapContainer>(context).write(listMapContainer, aggregateChange);
675676

0 commit comments

Comments
 (0)