Skip to content

Commit 1bb4fe5

Browse files
committed
Rename RecordDescriptor to InsertSubject.
1 parent 26f0867 commit 1bb4fe5

File tree

9 files changed

+28
-42
lines changed

9 files changed

+28
-42
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.springframework.data.jdbc.core.convert.Identifier;
3434
import org.springframework.data.jdbc.core.convert.JdbcConverter;
3535
import org.springframework.data.jdbc.core.convert.JdbcIdentifierBuilder;
36-
import org.springframework.data.jdbc.core.convert.RecordDescriptor;
36+
import org.springframework.data.jdbc.core.convert.InsertSubject;
3737
import org.springframework.data.mapping.PersistentProperty;
3838
import org.springframework.data.mapping.PersistentPropertyAccessor;
3939
import org.springframework.data.mapping.PersistentPropertyPath;
@@ -109,11 +109,11 @@ <T> void executeInsert(DbAction.Insert<T> insert) {
109109
<T> void executeInsertBatch(DbAction.InsertBatch<T> insertBatch) {
110110

111111
List<DbAction.Insert<T>> inserts = insertBatch.getInserts();
112-
List<RecordDescriptor<T>> recordDescriptors = inserts.stream()
113-
.map(insert -> RecordDescriptor.of(insert.getEntity(), getParentKeys(insert, converter)))
112+
List<InsertSubject<T>> insertSubjects = inserts.stream()
113+
.map(insert -> InsertSubject.describedBy(insert.getEntity(), getParentKeys(insert, converter)))
114114
.collect(Collectors.toList());
115115

116-
Object[] ids = accessStrategy.insert(recordDescriptors, insertBatch.getEntityType(), insertBatch.isIncludeId());
116+
Object[] ids = accessStrategy.insert(insertSubjects, insertBatch.getEntityType(), insertBatch.isIncludeId());
117117

118118
for (int i = 0; i < inserts.size(); i++) {
119119
add(new DbActionExecutionResult(inserts.get(i), ids.length > 0 ? ids[i] : null));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public <T> Object insert(T instance, Class<T> domainType, Identifier identifier,
5555
}
5656

5757
@Override
58-
public <T> Object[] insert(List<RecordDescriptor<T>> recordDescriptors, Class<T> domainType, boolean includeId) {
59-
return collect(das -> das.insert(recordDescriptors, domainType, includeId));
58+
public <T> Object[] insert(List<InsertSubject<T>> insertSubjects, Class<T> domainType, boolean includeId) {
59+
return collect(das -> das.insert(insertSubjects, domainType, includeId));
6060
}
6161

6262
/*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public interface DataAccessStrategy extends RelationResolver {
5555
@Nullable
5656
<T> Object insert(T instance, Class<T> domainType, Identifier identifier, boolean includeId);
5757

58-
<T> Object[] insert(List<RecordDescriptor<T>> recordDescriptors, Class<T> domainType, boolean includeId);
58+
<T> Object[] insert(List<InsertSubject<T>> insertSubjects, Class<T> domainType, boolean includeId);
5959

6060
/**
6161
* Updates the data of a single entity in the database. Referenced entities don't get handled.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ public <T> Object insert(T instance, Class<T> domainType, Identifier identifier,
107107
}
108108

109109
@Override
110-
public <T> Object[] insert(List<RecordDescriptor<T>> recordDescriptors, Class<T> domainType, boolean includeId) {
110+
public <T> Object[] insert(List<InsertSubject<T>> insertSubjects, Class<T> domainType, boolean includeId) {
111111

112-
Assert.notEmpty(recordDescriptors, "recordDescriptors must contain at least one recordDescriptor");
113-
SqlIdentifierParameterSource[] sqlParameterSources = recordDescriptors.stream()
114-
.map(recordDescriptor -> sqlParametersFactory.getInsert(recordDescriptor.getInstance(), domainType, recordDescriptor.getIdentifier()))
112+
Assert.notEmpty(insertSubjects, "Batch insert must contain at least one InsertSubject");
113+
SqlIdentifierParameterSource[] sqlParameterSources = insertSubjects.stream()
114+
.map(insertSubject -> sqlParametersFactory.getInsert(insertSubject.getInstance(), domainType, insertSubject.getIdentifier()))
115115
.toArray(SqlIdentifierParameterSource[]::new);
116116

117117
String insertSql = sql(domainType).getInsert(sqlParameterSources[0].getIdentifiers());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public <T> Object insert(T instance, Class<T> domainType, Identifier identifier,
4848
}
4949

5050
@Override
51-
public <T> Object[] insert(List<RecordDescriptor<T>> recordDescriptors, Class<T> domainType, boolean includeId) {
52-
return delegate.insert(recordDescriptors, domainType, includeId);
51+
public <T> Object[] insert(List<InsertSubject<T>> insertSubjects, Class<T> domainType, boolean includeId) {
52+
return delegate.insert(insertSubjects, domainType, includeId);
5353
}
5454

5555
/*

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/RecordDescriptor.java renamed to spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/InsertSubject.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import java.util.Objects;
44

5-
public final class RecordDescriptor<T> {
5+
public final class InsertSubject<T> {
66
private final T instance;
77
private final Identifier identifier;
88

9-
public static <T> RecordDescriptor<T> of(T instance, Identifier identifier) {
10-
return new RecordDescriptor<>(instance, identifier);
9+
public static <T> InsertSubject<T> describedBy(T instance, Identifier identifier) {
10+
return new InsertSubject<>(instance, identifier);
1111
}
1212

13-
private RecordDescriptor(T instance, Identifier identifier) {
13+
private InsertSubject(T instance, Identifier identifier) {
1414
this.instance = instance;
1515
this.identifier = identifier;
1616
}
@@ -29,7 +29,7 @@ public boolean equals(Object o) {
2929
return true;
3030
if (o == null || getClass() != o.getClass())
3131
return false;
32-
RecordDescriptor<?> that = (RecordDescriptor<?>) o;
32+
InsertSubject<?> that = (InsertSubject<?>) o;
3333
return Objects.equals(instance, that.instance) && Objects.equals(identifier, that.identifier);
3434
}
3535

@@ -40,6 +40,6 @@ public int hashCode() {
4040

4141
@Override
4242
public String toString() {
43-
return "RecordDescriptor{" + "instance=" + instance + ", identifier=" + identifier + '}';
43+
return "InsertSubject{" + "instance=" + instance + ", identifier=" + identifier + '}';
4444
}
4545
}

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ public <T> Object insert(T instance, Class<T> domainType, Identifier identifier,
159159
}
160160

161161
@Override
162-
public <T> Object[] insert(List<RecordDescriptor<T>> recordDescriptors, Class<T> domainType, boolean includeId) {
163-
return recordDescriptors.stream()
164-
.map(recordDescriptor -> insert(recordDescriptor.getInstance(), domainType, recordDescriptor.getIdentifier(), includeId))
162+
public <T> Object[] insert(List<InsertSubject<T>> insertSubjects, Class<T> domainType, boolean includeId) {
163+
return insertSubjects.stream()
164+
.map(insertSubject -> insert(insertSubject.getInstance(), domainType, insertSubject.getIdentifier(), includeId))
165165
.toArray();
166166
}
167167

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.springframework.data.jdbc.core.convert.Identifier;
3131
import org.springframework.data.jdbc.core.convert.JdbcConverter;
3232
import org.springframework.data.jdbc.core.convert.JdbcIdentifierBuilder;
33-
import org.springframework.data.jdbc.core.convert.RecordDescriptor;
33+
import org.springframework.data.jdbc.core.convert.InsertSubject;
3434
import org.springframework.data.mapping.PersistentPropertyPath;
3535
import org.springframework.data.mapping.PersistentPropertyPaths;
3636
import org.springframework.data.relational.core.conversion.DbAction;
@@ -147,7 +147,7 @@ void batchInsertOperation_withGeneratedIds() {
147147
Identifier identifier = Identifier.empty()
148148
.withPart(SqlIdentifier.quoted("DUMMY_ENTITY"), 123L, Long.class)
149149
.withPart(SqlIdentifier.quoted("DUMMY_ENTITY_KEY"), 0, Integer.class);
150-
when(accessStrategy.insert(singletonList(RecordDescriptor.of(content, identifier)), Content.class, false))
150+
when(accessStrategy.insert(singletonList(InsertSubject.describedBy(content, identifier)), Content.class, false))
151151
.thenReturn(new Object[] { 456L });
152152
DbAction.InsertBatch<?> insertBatch = new DbAction.InsertBatch<>(
153153
singletonList(createInsert(rootInsert, "list", content, 0)),
@@ -173,7 +173,7 @@ void batchInsertOperation_withoutGeneratedIds() {
173173
Identifier identifier = Identifier.empty()
174174
.withPart(SqlIdentifier.quoted("DUMMY_ENTITY"), 123L, Long.class)
175175
.withPart(SqlIdentifier.quoted("DUMMY_ENTITY_KEY"), 0, Integer.class);
176-
when(accessStrategy.insert(singletonList(RecordDescriptor.of(content, identifier)), Content.class, true))
176+
when(accessStrategy.insert(singletonList(InsertSubject.describedBy(content, identifier)), Content.class, true))
177177
.thenReturn(new Object[] { null });
178178
DbAction.InsertBatch<?> insertBatch = new DbAction.InsertBatch<>(
179179
singletonList(createInsert(rootInsert, "list", content, 0)),

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,21 @@
1616
package org.springframework.data.jdbc.core.convert;
1717

1818
import static java.util.Collections.*;
19-
import static org.assertj.core.api.Assertions.*;
2019
import static org.mockito.ArgumentMatchers.*;
2120
import static org.mockito.Mockito.*;
2221

23-
import java.util.ArrayList;
24-
import java.util.HashMap;
25-
import java.util.List;
26-
2722
import org.junit.jupiter.api.BeforeEach;
2823
import org.junit.jupiter.api.Test;
29-
import org.mockito.ArgumentCaptor;
30-
import org.springframework.core.convert.converter.Converter;
3124
import org.springframework.data.annotation.Id;
32-
import org.springframework.data.convert.WritingConverter;
3325
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
34-
import org.springframework.data.mapping.PersistentPropertyPath;
3526
import org.springframework.data.relational.core.dialect.Dialect;
3627
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
3728
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
38-
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
3929
import org.springframework.data.relational.core.sql.SqlIdentifier;
4030
import org.springframework.jdbc.core.JdbcOperations;
41-
import org.springframework.jdbc.core.RowMapper;
4231
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
43-
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
4432

45-
import lombok.Data;
4633
import lombok.RequiredArgsConstructor;
47-
import lombok.Value;
4834

4935
/**
5036
* Unit tests for {@link DefaultDataAccessStrategy}.
@@ -118,23 +104,23 @@ public void insertForEntityWithNoId() {
118104
@Test
119105
public void batchInsertWithDefinedIdDoesNotRetrieveGeneratedKeys() {
120106

121-
accessStrategy.insert(singletonList(RecordDescriptor.of(new DummyEntity(ORIGINAL_ID), Identifier.empty())), DummyEntity.class, true);
107+
accessStrategy.insert(singletonList(InsertSubject.describedBy(new DummyEntity(ORIGINAL_ID), Identifier.empty())), DummyEntity.class, true);
122108

123109
verify(insertStrategyFactory).batchInsertStrategy(false, SqlIdentifier.quoted("ID"));
124110
}
125111

126112
@Test
127113
public void batchInsertWithUndefinedIdRetrievesGeneratedKeys() {
128114

129-
accessStrategy.insert(singletonList(RecordDescriptor.of(new DummyEntity(ORIGINAL_ID), Identifier.empty())), DummyEntity.class, false);
115+
accessStrategy.insert(singletonList(InsertSubject.describedBy(new DummyEntity(ORIGINAL_ID), Identifier.empty())), DummyEntity.class, false);
130116

131117
verify(insertStrategyFactory).batchInsertStrategy(true, SqlIdentifier.quoted("ID"));
132118
}
133119

134120
@Test
135121
public void batchInsertForEntityWithNoId() {
136122

137-
accessStrategy.insert(singletonList(RecordDescriptor.of(new DummyEntityWithoutIdAnnotation(ORIGINAL_ID), Identifier.empty())), DummyEntityWithoutIdAnnotation.class, false);
123+
accessStrategy.insert(singletonList(InsertSubject.describedBy(new DummyEntityWithoutIdAnnotation(ORIGINAL_ID), Identifier.empty())), DummyEntityWithoutIdAnnotation.class, false);
138124

139125
verify(insertStrategyFactory).batchInsertStrategy(true, null);
140126
}

0 commit comments

Comments
 (0)