Skip to content

Commit 08dfebe

Browse files
committed
Refactoring ReactivePersistenceContextAdapter
1 parent 0c342a2 commit 08dfebe

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/engine/internal/ReactivePersistenceContextAdapter.java

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.io.Serializable;
99
import java.util.Iterator;
10+
import java.util.List;
1011
import java.util.Map;
1112
import java.util.concurrent.CompletionStage;
1213
import java.util.function.BiConsumer;
@@ -719,37 +720,43 @@ public NaturalIdResolutions getNaturalIdResolutions() {
719720

720721
/**
721722
* Reactive version of {@link StatefulPersistenceContext#postLoad(JdbcValuesSourceProcessingState, Consumer)}
722-
*
723723
*/
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() );
753760
}
754761
return voidFuture();
755762
}

0 commit comments

Comments
 (0)