Skip to content

Commit 9dd8e4f

Browse files
committed
Rename InsertBatch to BatchInsert
1 parent 5cae2bc commit 9dd8e4f

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ private void execute(DbAction<?> action, JdbcAggregateChangeExecutionContext exe
8484
executionContext.executeInsertRoot((DbAction.InsertRoot<?>) action);
8585
} else if (action instanceof DbAction.Insert) {
8686
executionContext.executeInsert((DbAction.Insert<?>) action);
87-
} else if (action instanceof DbAction.InsertBatch) {
88-
executionContext.executeInsertBatch((DbAction.InsertBatch<?>) action);
87+
} else if (action instanceof DbAction.BatchInsert) {
88+
executionContext.executeBatchInsert((DbAction.BatchInsert<?>) action);
8989
} else if (action instanceof DbAction.UpdateRoot) {
9090
executionContext.executeUpdateRoot((DbAction.UpdateRoot<?>) action);
9191
} else if (action instanceof DbAction.Delete) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ <T> void executeInsert(DbAction.Insert<T> insert) {
8383
add(new DbActionExecutionResult(insert, id));
8484
}
8585

86-
<T> void executeInsertBatch(DbAction.InsertBatch<T> insertBatch) {
86+
<T> void executeBatchInsert(DbAction.BatchInsert<T> batchInsert) {
8787

88-
List<DbAction.Insert<T>> inserts = insertBatch.getActions();
88+
List<DbAction.Insert<T>> inserts = batchInsert.getActions();
8989
List<InsertSubject<T>> insertSubjects = inserts.stream()
9090
.map(insert -> InsertSubject.describedBy(insert.getEntity(), getParentKeys(insert, converter)))
9191
.collect(Collectors.toList());
9292

93-
Object[] ids = accessStrategy.insert(insertSubjects, insertBatch.getEntityType(), insertBatch.getBatchValue());
93+
Object[] ids = accessStrategy.insert(insertSubjects, batchInsert.getEntityType(), batchInsert.getBatchValue());
9494

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

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ void batchInsertOperation_withGeneratedIds() {
129129
.withPart(SqlIdentifier.quoted("DUMMY_ENTITY_KEY"), 0, Integer.class);
130130
when(accessStrategy.insert(singletonList(InsertSubject.describedBy(content, identifier)), Content.class,
131131
IdValueSource.GENERATED)).thenReturn(new Object[] { 456L });
132-
DbAction.InsertBatch<?> insertBatch = new DbAction.InsertBatch<>(
132+
DbAction.BatchInsert<?> batchInsert = new DbAction.BatchInsert<>(
133133
singletonList(createInsert(rootInsert, "list", content, 0, IdValueSource.GENERATED)));
134-
executionContext.executeInsertBatch(insertBatch);
134+
executionContext.executeBatchInsert(batchInsert);
135135

136136
List<DummyEntity> newRoots = executionContext.populateIdsIfNecessary();
137137

@@ -153,9 +153,9 @@ void batchInsertOperation_withoutGeneratedIds() {
153153
.withPart(SqlIdentifier.quoted("DUMMY_ENTITY_KEY"), 0, Integer.class);
154154
when(accessStrategy.insert(singletonList(InsertSubject.describedBy(content, identifier)), Content.class,
155155
IdValueSource.PROVIDED)).thenReturn(new Object[] { null });
156-
DbAction.InsertBatch<?> insertBatch = new DbAction.InsertBatch<>(
156+
DbAction.BatchInsert<?> batchInsert = new DbAction.BatchInsert<>(
157157
singletonList(createInsert(rootInsert, "list", content, 0, IdValueSource.PROVIDED)));
158-
executionContext.executeInsertBatch(insertBatch);
158+
executionContext.executeBatchInsert(batchInsert);
159159

160160
List<DummyEntity> newRoots = executionContext.populateIdsIfNecessary();
161161

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ public String toString() {
382382
* @param <T> type of the entity for which this represents a database interaction.
383383
* @since 2.4
384384
*/
385-
final class InsertBatch<T> extends BatchWithValue<T, Insert<T>, IdValueSource> {
386-
public InsertBatch(List<Insert<T>> actions) {
385+
final class BatchInsert<T> extends BatchWithValue<T, Insert<T>, IdValueSource> {
386+
public BatchInsert(List<Insert<T>> actions) {
387387
super(actions, Insert::getIdValueSource);
388388
}
389389
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void forEachAction(Consumer<? super DbAction<?>> consumer) {
5050
.forEach((entry) -> entry.getValue().forEach(consumer));
5151
insertActions.entrySet().stream().sorted(Map.Entry.comparingByKey(pathLengthComparator))
5252
.forEach((entry) -> entry.getValue()
53-
.forEach((idValueSource, inserts) -> consumer.accept(new DbAction.InsertBatch<>(inserts))));
53+
.forEach((idValueSource, inserts) -> consumer.accept(new DbAction.BatchInsert<>(inserts))));
5454
}
5555

5656
@Override

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ static IdValueSource insertIdValueSource(DbAction<?> action) {
5656
return ((DbAction.InsertRoot<?>) action).getIdValueSource();
5757
} else if (action instanceof DbAction.Insert) {
5858
return ((DbAction.Insert<?>) action).getIdValueSource();
59-
} else if (action instanceof DbAction.InsertBatch) {
60-
return ((DbAction.InsertBatch<?>) action).getBatchValue();
59+
} else if (action instanceof DbAction.BatchInsert) {
60+
return ((DbAction.BatchInsert<?>) action).getBatchValue();
6161
} else {
6262
return null;
6363
}

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

+26-26
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void yieldsDeleteActionsBeforeInsertActions() {
129129

130130
assertThat(extractActions(change)).extracting(DbAction::getClass, DbAction::getEntityType).containsSubsequence( //
131131
Tuple.tuple(DbAction.Delete.class, Intermediate.class), //
132-
Tuple.tuple(DbAction.InsertBatch.class, Intermediate.class));
132+
Tuple.tuple(DbAction.BatchInsert.class, Intermediate.class));
133133
}
134134

135135
@Test
@@ -157,14 +157,14 @@ void yieldsInsertActionsAsBatchInserts_groupedByIdValueSource() {
157157
.extracting(DbAction::getClass, DbAction::getEntityType, DbActionTestSupport::insertIdValueSource) //
158158
.containsSubsequence( //
159159
Tuple.tuple(DbAction.InsertRoot.class, Root.class, IdValueSource.GENERATED), //
160-
Tuple.tuple(DbAction.InsertBatch.class, Intermediate.class, IdValueSource.PROVIDED)) //
160+
Tuple.tuple(DbAction.BatchInsert.class, Intermediate.class, IdValueSource.PROVIDED)) //
161161
.containsSubsequence( //
162162
Tuple.tuple(DbAction.InsertRoot.class, Root.class, IdValueSource.GENERATED), //
163-
Tuple.tuple(DbAction.InsertBatch.class, Intermediate.class, IdValueSource.GENERATED)) //
163+
Tuple.tuple(DbAction.BatchInsert.class, Intermediate.class, IdValueSource.GENERATED)) //
164164
.doesNotContain(Tuple.tuple(DbAction.Insert.class, Intermediate.class));
165-
assertThat(getInsertBatchAction(actions, Intermediate.class, IdValueSource.GENERATED).getActions())
165+
assertThat(getBatchInsertAction(actions, Intermediate.class, IdValueSource.GENERATED).getActions())
166166
.containsExactly(intermediateInsertGeneratedId);
167-
assertThat(getInsertBatchAction(actions, Intermediate.class, IdValueSource.PROVIDED).getActions())
167+
assertThat(getBatchInsertAction(actions, Intermediate.class, IdValueSource.PROVIDED).getActions())
168168
.containsExactly(intermediateInsertProvidedId);
169169
}
170170

@@ -205,11 +205,11 @@ void yieldsNestedInsertActionsInTreeOrderFromRootToLeaves() {
205205
assertThat(actions)
206206
.extracting(DbAction::getClass, DbAction::getEntityType, DbActionTestSupport::insertIdValueSource)
207207
.containsSubsequence( //
208-
Tuple.tuple(DbAction.InsertBatch.class, Intermediate.class, IdValueSource.GENERATED),
209-
Tuple.tuple(DbAction.InsertBatch.class, Leaf.class, IdValueSource.GENERATED));
210-
assertThat(getInsertBatchAction(actions, Intermediate.class).getActions()) //
208+
Tuple.tuple(DbAction.BatchInsert.class, Intermediate.class, IdValueSource.GENERATED),
209+
Tuple.tuple(DbAction.BatchInsert.class, Leaf.class, IdValueSource.GENERATED));
210+
assertThat(getBatchInsertAction(actions, Intermediate.class).getActions()) //
211211
.containsExactly(root1IntermediateInsert, root2IntermediateInsert);
212-
assertThat(getInsertBatchAction(actions, Leaf.class).getActions()) //
212+
assertThat(getBatchInsertAction(actions, Leaf.class).getActions()) //
213213
.containsExactly(root1LeafInsert);
214214
}
215215

@@ -237,33 +237,33 @@ void yieldsInsertsWithSameLengthReferences_asSeparateInserts() {
237237
assertThat(actions)
238238
.extracting(DbAction::getClass, DbAction::getEntityType, DbActionTestSupport::insertIdValueSource)
239239
.containsSubsequence( //
240-
Tuple.tuple(DbAction.InsertBatch.class, Intermediate.class, IdValueSource.GENERATED),
241-
Tuple.tuple(DbAction.InsertBatch.class, Intermediate.class, IdValueSource.GENERATED));
242-
List<DbAction.InsertBatch<Intermediate>> insertBatchActions = getInsertBatchActions(actions, Intermediate.class);
243-
assertThat(insertBatchActions).hasSize(2);
244-
assertThat(insertBatchActions.get(0).getActions()).containsExactly(oneInsert);
245-
assertThat(insertBatchActions.get(1).getActions()).containsExactly(twoInsert);
240+
Tuple.tuple(DbAction.BatchInsert.class, Intermediate.class, IdValueSource.GENERATED),
241+
Tuple.tuple(DbAction.BatchInsert.class, Intermediate.class, IdValueSource.GENERATED));
242+
List<DbAction.BatchInsert<Intermediate>> batchInsertActions = getBatchInsertActions(actions, Intermediate.class);
243+
assertThat(batchInsertActions).hasSize(2);
244+
assertThat(batchInsertActions.get(0).getActions()).containsExactly(oneInsert);
245+
assertThat(batchInsertActions.get(1).getActions()).containsExactly(twoInsert);
246246
}
247247

248-
private <T> DbAction.InsertBatch<T> getInsertBatchAction(List<DbAction<?>> actions, Class<T> entityType,
249-
IdValueSource idValueSource) {
250-
return getInsertBatchActions(actions, entityType).stream()
251-
.filter(insertBatch -> insertBatch.getBatchValue() == idValueSource).findFirst().orElseThrow(
252-
() -> new RuntimeException(String.format("No InsertBatch with includeId '%s' found!", idValueSource)));
248+
private <T> DbAction.BatchInsert<T> getBatchInsertAction(List<DbAction<?>> actions, Class<T> entityType,
249+
IdValueSource idValueSource) {
250+
return getBatchInsertActions(actions, entityType).stream()
251+
.filter(batchInsert -> batchInsert.getBatchValue() == idValueSource).findFirst().orElseThrow(
252+
() -> new RuntimeException(String.format("No BatchInsert with batch value '%s' found!", idValueSource)));
253253
}
254254

255-
private <T> DbAction.InsertBatch<T> getInsertBatchAction(List<DbAction<?>> actions, Class<T> entityType) {
256-
return getInsertBatchActions(actions, entityType).stream().findFirst()
257-
.orElseThrow(() -> new RuntimeException("No InsertBatch action found!"));
255+
private <T> DbAction.BatchInsert<T> getBatchInsertAction(List<DbAction<?>> actions, Class<T> entityType) {
256+
return getBatchInsertActions(actions, entityType).stream().findFirst()
257+
.orElseThrow(() -> new RuntimeException("No BatchInsert action found!"));
258258
}
259259

260260
@SuppressWarnings("unchecked")
261-
private <T> List<DbAction.InsertBatch<T>> getInsertBatchActions(List<DbAction<?>> actions, Class<T> entityType) {
261+
private <T> List<DbAction.BatchInsert<T>> getBatchInsertActions(List<DbAction<?>> actions, Class<T> entityType) {
262262

263263
return actions.stream() //
264-
.filter(dbAction -> dbAction instanceof DbAction.InsertBatch) //
264+
.filter(dbAction -> dbAction instanceof DbAction.BatchInsert) //
265265
.filter(dbAction -> dbAction.getEntityType().equals(entityType)) //
266-
.map(dbAction -> (DbAction.InsertBatch<T>) dbAction).collect(Collectors.toList());
266+
.map(dbAction -> (DbAction.BatchInsert<T>) dbAction).collect(Collectors.toList());
267267
}
268268

269269
private <T> List<DbAction<?>> extractActions(MergedAggregateChange<T, AggregateChangeWithRoot<T>> change) {

0 commit comments

Comments
 (0)