|
23 | 23 | import org.hibernate.reactive.engine.impl.ReactiveCallbackImpl;
|
24 | 24 | import org.hibernate.reactive.sql.exec.internal.StandardReactiveSelectExecutor;
|
25 | 25 | import org.hibernate.reactive.sql.results.spi.ReactiveListResultsConsumer;
|
| 26 | +import org.hibernate.reactive.util.impl.CompletionStages; |
26 | 27 | import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor;
|
27 | 28 | import org.hibernate.sql.ast.tree.select.SelectStatement;
|
28 | 29 | import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
|
29 | 30 | import org.hibernate.sql.exec.spi.Callback;
|
30 | 31 | import org.hibernate.sql.exec.spi.ExecutionContext;
|
31 | 32 | import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
32 | 33 | import org.hibernate.sql.exec.spi.JdbcParametersList;
|
| 34 | +import org.hibernate.sql.results.internal.RowTransformerStandardImpl; |
| 35 | +import org.hibernate.sql.results.spi.RowTransformer; |
33 | 36 |
|
| 37 | +import static org.hibernate.reactive.util.impl.CompletionStages.nullFuture; |
34 | 38 | import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;
|
35 | 39 |
|
36 | 40 | public class ReactiveSingleIdLoadPlan<T> extends SingleIdLoadPlan<CompletionStage<T>> {
|
@@ -75,23 +79,27 @@ public CompletionStage<T> load(Object restrictedValue, Object entityInstance, Bo
|
75 | 79 | );
|
76 | 80 | // FIXME: Should we get this from jdbcServices.getSelectExecutor()?
|
77 | 81 | return StandardReactiveSelectExecutor.INSTANCE
|
78 |
| - .list( getJdbcSelect(), jdbcParameterBindings, executionContext, getRowTransformer(), resultConsumer( singleResultExpected ) ) |
79 |
| - .thenCompose( list -> { |
80 |
| - Object entity = extractEntity( list ); |
81 |
| - return invokeAfterLoadActions( callback, session, entity ) |
82 |
| - .thenApply( v -> (T) entity ); |
83 |
| - } |
84 |
| - ); |
| 82 | + .list( getJdbcSelect(), jdbcParameterBindings, executionContext, rowTransformer(), resultConsumer( singleResultExpected ) ) |
| 83 | + .thenApply( this::extractEntity ) |
| 84 | + .thenCompose( entity -> invokeAfterLoadActions( callback, session, entity ) ); |
85 | 85 | }
|
86 | 86 |
|
87 |
| - private <G> CompletionStage<Void> invokeAfterLoadActions(ReactiveCallbackImpl callback, SharedSessionContractImplementor session, G entity) { |
| 87 | + private RowTransformer<T> rowTransformer() { |
| 88 | + // At the moment, I'm not sure how to refactor the code so that getRowTransformer() |
| 89 | + // returns RowTransformer<T> instead of RowTransformer<CompletionStage<T>>. |
| 90 | + return (RowTransformer<T>) getRowTransformer() |
| 91 | + } |
| 92 | + |
| 93 | + private CompletionStage<T> invokeAfterLoadActions(ReactiveCallbackImpl callback, SharedSessionContractImplementor session, T entity) { |
88 | 94 | if ( entity != null && getLoadable() != null ) {
|
89 |
| - return callback.invokeReactiveLoadActions( entity, (EntityMappingType) getLoadable(), session ); |
| 95 | + return callback |
| 96 | + .invokeReactiveLoadActions( entity, (EntityMappingType) getLoadable(), session ) |
| 97 | + .thenApply( v -> entity ); |
90 | 98 | }
|
91 |
| - return voidFuture(); |
| 99 | + return nullFuture(); |
92 | 100 | }
|
93 | 101 |
|
94 |
| - private Object extractEntity(List<?> list) { |
| 102 | + private T extractEntity(List<T> list) { |
95 | 103 | return list.isEmpty() ? null : list.get( 0 );
|
96 | 104 | }
|
97 | 105 |
|
|
0 commit comments