Skip to content

First draft of createQuery(TypedQueryReference) #2219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
*/
package org.hibernate.reactive.mutiny;

import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;

import org.hibernate.Cache;
import org.hibernate.CacheMode;
import org.hibernate.Filter;
Expand Down Expand Up @@ -43,12 +38,17 @@
import jakarta.persistence.FlushModeType;
import jakarta.persistence.LockModeType;
import jakarta.persistence.Parameter;
import jakarta.persistence.TypedQueryReference;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaUpdate;
import jakarta.persistence.metamodel.Attribute;
import jakarta.persistence.metamodel.Metamodel;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;

import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
Expand Down Expand Up @@ -994,6 +994,22 @@ default Uni<Void> lock(Object entity, LockModeType lockModeType) {
*/
MutationQuery createMutationQuery(JpaCriteriaInsert<?> insert);

/**
* Create a typed {@link org.hibernate.query.Query} instance for the given typed query reference.
*
* @param typedQueryReference the type query reference
*
* @return The {@link org.hibernate.query.Query} instance for execution
*
* @throws IllegalArgumentException if a query has not been
* defined with the name of the typed query reference or if
* the query result is found to not be assignable to
* result class of the typed query reference
*
* @see org.hibernate.query.QueryProducer#createQuery(TypedQueryReference)
*/
<R> Query<R> createQuery(TypedQueryReference<R> typedQueryReference);

/**
* Create an instance of {@link Query} for the given HQL/JPQL query
* string or HQL/JPQL update or delete statement. In the case of an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.persistence.FlushModeType;
import jakarta.persistence.LockModeType;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.TypedQueryReference;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaUpdate;
Expand All @@ -34,6 +35,7 @@
import org.hibernate.reactive.mutiny.Mutiny.Query;
import org.hibernate.reactive.mutiny.Mutiny.SelectionQuery;
import org.hibernate.reactive.pool.ReactiveConnection;
import org.hibernate.reactive.query.ReactiveQuery;
import org.hibernate.reactive.session.ReactiveConnectionSupplier;
import org.hibernate.reactive.session.ReactiveQueryProducer;
import org.hibernate.reactive.session.ReactiveSession;
Expand Down Expand Up @@ -140,6 +142,12 @@ public MutationQuery createMutationQuery(JpaCriteriaInsert<?> insert) {
return new MutinyMutationQueryImpl<>( delegate.createReactiveMutationQuery( insert ), factory );
}

@Override
public <R> Query<R> createQuery(TypedQueryReference<R> typedQueryReference) {
ReactiveQuery<R> reactiveQuery = delegate.createReactiveQuery( typedQueryReference );
return new MutinyQueryImpl<>( reactiveQuery, factory );
}

@Override @Deprecated
public <R> Query<R> createQuery(String queryString) {
return new MutinyQueryImpl<>( delegate.createReactiveQuery( queryString ), factory );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.hibernate.reactive.session;

import jakarta.persistence.TypedQueryReference;
import java.util.concurrent.CompletionStage;

import org.hibernate.Incubating;
Expand Down Expand Up @@ -53,6 +54,8 @@ public interface ReactiveQueryProducer extends ReactiveConnectionSupplier {

<R> ReactiveQuery<R> createReactiveQuery(String queryString);

<R> ReactiveQuery<R> createReactiveQuery(TypedQueryReference<R> typedQueryReference);

<R> ReactiveQuery<R> createReactiveQuery(CriteriaQuery<R> criteriaQuery);

<R> ReactiveQuery<R> createReactiveQuery(String queryString, Class<R> resultType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.hibernate.reactive.session.impl;

import jakarta.persistence.TypedQueryReference;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -357,6 +358,21 @@ protected <T> ReactiveQueryImplementor<T> createReactiveCriteriaQuery(SqmStateme
return query;
}

@Override
public <R> ReactiveQuery<R> createReactiveQuery(TypedQueryReference<R> typedQueryReference) {
checksBeforeQueryCreation();
@SuppressWarnings("unchecked")
// this cast is fine because of all our impls of TypedQueryReference return Class<R>
final Class<R> resultType = (Class<R>) typedQueryReference.getResultType();
ReactiveQueryImplementor<R> query = (ReactiveQueryImplementor<R>) buildNamedQuery(
typedQueryReference.getName(),
memento -> createSqmQueryImplementor( resultType, memento ),
memento -> createNativeQueryImplementor( resultType, memento )
);
typedQueryReference.getHints().forEach( query::setHint );
return query;
}

@Override
public <R> ReactiveQuery<R> createReactiveQuery(String queryString) {
return createReactiveQuery( queryString, null );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.hibernate.reactive.session.impl;

import jakarta.persistence.TypedQueryReference;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -830,6 +831,21 @@ public <T> RootGraphImplementor<T> getEntityGraph(Class<T> entity, String name)
return (RootGraphImplementor<T>) entityGraph;
}

@Override
public <R> ReactiveQuery<R> createReactiveQuery(TypedQueryReference<R> typedQueryReference) {
checksBeforeQueryCreation();
@SuppressWarnings("unchecked")
// this cast is fine because of all our impls of TypedQueryReference return Class<R>
final Class<R> resultType = (Class<R>) typedQueryReference.getResultType();
ReactiveQueryImplementor<R> query = (ReactiveQueryImplementor<R>) buildNamedQuery(
typedQueryReference.getName(),
memento -> createSqmQueryImplementor( resultType, memento ),
memento -> createNativeQueryImplementor( resultType, memento )
);
typedQueryReference.getHints().forEach( query::setHint );
return query;
}

@Override
public <R> ReactiveSqmQueryImplementor<R> createReactiveQuery(String queryString) {
return createReactiveQuery( queryString, null );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.hibernate.reactive.stage;

import jakarta.persistence.TypedQueryReference;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.concurrent.CompletionStage;
Expand All @@ -26,6 +27,7 @@
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.query.Order;
import org.hibernate.query.Page;
import org.hibernate.query.Query;
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
import org.hibernate.query.criteria.JpaCriteriaInsert;
import org.hibernate.reactive.common.AffectedEntities;
Expand Down Expand Up @@ -885,17 +887,6 @@ default CompletionStage<Void> lock(Object entity, LockModeType lockModeType) {
return lock( entity, convertToLockMode(lockModeType) );
}

// /**
// * Obtain the specified lock level upon the given object, with the given
// * {@link LockOptions}.
// *
// * @param entity a managed persistent instance
// * @param lockOptions the requested {@link LockOptions}
// *
// * @throws IllegalArgumentException if the given instance is not managed
// */
// CompletionStage<Void> lock(Object entity, LockOptions lockOptions);

/**
* Force this session to flush asynchronously. Must be called at the
* end of a unit of work, before committing the transaction and closing
Expand Down Expand Up @@ -1028,6 +1019,22 @@ default CompletionStage<Void> lock(Object entity, LockModeType lockModeType) {
*/
MutationQuery createMutationQuery(JpaCriteriaInsert<?> insert);

/**
* Create a typed {@link org.hibernate.query.Query} instance for the given typed query reference.
*
* @param typedQueryReference the type query reference
*
* @return The {@link org.hibernate.query.Query} instance for execution
*
* @throws IllegalArgumentException if a query has not been
* defined with the name of the typed query reference or if
* the query result is found to not be assignable to
* result class of the typed query reference
*
* @see org.hibernate.query.QueryProducer#createQuery(TypedQueryReference)
*/
<R> Query<R> createQuery(TypedQueryReference<R> typedQueryReference);

/**
* Create an instance of {@link Query} for the given HQL/JPQL query
* string or HQL/JPQL update or delete statement. In the case of an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.hibernate.reactive.stage.impl;

import jakarta.persistence.TypedQueryReference;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.concurrent.CompletionStage;
Expand All @@ -26,6 +27,7 @@
import org.hibernate.reactive.logging.impl.Log;
import org.hibernate.reactive.logging.impl.LoggerFactory;
import org.hibernate.reactive.pool.ReactiveConnection;
import org.hibernate.reactive.query.ReactiveQuery;
import org.hibernate.reactive.session.ReactiveConnectionSupplier;
import org.hibernate.reactive.session.ReactiveQueryProducer;
import org.hibernate.reactive.session.ReactiveSession;
Expand Down Expand Up @@ -530,6 +532,12 @@ public <T> EntityGraph<T> createEntityGraph(Class<T> rootType, String graphName)
return delegate.createEntityGraph( rootType, graphName );
}

@Override
public <R> Query<R> createQuery(TypedQueryReference<R> typedQueryReference) {
ReactiveQuery<R> reactiveQuery = delegate.createReactiveQuery( typedQueryReference );
return new StageQueryImpl<>( reactiveQuery );
}

@Override @Deprecated
public <R> Query<R> createQuery(String queryString) {
return new StageQueryImpl<>( delegate.createReactiveQuery( queryString ) );
Expand Down
Loading