|
7 | 7 |
|
8 | 8 | import java.io.Serializable;
|
9 | 9 | import java.util.Iterator;
|
| 10 | +import java.util.List; |
10 | 11 | import java.util.Map;
|
11 | 12 | import java.util.concurrent.CompletionStage;
|
12 | 13 | import java.util.function.BiConsumer;
|
@@ -719,37 +720,43 @@ public NaturalIdResolutions getNaturalIdResolutions() {
|
719 | 720 |
|
720 | 721 | /**
|
721 | 722 | * Reactive version of {@link StatefulPersistenceContext#postLoad(JdbcValuesSourceProcessingState, Consumer)}
|
722 |
| - * |
723 | 723 | */
|
724 |
| - public CompletionStage<Void> reactivePostLoad(JdbcValuesSourceProcessingState processingState, Consumer<EntityHolder> holderConsumer) { |
725 |
| - final ReactiveCallbackImpl callback = (ReactiveCallbackImpl) processingState.getExecutionContext().getCallback(); |
726 |
| - |
727 |
| - if ( processingState.getLoadingEntityHolders() != null ) { |
728 |
| - final EventListenerGroup<PostLoadEventListener> listenerGroup = |
729 |
| - getSession().getFactory().getEventListenerGroups().eventListenerGroup_POST_LOAD; |
730 |
| - final PostLoadEvent postLoadEvent = processingState.getPostLoadEvent(); |
731 |
| - return loop( |
732 |
| - processingState.getLoadingEntityHolders(), entityHolder -> |
733 |
| - processLoadedEntityHolder( |
734 |
| - entityHolder, |
735 |
| - listenerGroup, |
736 |
| - postLoadEvent, |
737 |
| - callback, |
738 |
| - holderConsumer |
739 |
| - )) |
740 |
| - .thenAccept( v -> processingState.getLoadingEntityHolders().clear() ); |
741 |
| - } |
742 |
| - if ( processingState.getReloadedEntityHolders() != null ) { |
743 |
| - return loop( |
744 |
| - processingState.getLoadingEntityHolders(), entityHolder -> |
745 |
| - processLoadedEntityHolder( |
746 |
| - entityHolder, |
747 |
| - null, |
748 |
| - null, |
749 |
| - callback, |
750 |
| - holderConsumer |
751 |
| - )) |
752 |
| - .thenAccept( v -> processingState.getLoadingEntityHolders().clear() ); |
| 724 | + public CompletionStage<Void> reactivePostLoad( |
| 725 | + JdbcValuesSourceProcessingState processingState, |
| 726 | + Consumer<EntityHolder> holderConsumer) { |
| 727 | + final ReactiveCallbackImpl callback = (ReactiveCallbackImpl) processingState |
| 728 | + .getExecutionContext().getCallback(); |
| 729 | + return processHolders( |
| 730 | + holderConsumer, |
| 731 | + processingState.getLoadingEntityHolders(), |
| 732 | + getSession().getFactory().getEventListenerGroups().eventListenerGroup_POST_LOAD, |
| 733 | + processingState.getPostLoadEvent(), |
| 734 | + callback |
| 735 | + ).thenCompose( v -> processHolders( |
| 736 | + holderConsumer, |
| 737 | + processingState.getReloadedEntityHolders(), |
| 738 | + null, |
| 739 | + null, |
| 740 | + callback |
| 741 | + ) ); |
| 742 | + } |
| 743 | + |
| 744 | + private CompletionStage<Void> processHolders( |
| 745 | + Consumer<EntityHolder> holderConsumer, |
| 746 | + List<EntityHolder> loadingEntityHolders, |
| 747 | + EventListenerGroup<PostLoadEventListener> listenerGroup, |
| 748 | + PostLoadEvent postLoadEvent, |
| 749 | + ReactiveCallbackImpl callback) { |
| 750 | + if ( loadingEntityHolders != null ) { |
| 751 | + return loop( loadingEntityHolders, |
| 752 | + holder -> processLoadedEntityHolder( |
| 753 | + holder, |
| 754 | + listenerGroup, |
| 755 | + postLoadEvent, |
| 756 | + callback, |
| 757 | + holderConsumer |
| 758 | + ) |
| 759 | + ).thenAccept( v -> loadingEntityHolders.clear() ); |
753 | 760 | }
|
754 | 761 | return voidFuture();
|
755 | 762 | }
|
|
0 commit comments