Skip to content

Commit

Permalink
Replace loop in cascade
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Jul 11, 2024
1 parent bb8bfe6 commit f30a7a1
Showing 1 changed file with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -623,40 +623,34 @@ private static <T> CompletionStage<Void> cascadeCollectionElements(
final T anything,
final boolean isCascadeDeleteEnabled) throws HibernateException {
final boolean reallyDoCascade = style.reallyDoCascade( action.delegate() ) && child != CollectionType.UNFETCHED_COLLECTION;
CompletionStage<Void> stage = voidFuture();
if ( reallyDoCascade ) {
final boolean traceEnabled = LOG.isTraceEnabled();
stage = stage.thenRun( () -> {
if ( traceEnabled ) {
LOG.tracev( "Done cascade {0} for collection: {1}", action, collectionType.getRole() );
}
} );

final Iterator<?> itr = action.getCascadableChildrenIterator( eventSource, collectionType, child );
while ( itr.hasNext() ) {
stage = stage.thenCompose( v -> cascadeProperty(
action,
cascadePoint,
eventSource,
componentPath,
parent,
itr.next(),
elemType,
style,
collectionType.getRole().substring( collectionType.getRole().lastIndexOf( '.' ) + 1 ),
anything,
isCascadeDeleteEnabled
) );
if ( traceEnabled ) {
LOG.tracev( "Done cascade {0} for collection: {1}", action, collectionType.getRole() );
}
stage = stage.thenRun( () -> {

final Iterator<?> itr = action.getCascadableChildrenIterator( eventSource, collectionType, child );
return loop( itr, (value, integer) -> cascadeProperty(
action,
cascadePoint,
eventSource,
componentPath,
parent,
value,
elemType,
style,
collectionType.getRole().substring( collectionType.getRole().lastIndexOf( '.' ) + 1 ),
anything,
isCascadeDeleteEnabled
) ).thenRun( () -> {
if ( traceEnabled ) {
LOG.tracev( "Done cascade {0} for collection: {1}", action, collectionType.getRole() );
}
} );
} ).thenCompose( v -> doDeleteOrphans( action, eventSource, child, collectionType, style, elemType ) );
}

return stage
.thenCompose( v -> doDeleteOrphans( action, eventSource, child, collectionType, style, elemType ) );
return doDeleteOrphans( action, eventSource, child, collectionType, style, elemType );
}

private static <T> CompletionStage<Void> doDeleteOrphans(
Expand Down

0 comments on commit f30a7a1

Please sign in to comment.