|
5 | 5 | */
|
6 | 6 | package org.hibernate.reactive.session.impl;
|
7 | 7 |
|
8 |
| -import jakarta.persistence.TypedQueryReference; |
9 |
| -import java.util.ArrayList; |
10 |
| -import java.util.List; |
11 |
| -import java.util.concurrent.CompletableFuture; |
12 |
| -import java.util.concurrent.CompletionStage; |
13 |
| -import java.util.function.Supplier; |
14 |
| - |
15 | 8 | import org.hibernate.HibernateException;
|
16 | 9 | import org.hibernate.LockMode;
|
17 | 10 | import org.hibernate.LockOptions;
|
|
49 | 42 | import org.hibernate.query.criteria.JpaCriteriaInsert;
|
50 | 43 | import org.hibernate.query.hql.spi.SqmQueryImplementor;
|
51 | 44 | import org.hibernate.query.named.NamedResultSetMappingMemento;
|
| 45 | +import org.hibernate.query.specification.internal.MutationSpecificationImpl; |
| 46 | +import org.hibernate.query.specification.internal.SelectionSpecificationImpl; |
52 | 47 | import org.hibernate.query.spi.HqlInterpretation;
|
53 | 48 | import org.hibernate.query.spi.QueryImplementor;
|
54 | 49 | import org.hibernate.query.sql.spi.NativeQueryImplementor;
|
|
84 | 79 |
|
85 | 80 | import jakarta.persistence.EntityGraph;
|
86 | 81 | import jakarta.persistence.Tuple;
|
| 82 | +import jakarta.persistence.TypedQueryReference; |
| 83 | +import jakarta.persistence.criteria.CommonAbstractCriteria; |
87 | 84 | import jakarta.persistence.criteria.CriteriaDelete;
|
88 | 85 | import jakarta.persistence.criteria.CriteriaQuery;
|
89 | 86 | import jakarta.persistence.criteria.CriteriaUpdate;
|
@@ -225,15 +222,14 @@ public <T> CompletionStage<List<T>> reactiveGet(Class<T> entityClass, Object...
|
225 | 222 | Object[] sids = new Object[ids.length];
|
226 | 223 | System.arraycopy( ids, 0, sids, 0, ids.length );
|
227 | 224 |
|
228 |
| - final CompletionStage<? extends List<?>> stage = |
229 |
| - getEntityPersister( entityClass.getName() ) |
230 |
| - .reactiveMultiLoad( sids, this, StatelessSessionImpl.MULTI_ID_LOAD_OPTIONS ) |
231 |
| - .whenComplete( (v, e) -> { |
232 |
| - if ( getPersistenceContext().isLoadFinished() ) { |
233 |
| - getPersistenceContext().clear(); |
234 |
| - } |
235 |
| - } ); |
236 |
| - return (CompletionStage<List<T>>) stage; |
| 225 | + return getEntityPersister( entityClass.getName() ) |
| 226 | + .reactiveMultiLoad( sids, this, StatelessSessionImpl.MULTI_ID_LOAD_OPTIONS ) |
| 227 | + .whenComplete( (v, e) -> { |
| 228 | + if ( getPersistenceContext().isLoadFinished() ) { |
| 229 | + getPersistenceContext().clear(); |
| 230 | + } |
| 231 | + } ) |
| 232 | + .thenApply( objects -> (List<T>) objects ); |
237 | 233 | }
|
238 | 234 |
|
239 | 235 | @Override
|
@@ -803,6 +799,14 @@ public <T> RootGraphImplementor<T> getEntityGraph(Class<T> entity, String name)
|
803 | 799 | @Override
|
804 | 800 | public <R> ReactiveQuery<R> createReactiveQuery(TypedQueryReference<R> typedQueryReference) {
|
805 | 801 | checksBeforeQueryCreation();
|
| 802 | + if ( typedQueryReference instanceof SelectionSpecificationImpl<R> specification ) { |
| 803 | + final CriteriaQuery<R> query = specification.buildCriteria( getCriteriaBuilder() ); |
| 804 | + return new ReactiveQuerySqmImpl<>( (SqmStatement<R>) query, specification.getResultType(), this ); |
| 805 | + } |
| 806 | + if ( typedQueryReference instanceof MutationSpecificationImpl<?> specification ) { |
| 807 | + final CommonAbstractCriteria query = specification.buildCriteria( getCriteriaBuilder() ); |
| 808 | + return new ReactiveQuerySqmImpl<>( (SqmStatement<R>) query, (Class<R>) specification.getResultType(), this ); |
| 809 | + } |
806 | 810 | @SuppressWarnings("unchecked")
|
807 | 811 | // this cast is fine because of all our impls of TypedQueryReference return Class<R>
|
808 | 812 | final Class<R> resultType = (Class<R>) typedQueryReference.getResultType();
|
|
0 commit comments