49
49
* @author Umut Erturk
50
50
* @author Myeonghyeon Lee
51
51
* @author Chirag Tailor
52
+ * @author Mark Paluch
52
53
*/
53
54
@ SuppressWarnings ("rawtypes" )
54
55
class JdbcAggregateChangeExecutionContext {
@@ -268,12 +269,10 @@ <T> List<T> populateIdsIfNecessary() {
268
269
269
270
cascadingValues .stage (insert .getDependingOn (), insert .getPropertyPath (),
270
271
qualifierValue , newEntity );
271
-
272
272
} else if (insert .getPropertyPath ().getLeafProperty ().isCollectionLike ()) {
273
273
274
274
cascadingValues .gather (insert .getDependingOn (), insert .getPropertyPath (),
275
275
qualifierValue , newEntity );
276
-
277
276
}
278
277
}
279
278
}
@@ -289,6 +288,7 @@ <T> List<T> populateIdsIfNecessary() {
289
288
return roots ;
290
289
}
291
290
291
+ @ SuppressWarnings ("unchecked" )
292
292
private <S > Object setIdAndCascadingProperties (DbAction .WithEntity <S > action , @ Nullable Object generatedId ,
293
293
StagedValues cascadingValues ) {
294
294
@@ -328,6 +328,7 @@ private PersistentPropertyPath<?> getRelativePath(DbAction<?> action, Persistent
328
328
throw new IllegalArgumentException (String .format ("DbAction of type %s is not supported" , action .getClass ()));
329
329
}
330
330
331
+ @ SuppressWarnings ("unchecked" )
331
332
private <T > RelationalPersistentEntity <T > getRequiredPersistentEntity (Class <T > type ) {
332
333
return (RelationalPersistentEntity <T >) context .getRequiredPersistentEntity (type );
333
334
}
@@ -358,7 +359,7 @@ private <T> void updateWithVersion(DbAction.UpdateRoot<T> update) {
358
359
*/
359
360
private static class StagedValues {
360
361
361
- static final List <MultiValueAggregator > aggregators = Arrays .asList (SetAggregator .INSTANCE , MapAggregator .INSTANCE ,
362
+ static final List <MultiValueAggregator <?> > aggregators = Arrays .asList (SetAggregator .INSTANCE , MapAggregator .INSTANCE ,
362
363
ListAggregator .INSTANCE , SingleElementAggregator .INSTANCE );
363
364
364
365
Map <DbAction , Map <PersistentPropertyPath , StagedValue >> values = new HashMap <>();
@@ -374,13 +375,14 @@ private static class StagedValues {
374
375
* be {@literal null}.
375
376
* @param value The value to be set. Must not be {@literal null}.
376
377
*/
377
- @ SuppressWarnings ( "unchecked" )
378
- < T > void stage ( DbAction <?> action , PersistentPropertyPath path , @ Nullable Object qualifier , Object value ) {
379
- gather (action , path , qualifier , value );
380
- values . get ( action ). get ( path ) .isStaged = true ;
378
+ void stage ( DbAction <?> action , PersistentPropertyPath path , @ Nullable Object qualifier , Object value ) {
379
+
380
+ StagedValue gather = gather (action , path , qualifier , value );
381
+ gather .isStaged = true ;
381
382
}
382
383
383
- <T > void gather (DbAction <?> action , PersistentPropertyPath path , @ Nullable Object qualifier , Object value ) {
384
+ @ SuppressWarnings ("unchecked" )
385
+ <T > StagedValue gather (DbAction <?> action , PersistentPropertyPath path , @ Nullable Object qualifier , Object value ) {
384
386
385
387
MultiValueAggregator <T > aggregator = getAggregatorFor (path );
386
388
@@ -391,19 +393,20 @@ <T> void gather(DbAction<?> action, PersistentPropertyPath path, @Nullable Objec
391
393
persistentPropertyPath -> new StagedValue (aggregator .createEmptyInstance ()));
392
394
T currentValue = (T ) stagedValue .value ;
393
395
394
- Object newValue = aggregator .add (currentValue , qualifier , value );
395
-
396
- stagedValue .value = newValue ;
396
+ stagedValue .value = aggregator .add (currentValue , qualifier , value );
397
397
398
398
valuesForPath .put (path , stagedValue );
399
+
400
+ return stagedValue ;
399
401
}
400
402
401
- private MultiValueAggregator getAggregatorFor (PersistentPropertyPath path ) {
403
+ @ SuppressWarnings ("unchecked" )
404
+ private <T > MultiValueAggregator <T > getAggregatorFor (PersistentPropertyPath path ) {
402
405
403
406
PersistentProperty property = path .getLeafProperty ();
404
- for (MultiValueAggregator aggregator : aggregators ) {
407
+ for (MultiValueAggregator <?> aggregator : aggregators ) {
405
408
if (aggregator .handles (property )) {
406
- return aggregator ;
409
+ return ( MultiValueAggregator < T >) aggregator ;
407
410
}
408
411
}
409
412
@@ -427,10 +430,10 @@ void forEachPath(DbAction<?> dbAction, BiConsumer<PersistentPropertyPath, Object
427
430
}
428
431
429
432
private static class StagedValue {
430
- Object value ;
433
+ @ Nullable Object value ;
431
434
boolean isStaged ;
432
435
433
- public StagedValue (Object value ) {
436
+ public StagedValue (@ Nullable Object value ) {
434
437
this .value = value ;
435
438
}
436
439
}
0 commit comments