@@ -73,16 +73,19 @@ class JdbcAggregateChangeExecutionContext {
73
73
74
74
<T > void executeInsertRoot (DbAction .InsertRoot <T > insert ) {
75
75
76
- Object id = accessStrategy .insert (insert .getEntity (), insert .getEntityType (), Identifier .empty (), insert .getIdValueSource ());
76
+ Object id = accessStrategy .insert (insert .getEntity (), insert .getEntityType (), Identifier .empty (),
77
+ insert .getIdValueSource ());
77
78
add (new DbActionExecutionResult (insert , id ));
78
79
}
79
80
80
81
<T > void executeBatchInsertRoot (DbAction .BatchInsertRoot <T > batchInsertRoot ) {
81
82
82
83
List <DbAction .InsertRoot <T >> inserts = batchInsertRoot .getActions ();
83
- List <InsertSubject <T >> insertSubjects = inserts .stream ().map (insert -> InsertSubject .describedBy (insert .getEntity (), Identifier .empty ())).collect (Collectors .toList ());
84
+ List <InsertSubject <T >> insertSubjects = inserts .stream ()
85
+ .map (insert -> InsertSubject .describedBy (insert .getEntity (), Identifier .empty ())).collect (Collectors .toList ());
84
86
85
- Object [] ids = accessStrategy .insert (insertSubjects , batchInsertRoot .getEntityType (), batchInsertRoot .getBatchValue ());
87
+ Object [] ids = accessStrategy .insert (insertSubjects , batchInsertRoot .getEntityType (),
88
+ batchInsertRoot .getBatchValue ());
86
89
87
90
for (int i = 0 ; i < inserts .size (); i ++) {
88
91
add (new DbActionExecutionResult (inserts .get (i ), ids .length > 0 ? ids [i ] : null ));
@@ -92,14 +95,17 @@ <T> void executeBatchInsertRoot(DbAction.BatchInsertRoot<T> batchInsertRoot) {
92
95
<T > void executeInsert (DbAction .Insert <T > insert ) {
93
96
94
97
Identifier parentKeys = getParentKeys (insert , converter );
95
- Object id = accessStrategy .insert (insert .getEntity (), insert .getEntityType (), parentKeys , insert .getIdValueSource ());
98
+ Object id = accessStrategy .insert (insert .getEntity (), insert .getEntityType (), parentKeys ,
99
+ insert .getIdValueSource ());
96
100
add (new DbActionExecutionResult (insert , id ));
97
101
}
98
102
99
103
<T > void executeBatchInsert (DbAction .BatchInsert <T > batchInsert ) {
100
104
101
105
List <DbAction .Insert <T >> inserts = batchInsert .getActions ();
102
- List <InsertSubject <T >> insertSubjects = inserts .stream ().map (insert -> InsertSubject .describedBy (insert .getEntity (), getParentKeys (insert , converter ))).collect (Collectors .toList ());
106
+ List <InsertSubject <T >> insertSubjects = inserts .stream ()
107
+ .map (insert -> InsertSubject .describedBy (insert .getEntity (), getParentKeys (insert , converter )))
108
+ .collect (Collectors .toList ());
103
109
104
110
Object [] ids = accessStrategy .insert (insertSubjects , batchInsert .getEntityType (), batchInsert .getBatchValue ());
105
111
@@ -174,7 +180,8 @@ private Identifier getParentKeys(DbAction.WithDependingOn<?> action, JdbcConvert
174
180
.forBackReferences (converter , context .getAggregatePath (action .getPropertyPath ()),
175
181
getValueProvider (id , context .getAggregatePath (action .getPropertyPath ()), converter ));
176
182
177
- for (Map .Entry <PersistentPropertyPath <RelationalPersistentProperty >, Object > qualifier : action .getQualifiers ().entrySet ()) {
183
+ for (Map .Entry <PersistentPropertyPath <RelationalPersistentProperty >, Object > qualifier : action .getQualifiers ()
184
+ .entrySet ()) {
178
185
identifier = identifier .withQualifier (context .getAggregatePath (qualifier .getKey ()), qualifier .getValue ());
179
186
}
180
187
@@ -183,7 +190,8 @@ private Identifier getParentKeys(DbAction.WithDependingOn<?> action, JdbcConvert
183
190
184
191
static Function <AggregatePath , Object > getValueProvider (Object idValue , AggregatePath path , JdbcConverter converter ) {
185
192
186
- RelationalPersistentEntity <?> entity = converter .getMappingContext ().getPersistentEntity (path .getIdDefiningParentPath ().getRequiredIdProperty ().getType ());
193
+ RelationalPersistentEntity <?> entity = converter .getMappingContext ()
194
+ .getPersistentEntity (path .getIdDefiningParentPath ().getRequiredIdProperty ().getType ());
187
195
188
196
Function <AggregatePath , Object > valueProvider = ap -> {
189
197
if (entity == null ) {
@@ -198,7 +206,8 @@ static Function<AggregatePath, Object> getValueProvider(Object idValue, Aggregat
198
206
199
207
private Object getParentId (DbAction .WithDependingOn <?> action ) {
200
208
201
- DbAction .WithEntity <?> idOwningAction = getIdOwningAction (action , context .getAggregatePath (action .getPropertyPath ()).getIdDefiningParentPath ());
209
+ DbAction .WithEntity <?> idOwningAction = getIdOwningAction (action ,
210
+ context .getAggregatePath (action .getPropertyPath ()).getIdDefiningParentPath ());
202
211
203
212
return getPotentialGeneratedIdFrom (idOwningAction );
204
213
}
@@ -207,7 +216,8 @@ private DbAction.WithEntity<?> getIdOwningAction(DbAction.WithEntity<?> action,
207
216
208
217
if (!(action instanceof DbAction .WithDependingOn <?> withDependingOn )) {
209
218
210
- Assert .state (idPath .isRoot (), "When the id path is not empty the id providing action should be of type WithDependingOn" );
219
+ Assert .state (idPath .isRoot (),
220
+ "When the id path is not empty the id providing action should be of type WithDependingOn" );
211
221
212
222
return action ;
213
223
}
@@ -284,7 +294,9 @@ <T> List<T> populateIdsIfNecessary() {
284
294
}
285
295
286
296
if (roots .isEmpty ()) {
287
- throw new IllegalStateException (String .format ("Cannot retrieve the resulting instance(s) unless a %s or %s action was successfully executed" , DbAction .InsertRoot .class .getName (), DbAction .UpdateRoot .class .getName ()));
297
+ throw new IllegalStateException (
298
+ String .format ("Cannot retrieve the resulting instance(s) unless a %s or %s action was successfully executed" ,
299
+ DbAction .InsertRoot .class .getName (), DbAction .UpdateRoot .class .getName ()));
288
300
}
289
301
290
302
Collections .reverse (roots );
@@ -293,19 +305,23 @@ <T> List<T> populateIdsIfNecessary() {
293
305
}
294
306
295
307
@ SuppressWarnings ("unchecked" )
296
- private <S > Object setIdAndCascadingProperties (DbAction .WithEntity <S > action , @ Nullable Object generatedId , StagedValues cascadingValues ) {
308
+ private <S > Object setIdAndCascadingProperties (DbAction .WithEntity <S > action , @ Nullable Object generatedId ,
309
+ StagedValues cascadingValues ) {
297
310
298
311
S originalEntity = action .getEntity ();
299
312
300
- RelationalPersistentEntity <S > persistentEntity = (RelationalPersistentEntity <S >) context .getRequiredPersistentEntity (action .getEntityType ());
301
- PersistentPropertyPathAccessor <S > propertyAccessor = converter .getPropertyAccessor (persistentEntity , originalEntity );
313
+ RelationalPersistentEntity <S > persistentEntity = (RelationalPersistentEntity <S >) context
314
+ .getRequiredPersistentEntity (action .getEntityType ());
315
+ PersistentPropertyPathAccessor <S > propertyAccessor = converter .getPropertyAccessor (persistentEntity ,
316
+ originalEntity );
302
317
303
318
if (IdValueSource .GENERATED .equals (action .getIdValueSource ())) {
304
319
propertyAccessor .setProperty (persistentEntity .getRequiredIdProperty (), generatedId );
305
320
}
306
321
307
322
// set values of changed immutables referenced by this entity
308
- cascadingValues .forEachPath (action , (persistentPropertyPath , o ) -> propertyAccessor .setProperty (getRelativePath (action , persistentPropertyPath ), o ));
323
+ cascadingValues .forEachPath (action , (persistentPropertyPath , o ) -> propertyAccessor
324
+ .setProperty (getRelativePath (action , persistentPropertyPath ), o ));
309
325
310
326
return propertyAccessor .getBean ();
311
327
}
@@ -337,7 +353,8 @@ private <T> void updateWithoutVersion(DbAction.UpdateRoot<T> update) {
337
353
338
354
if (!accessStrategy .update (update .getEntity (), update .getEntityType ())) {
339
355
340
- throw new IncorrectUpdateSemanticsDataAccessException (String .format (UPDATE_FAILED , update .getEntity (), getIdFrom (update )));
356
+ throw new IncorrectUpdateSemanticsDataAccessException (
357
+ String .format (UPDATE_FAILED , update .getEntity (), getIdFrom (update )));
341
358
}
342
359
}
343
360
@@ -358,20 +375,21 @@ private <T> void updateWithVersion(DbAction.UpdateRoot<T> update) {
358
375
*/
359
376
private static class StagedValues {
360
377
361
- static final List <MultiValueAggregator <?>> aggregators = Arrays .asList (SetAggregator .INSTANCE , MapAggregator .INSTANCE , ListAggregator .INSTANCE , SingleElementAggregator .INSTANCE );
378
+ static final List <MultiValueAggregator <?>> aggregators = Arrays .asList (SetAggregator .INSTANCE ,
379
+ MapAggregator .INSTANCE , ListAggregator .INSTANCE , SingleElementAggregator .INSTANCE );
362
380
363
381
Map <DbAction , Map <PersistentPropertyPath , StagedValue >> values = new HashMap <>();
364
382
365
383
/**
366
384
* Adds a value that needs to be set in an entity higher up in the tree of entities in the aggregate. If the
367
385
* attribute to be set is multivalued this method expects only a single element.
368
386
*
369
- * @param action The action responsible for persisting the entity that needs the added value set. Must not be
370
- * {@literal null}.
371
- * @param path The path to the property in which to set the value. Must not be {@literal null}.
387
+ * @param action The action responsible for persisting the entity that needs the added value set. Must not be
388
+ * {@literal null}.
389
+ * @param path The path to the property in which to set the value. Must not be {@literal null}.
372
390
* @param qualifier If {@code path} is a qualified multivalued properties this parameter contains the qualifier. May
373
- * be {@literal null}.
374
- * @param value The value to be set. Must not be {@literal null}.
391
+ * be {@literal null}.
392
+ * @param value The value to be set. Must not be {@literal null}.
375
393
*/
376
394
void stage (DbAction <?> action , PersistentPropertyPath path , @ Nullable Object qualifier , Object value ) {
377
395
@@ -384,9 +402,11 @@ <T> StagedValue gather(DbAction<?> action, PersistentPropertyPath path, @Nullabl
384
402
385
403
MultiValueAggregator <T > aggregator = getAggregatorFor (path );
386
404
387
- Map <PersistentPropertyPath , StagedValue > valuesForPath = this .values .computeIfAbsent (action , dbAction -> new HashMap <>());
405
+ Map <PersistentPropertyPath , StagedValue > valuesForPath = this .values .computeIfAbsent (action ,
406
+ dbAction -> new HashMap <>());
388
407
389
- StagedValue stagedValue = valuesForPath .computeIfAbsent (path , persistentPropertyPath -> new StagedValue (aggregator .createEmptyInstance ()));
408
+ StagedValue stagedValue = valuesForPath .computeIfAbsent (path ,
409
+ persistentPropertyPath -> new StagedValue (aggregator .createEmptyInstance ()));
390
410
T currentValue = (T ) stagedValue .value ;
391
411
392
412
stagedValue .value = aggregator .add (currentValue , qualifier , value );
@@ -426,8 +446,7 @@ void forEachPath(DbAction<?> dbAction, BiConsumer<PersistentPropertyPath, Object
426
446
}
427
447
428
448
private static class StagedValue {
429
- @ Nullable
430
- Object value ;
449
+ @ Nullable Object value ;
431
450
boolean isStaged ;
432
451
433
452
public StagedValue (@ Nullable Object value ) {
0 commit comments