Skip to content

Commit 10b092c

Browse files
mp911deschauder
authored andcommitted
Polishing.
1 parent 38abfb3 commit 10b092c

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@
1515
*/
1616
package org.springframework.data.jdbc.core;
1717

18-
import java.util.*;
18+
import java.util.ArrayList;
19+
import java.util.Arrays;
20+
import java.util.Collections;
21+
import java.util.HashMap;
22+
import java.util.HashSet;
23+
import java.util.LinkedHashMap;
24+
import java.util.List;
25+
import java.util.Map;
26+
import java.util.Optional;
27+
import java.util.Set;
1928
import java.util.function.BiConsumer;
2029
import java.util.function.Function;
2130
import java.util.stream.Collectors;
@@ -176,9 +185,9 @@ private Identifier getParentKeys(DbAction.WithDependingOn<?> action, JdbcConvert
176185

177186
Object id = getParentId(action);
178187

188+
AggregatePath aggregatePath = context.getAggregatePath(action.getPropertyPath());
179189
JdbcIdentifierBuilder identifier = JdbcIdentifierBuilder //
180-
.forBackReferences(converter, context.getAggregatePath(action.getPropertyPath()),
181-
getValueProvider(id, context.getAggregatePath(action.getPropertyPath()), converter));
190+
.forBackReferences(converter, aggregatePath, getIdMapper(id, aggregatePath, converter));
182191

183192
for (Map.Entry<PersistentPropertyPath<RelationalPersistentProperty>, Object> qualifier : action.getQualifiers()
184193
.entrySet()) {
@@ -188,20 +197,17 @@ private Identifier getParentKeys(DbAction.WithDependingOn<?> action, JdbcConvert
188197
return identifier.build();
189198
}
190199

191-
static Function<AggregatePath, Object> getValueProvider(Object idValue, AggregatePath path, JdbcConverter converter) {
200+
static Function<AggregatePath, Object> getIdMapper(Object idValue, AggregatePath path, JdbcConverter converter) {
192201

193202
RelationalPersistentEntity<?> entity = converter.getMappingContext()
194-
.getPersistentEntity(path.getIdDefiningParentPath().getRequiredIdProperty().getType());
203+
.getPersistentEntity(path.getIdDefiningParentPath().getRequiredIdProperty());
195204

196-
Function<AggregatePath, Object> valueProvider = ap -> {
197-
if (entity == null) {
198-
return idValue;
199-
} else {
200-
PersistentPropertyPathAccessor<Object> propertyPathAccessor = entity.getPropertyPathAccessor(idValue);
201-
return propertyPathAccessor.getProperty(ap.getRequiredPersistentPropertyPath());
202-
}
203-
};
204-
return valueProvider;
205+
if (entity == null) {
206+
return aggregatePath -> idValue;
207+
}
208+
209+
PersistentPropertyPathAccessor<Object> propertyPathAccessor = entity.getPropertyPathAccessor(idValue);
210+
return aggregatePath -> propertyPathAccessor.getProperty(aggregatePath.getRequiredPersistentPropertyPath());
205211
}
206212

207213
private Object getParentId(DbAction.WithDependingOn<?> action) {

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,9 @@ private static Function<AggregatePath, Object> getWrappedValueProvider(Function<
454454
AggregatePath aggregatePath) {
455455

456456
AggregatePath idDefiningParentPath = aggregatePath.getIdDefiningParentPath();
457-
458-
if (!idDefiningParentPath.hasIdProperty()) {
459-
return ap -> {
460-
throw new IllegalStateException("This should never happen");
461-
};
462-
}
463-
464457
RelationalPersistentProperty idProperty = idDefiningParentPath.getRequiredIdProperty();
465458
AggregatePath idPath = idProperty.isEntity() ? idDefiningParentPath.append(idProperty) : idDefiningParentPath;
459+
466460
return ap -> valueProvider.apply(idPath.append(ap));
467461
}
468462

0 commit comments

Comments
 (0)