Skip to content
Closed

WIP #10030

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 @@ -46,9 +46,11 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.procedure.ProcedureCall;
import org.hibernate.query.MutationQuery;
import org.hibernate.query.SelectionBuilder;
import org.hibernate.query.SelectionQuery;
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
import org.hibernate.query.criteria.JpaCriteriaInsert;
import org.hibernate.query.criteria.JpaCriteriaQuery;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.query.spi.QueryProducerImplementor;
import org.hibernate.query.sql.spi.NativeQueryImplementor;
Expand Down Expand Up @@ -587,6 +589,16 @@ public <R> SelectionQuery<R> createSelectionQuery(String hqlString, EntityGraph<
return queryDelegate().createSelectionQuery( hqlString, resultGraph );
}

@Override
public <R> JpaCriteriaQuery<R> createSelectionCriteria(String hqlString, Class<R> resultClass) {
return queryDelegate().createSelectionCriteria( hqlString, resultClass );
}

@Override
public <R> SelectionBuilder<R> createSelectionBuilder(String hqlString, Class<R> resultClass) {
return queryDelegate().createSelectionBuilder( hqlString, resultClass );
}

@Override
public <R> SelectionQuery<R> createSelectionQuery(CriteriaQuery<R> criteria) {
return queryDelegate().createSelectionQuery( criteria );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
import org.hibernate.query.MutationQuery;
import org.hibernate.query.NativeQuery;
import org.hibernate.query.Query;
import org.hibernate.query.SelectionBuilder;
import org.hibernate.query.SelectionQuery;
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
import org.hibernate.query.criteria.JpaCriteriaInsert;
import org.hibernate.query.criteria.JpaCriteriaQuery;
import org.hibernate.stat.SessionStatistics;

import jakarta.persistence.ConnectionConsumer;
Expand Down Expand Up @@ -704,6 +706,16 @@ public <R> SelectionQuery<R> createSelectionQuery(String hqlString, EntityGraph<
return this.lazySession.get().createSelectionQuery( hqlString, resultGraph );
}

@Override
public <R> JpaCriteriaQuery<R> createSelectionCriteria(String hqlString, Class<R> resultClass) {
return this.lazySession.get().createSelectionCriteria( hqlString, resultClass );
}

@Override
public <R> SelectionBuilder<R> createSelectionBuilder(String hqlString, Class<R> resultClass) {
return this.lazySession.get().createSelectionBuilder( hqlString, resultClass );
}

@Override
public <R> SelectionQuery<R> createSelectionQuery(CriteriaQuery<R> criteria) {
return this.lazySession.get().createSelectionQuery( criteria );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.procedure.ProcedureCall;
import org.hibernate.query.MutationQuery;
import org.hibernate.query.SelectionBuilder;
import org.hibernate.query.SelectionQuery;
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
import org.hibernate.query.criteria.JpaCriteriaInsert;
import org.hibernate.query.criteria.JpaCriteriaQuery;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.query.spi.QueryProducerImplementor;
import org.hibernate.query.sql.spi.NativeQueryImplementor;
Expand Down Expand Up @@ -154,6 +156,16 @@ public <R> SelectionQuery<R> createSelectionQuery(String hqlString, EntityGraph<
return queryDelegate().createSelectionQuery( hqlString, resultGraph );
}

@Override
public <R> JpaCriteriaQuery<R> createSelectionCriteria(String hqlString, Class<R> resultClass) {
return queryDelegate().createSelectionCriteria( hqlString, resultClass );
}

@Override
public <R> SelectionBuilder<R> createSelectionBuilder(String hqlString, Class<R> resultClass) {
return queryDelegate().createSelectionBuilder( hqlString, resultClass );
}

@Override
public <R> SelectionQuery<R> createSelectionQuery(CriteriaQuery<R> criteria) {
return queryDelegate().createSelectionQuery( criteria );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@
import org.hibernate.query.MutationQuery;
import org.hibernate.query.Query;
import org.hibernate.query.QueryTypeMismatchException;
import org.hibernate.query.SelectionBuilder;
import org.hibernate.query.SelectionQuery;
import org.hibernate.query.UnknownNamedQueryException;
import org.hibernate.query.criteria.CriteriaDefinition;
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
import org.hibernate.query.criteria.JpaCriteriaInsert;
import org.hibernate.query.criteria.JpaCriteriaQuery;
import org.hibernate.query.hql.spi.SqmQueryImplementor;
import org.hibernate.query.internal.SelectionBuilderImpl;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.named.NamedResultSetMappingMemento;
import org.hibernate.query.spi.HqlInterpretation;
Expand Down Expand Up @@ -871,6 +874,15 @@ public <R> SelectionQuery<R> createSelectionQuery(String hqlString, EntityGraph<
.setEntityGraph( resultGraph, GraphSemantic.LOAD );
}

@Override
public <R> JpaCriteriaQuery<R> createSelectionCriteria(String hqlString, Class<R> resultClass) {
return getCriteriaBuilder().createQuery(hqlString, resultClass);
}

@Override
public <R> SelectionBuilder<R> createSelectionBuilder(String hqlString, Class<R> resultClass) {
return new SelectionBuilderImpl<>( getCriteriaBuilder().createQuery(hqlString, resultClass), this );
}

@Override
public <R> SelectionQuery<R> createSelectionQuery(CriteriaQuery<R> criteria) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.hibernate.query.BindableType;
import org.hibernate.query.KeyedPage;
import org.hibernate.query.KeyedResultList;
import org.hibernate.query.Order;
import org.hibernate.query.OutputableType;
import org.hibernate.query.Query;
import org.hibernate.query.QueryParameter;
Expand Down Expand Up @@ -411,16 +410,6 @@ public QueryParameterBindings getParameterBindings() {
return parameterBindings;
}

@Override
public Query<R> setOrder(List<? extends Order<? super R>> orderList) {
throw new UnsupportedOperationException("Ordering not supported for stored procedure calls");
}

@Override
public Query<R> setOrder(Order<? super R> order) {
throw new UnsupportedOperationException("Ordering not supported for stored procedure calls");
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Parameter registrations
Expand Down
10 changes: 0 additions & 10 deletions hibernate-core/src/main/java/org/hibernate/query/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.graph.GraphSemantic;
import org.hibernate.graph.RootGraph;
import org.hibernate.query.restriction.Restriction;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.transform.ResultTransformer;

Expand Down Expand Up @@ -929,15 +928,6 @@ default Query<R> setPage(Page page) {
@Override
Query<R> setLockMode(LockModeType lockMode);

@Override @Incubating
Query<R> setOrder(List<? extends Order<? super R>> orderList);

@Override @Incubating
Query<R> setOrder(Order<? super R> order);

@Override @Incubating
Query<R> addRestriction(Restriction<? super R> restriction);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// deprecated methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
package org.hibernate.query;

import jakarta.persistence.EntityGraph;
import org.hibernate.Incubating;
import org.hibernate.query.criteria.JpaCriteriaInsert;

import jakarta.persistence.TypedQueryReference;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaUpdate;
import org.hibernate.query.criteria.JpaCriteriaQuery;

/**
* Contract for things that can produce instances of {@link Query} and {@link NativeQuery}.
Expand Down Expand Up @@ -377,6 +379,32 @@ public interface QueryProducer {
*/
<R> SelectionQuery<R> createSelectionQuery(String hqlString, EntityGraph<R> resultGraph);

/**
* Transform the given HQL {@code select} query to an equivalent criteria query.
*
* @param hqlString The HQL {@code select} query
* @param resultClass The result type of the query
*
* @see org.hibernate.query.criteria.HibernateCriteriaBuilder#createQuery(String, Class)
*
* @since 7.0
*/
@Incubating
<R> JpaCriteriaQuery<R> createSelectionCriteria(String hqlString, Class<R> resultClass);

/**
* Transform the given HQL {@code select} query to an equivalent criteria query.
*
* @param hqlString The HQL {@code select} query
* @param resultClass The result type of the query
*
* @see org.hibernate.query.criteria.HibernateCriteriaBuilder#createQuery(String, Class)
*
* @since 7.0
*/
@Incubating
<R> SelectionBuilder<R> createSelectionBuilder(String hqlString, Class<R> resultClass);

/**
* Create a {@link SelectionQuery} reference for the given
* {@link CriteriaQuery}.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.query;

import org.hibernate.Incubating;
import org.hibernate.query.restriction.Restriction;

import java.util.List;

/**
* A builder for a {@link SelectionQuery}.
*
* @since 7.0
*/
@Incubating
public interface SelectionBuilder<T> {

/**
* If the result type of this query is an entity class, add one or more
* {@linkplain org.hibernate.query.Order rules} for ordering the query results.
*
* @param orderList one or more instances of {@link org.hibernate.query.Order}
*
* @see org.hibernate.query.Order
*
* @since 7.0
*/
@Incubating
SelectionBuilder<T> setOrder(List<? extends Order<? super T>> orderList);

/**
* If the result type of this query is an entity class, add a
* {@linkplain org.hibernate.query.Order rule} for ordering the query results.
*
* @param order an instance of {@link org.hibernate.query.Order}
*
* @see org.hibernate.query.Order
*
* @since 7.0
*/
@Incubating
SelectionBuilder<T> setOrder(org.hibernate.query.Order<? super T> order);

/**
* If the result type of this query is an entity class, add a
* {@linkplain Restriction rule} for restricting the query results.
*
* @param restriction an instance of {@link Restriction}
*
* @see Restriction
*
* @since 7.0
*/
@Incubating
SelectionBuilder<T> addRestriction(Restriction<? super T> restriction);

/**
* Creates a query for this selection builder.
*
* @since 7.0
*/
SelectionQuery<T> createQuery();
}
Original file line number Diff line number Diff line change
Expand Up @@ -603,45 +603,6 @@ default Stream<R> stream() {
*/
SelectionQuery<R> setLockMode(String alias, LockMode lockMode);

/**
* If the result type of this query is an entity class, add one or more
* {@linkplain Order rules} for ordering the query results.
*
* @param orderList one or more instances of {@link Order}
*
* @see Order
*
* @since 6.3
*/
@Incubating
SelectionQuery<R> setOrder(List<? extends Order<? super R>> orderList);

/**
* If the result type of this query is an entity class, add a
* {@linkplain Order rule} for ordering the query results.
*
* @param order an instance of {@link Order}
*
* @see Order
*
* @since 6.3
*/
@Incubating
SelectionQuery<R> setOrder(Order<? super R> order);

/**
* If the result type of this query is an entity class, add a
* {@linkplain Restriction rule} for restricting the query results.
*
* @param restriction an instance of {@link Restriction}
*
* @see Restriction
*
* @since 7.0
*/
@Incubating
SelectionQuery<R> addRestriction(Restriction<? super R> restriction);

/**
* Specifies whether follow-on locking should be applied
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.hibernate.query.SelectionQuery;
import org.hibernate.query.criteria.spi.HibernateCriteriaBuilderDelegate;
import org.hibernate.query.common.FetchClauseType;
import org.hibernate.query.restriction.Restriction;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;

Expand Down Expand Up @@ -495,4 +496,19 @@ public <X> JpaFunctionRoot<X> from(JpaSetReturningFunction<X> function) {
public JpaCriteriaQuery<Long> createCountQuery() {
return query.createCountQuery();
}

@Override
public JpaCriteriaQuery<R> setOrder(List<? extends org.hibernate.query.Order<? super R>> orderList) {
return query.setOrder( orderList );
}

@Override
public JpaCriteriaQuery<R> setOrder(org.hibernate.query.Order<? super R> order) {
return query.setOrder( order );
}

@Override
public JpaCriteriaQuery<R> addRestriction(Restriction<? super R> restriction) {
return query.addRestriction( restriction );
}
}
Loading
Loading