Skip to content

Commit 0c342a2

Browse files
committed
Refactoring of ReactiveSingleResultConsumer
1 parent 45c49b6 commit 0c342a2

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/spi/ReactiveListResultsConsumer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,15 @@ private static CompletionStage<Void> finishUp(
135135
SharedSessionContractImplementor session,
136136
JdbcValuesSourceProcessingStateStandardImpl jdbcValuesSourceProcessingState) {
137137
jdbcValuesSourceProcessingState.finishLoadingCollections();
138-
139138
return ( (ReactivePersistenceContextAdapter) session.getPersistenceContextInternal() )
140139
.reactivePostLoad(
141140
jdbcValuesSourceProcessingState,
142-
registerSubselects ?
143-
jdbcValuesSourceProcessingState.getExecutionContext()::registerLoadingEntityHolder :
144-
null
141+
registerSubselects
142+
? jdbcValuesSourceProcessingState.getExecutionContext()::registerLoadingEntityHolder
143+
: null
145144
);
146145
}
147146

148-
149147
/**
150148
* The boolean in the CompletionStage is true if the element has been added to the results
151149
*/

hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/spi/ReactiveSingleResultConsumer.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1313
import org.hibernate.reactive.sql.exec.spi.ReactiveRowProcessingState;
1414
import org.hibernate.reactive.sql.exec.spi.ReactiveValuesResultSet;
15+
import org.hibernate.sql.exec.spi.ExecutionContext;
1516
import org.hibernate.sql.results.jdbc.internal.JdbcValuesSourceProcessingStateStandardImpl;
1617
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingOptions;
1718

19+
/**
20+
* @see org.hibernate.sql.results.spi.SingleResultConsumer
21+
*/
1822
@Incubating
1923
public class ReactiveSingleResultConsumer<T> implements ReactiveResultsConsumer<T, T> {
2024

@@ -33,15 +37,25 @@ public CompletionStage<T> consume(
3337
.thenCompose( result -> {
3438
rowProcessingState.finishRowProcessing( true );
3539
rowReader.finishUp( rowProcessingState );
36-
session.getPersistenceContext();
37-
jdbcValuesSourceProcessingState.finishLoadingCollections();
38-
return ( (ReactivePersistenceContextAdapter) session.getPersistenceContextInternal() )
39-
.reactivePostLoad( jdbcValuesSourceProcessingState, null )
40-
.thenApply( v -> result );
40+
return finishUp( session, jdbcValuesSourceProcessingState, result );
4141
} )
4242
);
4343
}
4444

45+
/**
46+
* Reactive version of {@link JdbcValuesSourceProcessingStateStandardImpl#finishUp(boolean)}
47+
*/
48+
private static <T> CompletionStage<T> finishUp(
49+
SharedSessionContractImplementor session,
50+
JdbcValuesSourceProcessingStateStandardImpl jdbcValuesSourceProcessingState,
51+
T result) {
52+
jdbcValuesSourceProcessingState.finishLoadingCollections();
53+
final ExecutionContext executionContext = jdbcValuesSourceProcessingState.getExecutionContext();
54+
return ( (ReactivePersistenceContextAdapter) session.getPersistenceContextInternal() )
55+
.reactivePostLoad( jdbcValuesSourceProcessingState, executionContext::registerLoadingEntityHolder )
56+
.thenApply( v -> result );
57+
}
58+
4559
@Override
4660
public boolean canResultsBeCached() {
4761
return false;

0 commit comments

Comments
 (0)