|
42 | 42 | import org.hibernate.query.criteria.JpaCriteriaInsert;
|
43 | 43 | import org.hibernate.query.hql.spi.SqmQueryImplementor;
|
44 | 44 | import org.hibernate.query.named.NamedResultSetMappingMemento;
|
| 45 | +import org.hibernate.query.specification.internal.MutationSpecificationImpl; |
| 46 | +import org.hibernate.query.specification.internal.SelectionSpecificationImpl; |
45 | 47 | import org.hibernate.query.spi.HqlInterpretation;
|
46 | 48 | import org.hibernate.query.spi.QueryImplementor;
|
47 | 49 | import org.hibernate.query.sql.spi.NativeQueryImplementor;
|
|
77 | 79 |
|
78 | 80 | import jakarta.persistence.EntityGraph;
|
79 | 81 | import jakarta.persistence.Tuple;
|
| 82 | +import jakarta.persistence.TypedQueryReference; |
| 83 | +import jakarta.persistence.criteria.CommonAbstractCriteria; |
80 | 84 | import jakarta.persistence.criteria.CriteriaDelete;
|
81 | 85 | import jakarta.persistence.criteria.CriteriaQuery;
|
82 | 86 | import jakarta.persistence.criteria.CriteriaUpdate;
|
@@ -218,15 +222,14 @@ public <T> CompletionStage<List<T>> reactiveGet(Class<T> entityClass, Object...
|
218 | 222 | Object[] sids = new Object[ids.length];
|
219 | 223 | System.arraycopy( ids, 0, sids, 0, ids.length );
|
220 | 224 |
|
221 |
| - final CompletionStage<? extends List<?>> stage = |
222 |
| - getEntityPersister( entityClass.getName() ) |
223 |
| - .reactiveMultiLoad( sids, this, StatelessSessionImpl.MULTI_ID_LOAD_OPTIONS ) |
224 |
| - .whenComplete( (v, e) -> { |
225 |
| - if ( getPersistenceContext().isLoadFinished() ) { |
226 |
| - getPersistenceContext().clear(); |
227 |
| - } |
228 |
| - } ); |
229 |
| - 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 ); |
230 | 233 | }
|
231 | 234 |
|
232 | 235 | @Override
|
@@ -793,6 +796,33 @@ public <T> RootGraphImplementor<T> getEntityGraph(Class<T> entity, String name)
|
793 | 796 | return (RootGraphImplementor<T>) entityGraph;
|
794 | 797 | }
|
795 | 798 |
|
| 799 | + @Override |
| 800 | + public <R> ReactiveQuery<R> createReactiveQuery(TypedQueryReference<R> typedQueryReference) { |
| 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 | + // Workaround for ORM, can be remove when this issue is solved: https://hibernate.atlassian.net/browse/HHH-19386 |
| 809 | + Class<R> type = (Class<R>) specification.getResultType() == Void.class |
| 810 | + ? null |
| 811 | + : (Class<R>) specification.getResultType(); |
| 812 | + return new ReactiveQuerySqmImpl<>( (SqmStatement<R>) query, type, this ); |
| 813 | + } |
| 814 | + @SuppressWarnings("unchecked") |
| 815 | + // this cast is fine because of all our impls of TypedQueryReference return Class<R> |
| 816 | + final Class<R> resultType = (Class<R>) typedQueryReference.getResultType(); |
| 817 | + ReactiveQueryImplementor<R> query = (ReactiveQueryImplementor<R>) buildNamedQuery( |
| 818 | + typedQueryReference.getName(), |
| 819 | + memento -> createSqmQueryImplementor( resultType, memento ), |
| 820 | + memento -> createNativeQueryImplementor( resultType, memento ) |
| 821 | + ); |
| 822 | + typedQueryReference.getHints().forEach( query::setHint ); |
| 823 | + return query; |
| 824 | + } |
| 825 | + |
796 | 826 | @Override
|
797 | 827 | public <R> ReactiveSqmQueryImplementor<R> createReactiveQuery(String queryString) {
|
798 | 828 | return createReactiveQuery( queryString, null );
|
|
0 commit comments