Skip to content

Commit 5bf2af5

Browse files
committed
Finish implementation of ReactiveSingleIdEntityLoaderDynamicBatch
1 parent 50a8ee7 commit 5bf2af5

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdEntityLoaderDynamicBatch.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.hibernate.query.spi.QueryOptions;
2525
import org.hibernate.query.spi.QueryOptionsAdapter;
2626
import org.hibernate.reactive.loader.ast.spi.ReactiveSingleIdEntityLoader;
27+
import org.hibernate.reactive.sql.exec.internal.StandardReactiveSelectExecutor;
28+
import org.hibernate.reactive.sql.results.spi.ReactiveListResultsConsumer;
2729
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
2830
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
2931
import org.hibernate.sql.ast.tree.select.SelectStatement;
@@ -34,11 +36,9 @@
3436
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
3537
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
3638
import org.hibernate.sql.results.internal.RowTransformerStandardImpl;
37-
import org.hibernate.sql.results.spi.ListResultsConsumer;
3839

3940
import org.jboss.logging.Logger;
4041

41-
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
4242

4343
/**
4444
* @see org.hibernate.loader.ast.internal.SingleIdEntityLoaderDynamicBatch
@@ -167,7 +167,7 @@ public CompletionStage<T> load(
167167
jdbcParameterBindings
168168
);
169169

170-
session.getJdbcServices().getJdbcSelectExecutor().list(
170+
return StandardReactiveSelectExecutor.INSTANCE.list(
171171
jdbcSelect,
172172
jdbcParameterBindings,
173173
getExecutionContext(
@@ -179,20 +179,21 @@ public CompletionStage<T> load(
179179
subSelectFetchableKeysHandler
180180
),
181181
RowTransformerStandardImpl.instance(),
182-
ListResultsConsumer.UniqueSemantic.FILTER
183-
);
184-
185-
//noinspection ForLoopReplaceableByForEach
186-
for ( int i = 0; i < idsToLoad.length; i++ ) {
187-
final Object id = idsToLoad[i];
188-
// found or not, remove the key from the batch-fetch queye
189-
BatchFetchQueueHelper.removeBatchLoadableEntityKey( id, getLoadable(), session );
190-
}
191-
192-
final EntityKey entityKey = session.generateEntityKey( pkValue, getLoadable().getEntityPersister() );
193-
//noinspection unchecked
194-
return completedFuture( (T) session.getPersistenceContext().getEntity( entityKey ) );
195-
182+
ReactiveListResultsConsumer.UniqueSemantic.FILTER
183+
)
184+
.thenApply( results -> {
185+
//noinspection ForLoopReplaceableByForEach
186+
for ( int i = 0; i < idsToLoad.length; i++ ) {
187+
final Object id = idsToLoad[i];
188+
// found or not, remove the key from the batch-fetch queue
189+
BatchFetchQueueHelper.removeBatchLoadableEntityKey( id, getLoadable(), session );
190+
}
191+
192+
final EntityKey entityKey = session.generateEntityKey( pkValue, getLoadable().getEntityPersister() );
193+
//noinspection unchecked
194+
return (T) session.getPersistenceContext().getEntity( entityKey );
195+
196+
} );
196197
}
197198

198199
private void initializeSingleIdLoaderIfNeeded(SharedSessionContractImplementor session) {

0 commit comments

Comments
 (0)