HHH-15030 - SelectQuery, MutationQuery, etc

SelectQuery as typed
This commit is contained in:
Steve Ebersole 2022-01-21 23:48:58 -06:00
parent dccb1580fe
commit 6f2273d749
12 changed files with 372 additions and 302 deletions

View File

@ -495,10 +495,15 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
}
@Override
public SelectionQuery createSelectQuery(String hqlString) {
public SelectionQuery<?> createSelectQuery(String hqlString) {
return queryDelegate().createSelectQuery( hqlString );
}
@Override
public <R> SelectionQuery<R> createSelectQuery(String hqlString, Class<R> resultType) {
return queryDelegate().createSelectQuery( hqlString, resultType );
}
@Override
public <T> QueryImplementor<T> createQuery(String queryString, Class<T> resultType) {
return queryDelegate().createQuery( queryString, resultType );

View File

@ -11,6 +11,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.SQLException;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.UUID;
import java.util.function.Function;
@ -56,6 +57,7 @@ import org.hibernate.query.IllegalNamedQueryOptionsException;
import org.hibernate.query.IllegalSelectQueryException;
import org.hibernate.query.MutationQuery;
import org.hibernate.query.Query;
import org.hibernate.query.QueryTypeMismatchException;
import org.hibernate.query.SelectionQuery;
import org.hibernate.query.UnknownNamedQueryException;
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
@ -71,7 +73,7 @@ import org.hibernate.query.sql.spi.NamedNativeQueryMemento;
import org.hibernate.query.sql.spi.NativeQueryImplementor;
import org.hibernate.query.sqm.SqmSelectionQuery;
import org.hibernate.query.sqm.internal.QuerySqmImpl;
import org.hibernate.query.sqm.internal.SqmSelectQueryImpl;
import org.hibernate.query.sqm.internal.SqmSelectionQueryImpl;
import org.hibernate.query.sqm.tree.SqmDmlStatement;
import org.hibernate.query.sqm.tree.SqmStatement;
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
@ -665,7 +667,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
}
@Override
public SelectionQuery createSelectQuery(String hqlString) {
public SelectionQuery<?> createSelectQuery(String hqlString) {
checkOpen();
pulseTransactionCoordinator();
delayedAfterCompletion();
@ -682,7 +684,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
throw new IllegalSelectQueryException( "Expecting a selection query, but found `" + hqlString + "`" );
}
final SqmSelectionQuery query = new SqmSelectQueryImpl( hqlString, hqlInterpretation, this );
final SqmSelectionQuery<?> query = new SqmSelectionQueryImpl<>( hqlString, hqlInterpretation, this );
query.setComment( hqlString );
applyQuerySettingsAndHints( query );
@ -695,6 +697,27 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
}
}
@Override
public <R> SelectionQuery<R> createSelectQuery(String hqlString, Class<R> expectedResultType) {
final SelectionQuery<?> selectQuery = createSelectQuery( hqlString );
//noinspection unchecked
final Class<?> resultType = ( (SqmSelectionQueryImpl<R>) selectQuery ).getResultType();
if ( resultType == null || expectedResultType.isAssignableFrom( resultType ) ) {
//noinspection unchecked
return (SelectionQuery<R>) selectQuery;
}
throw new QueryTypeMismatchException(
String.format(
Locale.ROOT,
"Query result-type error - expecting `%s`, but found `%s`",
expectedResultType.getName(),
resultType.getName()
)
);
}
@Override
public <T> QueryImplementor<T> createQuery(String queryString, Class<T> resultClass) {
checkOpen();

View File

@ -66,7 +66,7 @@ import jakarta.persistence.TypedQuery;
* @param <R> The result type, for typed queries, or {@link Object} for untyped queries
*/
@Incubating
public interface Query<R> extends SelectionQuery, MutationQuery, TypedQuery<R> {
public interface Query<R> extends SelectionQuery<R>, MutationQuery, TypedQuery<R> {
/**
* Execute the query and return the query results as a {@link List}.

View File

@ -168,7 +168,19 @@ public interface QueryProducer {
* @throws IllegalSelectQueryException if the given HQL query
* is an insert, update or delete query
*/
SelectionQuery createSelectQuery(String hqlString);
SelectionQuery<?> createSelectQuery(String hqlString);
/**
* Create a {@link SelectionQuery} reference for the given HQL.
*
* Only valid for select queries
*
* @see jakarta.persistence.EntityManager#createQuery(String)
*
* @throws IllegalSelectQueryException if the given HQL query
* is an insert, update or delete query
*/
<R> SelectionQuery<R> createSelectQuery(String hqlString, Class<R> resultType);
/**
* Create a MutationQuery reference for the given HQL insert,

View File

@ -39,7 +39,7 @@ import jakarta.persistence.TemporalType;
* @author Steve Ebersole
*/
@Incubating
public interface SelectionQuery extends CommonQueryContract {
public interface SelectionQuery<R> extends CommonQueryContract {
/**
* Execute the query and return the query results as a {@link List}.
* If the query contains multiple items in the selection list, then
@ -48,7 +48,7 @@ public interface SelectionQuery extends CommonQueryContract {
*
* @return the result list
*/
List<?> list();
List<R> list();
/**
* Execute the query and return the query results as a {@link List}.
@ -58,7 +58,7 @@ public interface SelectionQuery extends CommonQueryContract {
*
* @return the results as a list
*/
default List<?> getResultList() {
default List<R> getResultList() {
return list();
}
@ -70,7 +70,7 @@ public interface SelectionQuery extends CommonQueryContract {
* @apiNote The exact behavior of this method depends somewhat
* on the JDBC driver's {@link java.sql.ResultSet} scrolling support
*/
ScrollableResults<?> scroll();
ScrollableResults<R> scroll();
/**
* Returns scrollable access to the query results. The capabilities of the
@ -79,7 +79,7 @@ public interface SelectionQuery extends CommonQueryContract {
* @apiNote The exact behavior of this method depends somewhat
* on the JDBC driver's {@link java.sql.ResultSet} scrolling support
*/
ScrollableResults<?> scroll(ScrollMode scrollMode);
ScrollableResults<R> scroll(ScrollMode scrollMode);
/**
* Execute the query and return the query results as a {@link Stream}.
@ -92,7 +92,7 @@ public interface SelectionQuery extends CommonQueryContract {
*
* @return The results as a {@link Stream}
*/
default Stream<?> getResultStream() {
default Stream<R> getResultStream() {
return stream();
}
@ -109,7 +109,7 @@ public interface SelectionQuery extends CommonQueryContract {
*
* @since 5.2
*/
default Stream<?> stream() {
default Stream<R> stream() {
return getResultStream();
}
@ -121,7 +121,7 @@ public interface SelectionQuery extends CommonQueryContract {
*
* @throws NonUniqueResultException if there is more than one matching result
*/
Object uniqueResult();
R uniqueResult();
/**
* Execute the query and return the single result of the query,
@ -132,7 +132,7 @@ public interface SelectionQuery extends CommonQueryContract {
* @throws jakarta.persistence.NonUniqueResultException if there is more than one matching result
* @throws jakarta.persistence.NoResultException if there is no result to return
*/
Object getSingleResult();
R getSingleResult();
/**
* Execute the query and return the single result of the query,
@ -142,18 +142,18 @@ public interface SelectionQuery extends CommonQueryContract {
*
* @throws NonUniqueResultException if there is more than one matching result
*/
Optional<?> uniqueResultOptional();
Optional<R> uniqueResultOptional();
SelectionQuery setHint(String hintName, Object value);
SelectionQuery<R> setHint(String hintName, Object value);
@Override
SelectionQuery setFlushMode(FlushModeType flushMode);
SelectionQuery<R> setFlushMode(FlushModeType flushMode);
@Override
SelectionQuery setHibernateFlushMode(FlushMode flushMode);
SelectionQuery<R> setHibernateFlushMode(FlushMode flushMode);
@Override
SelectionQuery setTimeout(int timeout);
SelectionQuery<R> setTimeout(int timeout);
/**
* Obtain the JDBC fetch size hint in effect for this query. This value is eventually passed along to the JDBC
@ -179,7 +179,7 @@ public interface SelectionQuery extends CommonQueryContract {
*
* @see #getFetchSize()
*/
SelectionQuery setFetchSize(int fetchSize);
SelectionQuery<R> setFetchSize(int fetchSize);
/**
* Should entities and proxies loaded by this Query be put in read-only mode? If the
@ -225,7 +225,7 @@ public interface SelectionQuery extends CommonQueryContract {
* are to be put in read-only mode; {@code false} indicates that entities and proxies
* loaded by the query will be put in modifiable mode
*/
SelectionQuery setReadOnly(boolean readOnly);
SelectionQuery<R> setReadOnly(boolean readOnly);
/**
* The max number of rows requested for the query results
@ -236,7 +236,7 @@ public interface SelectionQuery extends CommonQueryContract {
* Set the max number of rows requested for the query results. Applied
* to the SQL query
*/
SelectionQuery setMaxResults(int maxResult);
SelectionQuery<R> setMaxResults(int maxResult);
/**
* The first row position to return from the query results. Applied
@ -248,7 +248,7 @@ public interface SelectionQuery extends CommonQueryContract {
* Set the first row position to return from the query results. Applied
* to the SQL query
*/
SelectionQuery setFirstResult(int startPosition);
SelectionQuery<R> setFirstResult(int startPosition);
/**
* Obtain the CacheMode in effect for this query. By default, the query
@ -275,7 +275,7 @@ public interface SelectionQuery extends CommonQueryContract {
* @see #getCacheMode()
* @see Session#setCacheMode
*/
SelectionQuery setCacheMode(CacheMode cacheMode);
SelectionQuery<R> setCacheMode(CacheMode cacheMode);
/**
* Should the results of the query be stored in the second level cache?
@ -296,7 +296,7 @@ public interface SelectionQuery extends CommonQueryContract {
*
* @see #isCacheable
*/
SelectionQuery setCacheable(boolean cacheable);
SelectionQuery<R> setCacheable(boolean cacheable);
/**
* Obtain the name of the second level query cache region in which query results will be stored (if they are
@ -311,7 +311,7 @@ public interface SelectionQuery extends CommonQueryContract {
*
* @see #getCacheRegion()
*/
SelectionQuery setCacheRegion(String cacheRegion);
SelectionQuery<R> setCacheRegion(String cacheRegion);
/**
* The LockOptions currently in effect for the query
@ -323,134 +323,134 @@ public interface SelectionQuery extends CommonQueryContract {
*
* @see #setHibernateLockMode
*/
SelectionQuery setLockMode(LockModeType lockMode);
SelectionQuery<R> setLockMode(LockModeType lockMode);
/**
* Specify the root LockMode for the query
*/
SelectionQuery setHibernateLockMode(LockMode lockMode);
SelectionQuery<R> setHibernateLockMode(LockMode lockMode);
/**
* Specify a LockMode to apply to a specific alias defined in the query
*/
SelectionQuery setAliasSpecificLockMode(String alias, LockMode lockMode);
SelectionQuery<R> setAliasSpecificLockMode(String alias, LockMode lockMode);
/**
* Specifies whether follow-on locking should be applied?
*/
SelectionQuery setFollowOnLocking(boolean enable);
SelectionQuery<R> setFollowOnLocking(boolean enable);
@Override
SelectionQuery setParameter(String name, Object value);
SelectionQuery<R> setParameter(String name, Object value);
@Override
<P> SelectionQuery setParameter(String name, P value, Class<P> type);
<P> SelectionQuery<R> setParameter(String name, P value, Class<P> type);
@Override
<P> SelectionQuery setParameter(String name, P value, BindableType<P> type);
<P> SelectionQuery<R> setParameter(String name, P value, BindableType<P> type);
@Override
SelectionQuery setParameter(String name, Instant value, TemporalType temporalType);
SelectionQuery<R> setParameter(String name, Instant value, TemporalType temporalType);
@Override
SelectionQuery setParameter(String name, Calendar value, TemporalType temporalType);
SelectionQuery<R> setParameter(String name, Calendar value, TemporalType temporalType);
@Override
SelectionQuery setParameter(String name, Date value, TemporalType temporalType);
SelectionQuery<R> setParameter(String name, Date value, TemporalType temporalType);
@Override
SelectionQuery setParameter(int position, Object value);
SelectionQuery<R> setParameter(int position, Object value);
@Override
<P> SelectionQuery setParameter(int position, P value, Class<P> type);
<P> SelectionQuery<R> setParameter(int position, P value, Class<P> type);
@Override
<P> SelectionQuery setParameter(int position, P value, BindableType<P> type);
<P> SelectionQuery<R> setParameter(int position, P value, BindableType<P> type);
@Override
SelectionQuery setParameter(int position, Instant value, TemporalType temporalType);
SelectionQuery<R> setParameter(int position, Instant value, TemporalType temporalType);
@Override
SelectionQuery setParameter(int position, Date value, TemporalType temporalType);
SelectionQuery<R> setParameter(int position, Date value, TemporalType temporalType);
@Override
SelectionQuery setParameter(int position, Calendar value, TemporalType temporalType);
SelectionQuery<R> setParameter(int position, Calendar value, TemporalType temporalType);
@Override
<T> SelectionQuery setParameter(QueryParameter<T> parameter, T value);
<T> SelectionQuery<R> setParameter(QueryParameter<T> parameter, T value);
@Override
<P> SelectionQuery setParameter(QueryParameter<P> parameter, P value, Class<P> type);
<P> SelectionQuery<R> setParameter(QueryParameter<P> parameter, P value, Class<P> type);
@Override
<P> SelectionQuery setParameter(QueryParameter<P> parameter, P val, BindableType<P> type);
<P> SelectionQuery<R> setParameter(QueryParameter<P> parameter, P val, BindableType<P> type);
@Override
<T> SelectionQuery setParameter(Parameter<T> param, T value);
<T> SelectionQuery<R> setParameter(Parameter<T> param, T value);
@Override
SelectionQuery setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType);
SelectionQuery<R> setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType);
@Override
SelectionQuery setParameter(Parameter<Date> param, Date value, TemporalType temporalType);
SelectionQuery<R> setParameter(Parameter<Date> param, Date value, TemporalType temporalType);
@Override
SelectionQuery setParameterList(String name, Collection values);
SelectionQuery<R> setParameterList(String name, Collection values);
@Override
<P> SelectionQuery setParameterList(String name, Collection<? extends P> values, Class<P> javaType);
<P> SelectionQuery<R> setParameterList(String name, Collection<? extends P> values, Class<P> javaType);
@Override
<P> SelectionQuery setParameterList(String name, Collection<? extends P> values, BindableType<P> type);
<P> SelectionQuery<R> setParameterList(String name, Collection<? extends P> values, BindableType<P> type);
@Override
SelectionQuery setParameterList(String name, Object[] values);
SelectionQuery<R> setParameterList(String name, Object[] values);
@Override
<P> SelectionQuery setParameterList(String name, P[] values, Class<P> javaType);
<P> SelectionQuery<R> setParameterList(String name, P[] values, Class<P> javaType);
@Override
<P> SelectionQuery setParameterList(String name, P[] values, BindableType<P> type);
<P> SelectionQuery<R> setParameterList(String name, P[] values, BindableType<P> type);
@Override
SelectionQuery setParameterList(int position, Collection values);
SelectionQuery<R> setParameterList(int position, Collection values);
@Override
<P> SelectionQuery setParameterList(int position, Collection<? extends P> values, Class<P> javaType);
<P> SelectionQuery<R> setParameterList(int position, Collection<? extends P> values, Class<P> javaType);
@Override
<P> SelectionQuery setParameterList(int position, Collection<? extends P> values, BindableType<P> type);
<P> SelectionQuery<R> setParameterList(int position, Collection<? extends P> values, BindableType<P> type);
@Override
SelectionQuery setParameterList(int position, Object[] values);
SelectionQuery<R> setParameterList(int position, Object[] values);
@Override
<P> SelectionQuery setParameterList(int position, P[] values, Class<P> javaType);
<P> SelectionQuery<R> setParameterList(int position, P[] values, Class<P> javaType);
@Override
<P> SelectionQuery setParameterList(int position, P[] values, BindableType<P> type);
<P> SelectionQuery<R> setParameterList(int position, P[] values, BindableType<P> type);
@Override
<P> SelectionQuery setParameterList(QueryParameter<P> parameter, Collection<? extends P> values);
<P> SelectionQuery<R> setParameterList(QueryParameter<P> parameter, Collection<? extends P> values);
@Override
<P> SelectionQuery setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType);
<P> SelectionQuery<R> setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType);
@Override
<P> SelectionQuery setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, BindableType<P> type);
<P> SelectionQuery<R> setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, BindableType<P> type);
@Override
<P> SelectionQuery setParameterList(QueryParameter<P> parameter, P[] values);
<P> SelectionQuery<R> setParameterList(QueryParameter<P> parameter, P[] values);
@Override
<P> SelectionQuery setParameterList(QueryParameter<P> parameter, P[] values, Class<P> javaType);
<P> SelectionQuery<R> setParameterList(QueryParameter<P> parameter, P[] values, Class<P> javaType);
@Override
<P> SelectionQuery setParameterList(QueryParameter<P> parameter, P[] values, BindableType<P> type);
<P> SelectionQuery<R> setParameterList(QueryParameter<P> parameter, P[] values, BindableType<P> type);
@Override
SelectionQuery setProperties(Object bean);
SelectionQuery<R> setProperties(Object bean);
@Override
SelectionQuery setProperties(@SuppressWarnings("rawtypes") Map bean);
SelectionQuery<R> setProperties(@SuppressWarnings("rawtypes") Map bean);
}

View File

@ -34,7 +34,6 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.EntityManagerMessageLogger;
import org.hibernate.internal.HEMLogging;
import org.hibernate.jpa.AvailableHints;
import org.hibernate.jpa.internal.util.ConfigurationHelper;
import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
import org.hibernate.jpa.internal.util.LockModeTypeHelper;
import org.hibernate.metamodel.model.domain.ManagedDomainType;
@ -77,8 +76,6 @@ import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_LOCK_TIMEOUT;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_QUERY_TIMEOUT;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_RETRIEVE_MODE;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_STORE_MODE;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_FETCH_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOAD_GRAPH;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOCK_SCOPE;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOCK_TIMEOUT;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT;
@ -87,7 +84,7 @@ import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT;
* @author Steve Ebersole
*/
public abstract class AbstractQuery<R>
extends AbstractSelectionQuery
extends AbstractSelectionQuery<R>
implements QueryImplementor<R> {
protected static final EntityManagerMessageLogger log = HEMLogging.messageLogger( AbstractQuery.class );

View File

@ -59,9 +59,9 @@ import static org.hibernate.jpa.QueryHints.HINT_READONLY;
/**
* @author Steve Ebersole
*/
public abstract class AbstractSelectionQuery
public abstract class AbstractSelectionQuery<R>
extends AbstractCommonQueryContract
implements SelectionQuery, DomainQueryExecutionContext {
implements SelectionQuery<R>, DomainQueryExecutionContext {
private Callback callback;
@ -115,11 +115,11 @@ public abstract class AbstractSelectionQuery
private CacheMode sessionCacheMode;
@Override
public List list() {
public List<R> list() {
beforeQuery();
boolean success = false;
try {
final List result = doList();
final List<R> result = doList();
success = true;
return result;
}
@ -180,19 +180,19 @@ public abstract class AbstractSelectionQuery
return lockMode != null && lockMode.greaterThan( LockMode.READ );
}
protected abstract List doList();
protected abstract List<R> doList();
@Override
public ScrollableResultsImplementor scroll() {
public ScrollableResultsImplementor<R> scroll() {
return scroll( getSession().getFactory().getJdbcServices().getJdbcEnvironment().getDialect().defaultScrollMode() );
}
@Override
public ScrollableResultsImplementor scroll(ScrollMode scrollMode) {
public ScrollableResultsImplementor<R> scroll(ScrollMode scrollMode) {
return doScroll( scrollMode );
}
protected abstract ScrollableResultsImplementor doScroll(ScrollMode scrollMode);
protected abstract ScrollableResultsImplementor<R> doScroll(ScrollMode scrollMode);
@SuppressWarnings( {"unchecked", "rawtypes"} )
@Override
@ -206,14 +206,14 @@ public abstract class AbstractSelectionQuery
}
@Override
public Object uniqueResult() {
public R uniqueResult() {
return uniqueElement( list() );
}
@Override
public Object getSingleResult() {
public R getSingleResult() {
try {
final List<?> list = list();
final List<R> list = list();
if ( list.isEmpty() ) {
throw new NoResultException( "No result found for query" );
}
@ -225,12 +225,12 @@ public abstract class AbstractSelectionQuery
}
@SuppressWarnings("WeakerAccess")
protected static Object uniqueElement(List<?> list) throws NonUniqueResultException {
protected static <T> T uniqueElement(List<T> list) throws NonUniqueResultException {
int size = list.size();
if ( size == 0 ) {
return null;
}
final Object first = list.get( 0 );
final T first = list.get( 0 );
// todo (6.0) : add a setting here to control whether to perform this validation or not
for ( int i = 1; i < size; i++ ) {
if ( list.get( i ) != first ) {
@ -240,9 +240,8 @@ public abstract class AbstractSelectionQuery
return first;
}
@SuppressWarnings("rawtypes")
@Override
public Optional uniqueResultOptional() {
public Optional<R> uniqueResultOptional() {
return Optional.ofNullable( uniqueResult() );
}
@ -279,13 +278,13 @@ public abstract class AbstractSelectionQuery
}
@Override
public SelectionQuery setFlushMode(FlushModeType flushMode) {
public SelectionQuery<R> setFlushMode(FlushModeType flushMode) {
getQueryOptions().setFlushMode( FlushMode.fromJpaFlushMode( flushMode ) );
return this;
}
@Override
public SelectionQuery setMaxResults(int maxResult) {
public SelectionQuery<R> setMaxResults(int maxResult) {
if ( maxResult < 0 ) {
throw new IllegalArgumentException( "max-results cannot be negative" );
}
@ -298,12 +297,12 @@ public abstract class AbstractSelectionQuery
}
@Override
public SelectionQuery setFirstResult(int startPosition) {
public SelectionQuery<R> setFirstResult(int startPosition) {
return null;
}
@Override
public SelectionQuery setHint(String hintName, Object value) {
public SelectionQuery<R> setHint(String hintName, Object value) {
super.setHint( hintName, value );
return this;
}
@ -319,7 +318,7 @@ public abstract class AbstractSelectionQuery
*
* @see #setHibernateLockMode
*/
public SelectionQuery setLockMode(LockModeType lockMode) {
public SelectionQuery<R> setLockMode(LockModeType lockMode) {
setHibernateLockMode( LockModeTypeHelper.getLockMode( lockMode ) );
return this;
}
@ -327,7 +326,7 @@ public abstract class AbstractSelectionQuery
/**
* Specify the root LockMode for the query
*/
public SelectionQuery setHibernateLockMode(LockMode lockMode) {
public SelectionQuery<R> setHibernateLockMode(LockMode lockMode) {
getLockOptions().setLockMode( lockMode );
return this;
}
@ -335,7 +334,7 @@ public abstract class AbstractSelectionQuery
/**
* Specify a LockMode to apply to a specific alias defined in the query
*/
public SelectionQuery setAliasSpecificLockMode(String alias, LockMode lockMode) {
public SelectionQuery<R> setAliasSpecificLockMode(String alias, LockMode lockMode) {
getLockOptions().setAliasSpecificLockMode( alias, lockMode );
return this;
}
@ -343,7 +342,7 @@ public abstract class AbstractSelectionQuery
/**
* Specifies whether follow-on locking should be applied?
*/
public SelectionQuery setFollowOnLocking(boolean enable) {
public SelectionQuery<R> setFollowOnLocking(boolean enable) {
getLockOptions().setFollowOnLocking( enable );
return this;
}
@ -385,7 +384,7 @@ public abstract class AbstractSelectionQuery
}
@Override
public SelectionQuery setFetchSize(int fetchSize) {
public SelectionQuery<R> setFetchSize(int fetchSize) {
getQueryOptions().setFetchSize( fetchSize );
return this;
}
@ -398,7 +397,7 @@ public abstract class AbstractSelectionQuery
}
@Override
public SelectionQuery setReadOnly(boolean readOnly) {
public SelectionQuery<R> setReadOnly(boolean readOnly) {
getQueryOptions().setReadOnly( readOnly );
return this;
}
@ -408,7 +407,7 @@ public abstract class AbstractSelectionQuery
}
@Override
public SelectionQuery setCacheMode(CacheMode cacheMode) {
public SelectionQuery<R> setCacheMode(CacheMode cacheMode) {
getQueryOptions().setCacheMode( cacheMode );
return this;
}
@ -419,7 +418,7 @@ public abstract class AbstractSelectionQuery
}
@Override
public SelectionQuery setCacheable(boolean cacheable) {
public SelectionQuery<R> setCacheable(boolean cacheable) {
getQueryOptions().setResultCachingEnabled( cacheable );
return this;
}
@ -430,7 +429,7 @@ public abstract class AbstractSelectionQuery
}
@Override
public SelectionQuery setCacheRegion(String regionName) {
public SelectionQuery<R> setCacheRegion(String regionName) {
getQueryOptions().setResultCacheRegionName( regionName );
return this;
}
@ -440,242 +439,242 @@ public abstract class AbstractSelectionQuery
// covariance
@Override
public SelectionQuery setHibernateFlushMode(FlushMode flushMode) {
public SelectionQuery<R> setHibernateFlushMode(FlushMode flushMode) {
super.setHibernateFlushMode( flushMode );
return this;
}
@Override
public SelectionQuery setTimeout(int timeout) {
public SelectionQuery<R> setTimeout(int timeout) {
super.setTimeout( timeout );
return this;
}
@Override
public SelectionQuery setParameter(String name, Object value) {
public SelectionQuery<R> setParameter(String name, Object value) {
super.setParameter( name, value );
return this;
}
@Override
public <P> SelectionQuery setParameter(String name, P value, Class<P> javaType) {
public <P> SelectionQuery<R> setParameter(String name, P value, Class<P> javaType) {
super.setParameter( name, value, javaType );
return this;
}
@Override
public <P> SelectionQuery setParameter(String name, P value, BindableType<P> type) {
public <P> SelectionQuery<R> setParameter(String name, P value, BindableType<P> type) {
super.setParameter( name, value, type );
return this;
}
@Override
public SelectionQuery setParameter(String name, Instant value, TemporalType temporalType) {
public SelectionQuery<R> setParameter(String name, Instant value, TemporalType temporalType) {
super.setParameter( name, value, temporalType );
return this;
}
@Override
public SelectionQuery setParameter(int position, Object value) {
public SelectionQuery<R> setParameter(int position, Object value) {
super.setParameter( position, value );
return this;
}
@Override
public <P> SelectionQuery setParameter(int position, P value, Class<P> javaType) {
public <P> SelectionQuery<R> setParameter(int position, P value, Class<P> javaType) {
super.setParameter( position, value, javaType );
return this;
}
@Override
public <P> SelectionQuery setParameter(int position, P value, BindableType<P> type) {
public <P> SelectionQuery<R> setParameter(int position, P value, BindableType<P> type) {
super.setParameter( position, value, type );
return this;
}
@Override
public SelectionQuery setParameter(int position, Instant value, TemporalType temporalType) {
public SelectionQuery<R> setParameter(int position, Instant value, TemporalType temporalType) {
super.setParameter( position, value, temporalType );
return this;
}
@Override
public <P> SelectionQuery setParameter(QueryParameter<P> parameter, P value) {
public <P> SelectionQuery<R> setParameter(QueryParameter<P> parameter, P value) {
super.setParameter( parameter, value );
return this;
}
@Override
public <P> SelectionQuery setParameter(QueryParameter<P> parameter, P value, Class<P> javaType) {
public <P> SelectionQuery<R> setParameter(QueryParameter<P> parameter, P value, Class<P> javaType) {
super.setParameter( parameter, value, javaType );
return this;
}
@Override
public <P> SelectionQuery setParameter(QueryParameter<P> parameter, P value, BindableType<P> type) {
public <P> SelectionQuery<R> setParameter(QueryParameter<P> parameter, P value, BindableType<P> type) {
super.setParameter( parameter, value, type );
return this;
}
@Override
public <P> SelectionQuery setParameter(Parameter<P> parameter, P value) {
public <P> SelectionQuery<R> setParameter(Parameter<P> parameter, P value) {
super.setParameter( parameter, value );
return this;
}
@Override
public SelectionQuery setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) {
public SelectionQuery<R> setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) {
super.setParameter( param, value, temporalType );
return this;
}
@Override
public SelectionQuery setParameter(Parameter<Date> param, Date value, TemporalType temporalType) {
public SelectionQuery<R> setParameter(Parameter<Date> param, Date value, TemporalType temporalType) {
super.setParameter( param, value, temporalType );
return this;
}
@Override
public SelectionQuery setParameter(String name, Calendar value, TemporalType temporalType) {
public SelectionQuery<R> setParameter(String name, Calendar value, TemporalType temporalType) {
super.setParameter( name, value, temporalType );
return this;
}
@Override
public SelectionQuery setParameter(String name, Date value, TemporalType temporalType) {
public SelectionQuery<R> setParameter(String name, Date value, TemporalType temporalType) {
super.setParameter( name, value, temporalType );
return this;
}
@Override
public SelectionQuery setParameter(int position, Calendar value, TemporalType temporalType) {
public SelectionQuery<R> setParameter(int position, Calendar value, TemporalType temporalType) {
super.setParameter( position, value, temporalType );
return this;
}
@Override
public SelectionQuery setParameter(int position, Date value, TemporalType temporalType) {
public SelectionQuery<R> setParameter(int position, Date value, TemporalType temporalType) {
super.setParameter( position, value, temporalType );
return this;
}
@Override
public SelectionQuery setParameterList(String name, Collection values) {
public SelectionQuery<R> setParameterList(String name, Collection values) {
super.setParameterList( name, values );
return this;
}
@Override
public <P> SelectionQuery setParameterList(String name, Collection<? extends P> values, Class<P> javaType) {
public <P> SelectionQuery<R> setParameterList(String name, Collection<? extends P> values, Class<P> javaType) {
super.setParameterList( name, values, javaType );
return this;
}
@Override
public <P> SelectionQuery setParameterList(String name, Collection<? extends P> values, BindableType<P> type) {
public <P> SelectionQuery<R> setParameterList(String name, Collection<? extends P> values, BindableType<P> type) {
super.setParameterList( name, values, type );
return this;
}
@Override
public SelectionQuery setParameterList(String name, Object[] values) {
public SelectionQuery<R> setParameterList(String name, Object[] values) {
super.setParameterList( name, values );
return this;
}
@Override
public <P> SelectionQuery setParameterList(String name, P[] values, Class<P> javaType) {
public <P> SelectionQuery<R> setParameterList(String name, P[] values, Class<P> javaType) {
super.setParameterList( name, values, javaType );
return this;
}
@Override
public <P> SelectionQuery setParameterList(String name, P[] values, BindableType<P> type) {
public <P> SelectionQuery<R> setParameterList(String name, P[] values, BindableType<P> type) {
super.setParameterList( name, values, type );
return this;
}
@Override
public SelectionQuery setParameterList(int position, Collection values) {
public SelectionQuery<R> setParameterList(int position, Collection values) {
super.setParameterList( position, values );
return this;
}
@Override
public <P> SelectionQuery setParameterList(int position, Collection<? extends P> values, Class<P> javaType) {
public <P> SelectionQuery<R> setParameterList(int position, Collection<? extends P> values, Class<P> javaType) {
super.setParameterList( position, values, javaType );
return this;
}
@Override
public <P> SelectionQuery setParameterList(int position, Collection<? extends P> values, BindableType<P> type) {
public <P> SelectionQuery<R> setParameterList(int position, Collection<? extends P> values, BindableType<P> type) {
super.setParameterList( position, values, type );
return this;
}
@Override
public SelectionQuery setParameterList(int position, Object[] values) {
public SelectionQuery<R> setParameterList(int position, Object[] values) {
super.setParameterList( position, values );
return this;
}
@Override
public <P> SelectionQuery setParameterList(int position, P[] values, Class<P> javaType) {
public <P> SelectionQuery<R> setParameterList(int position, P[] values, Class<P> javaType) {
super.setParameterList( position, values, javaType );
return this;
}
@Override
public <P> SelectionQuery setParameterList(int position, P[] values, BindableType<P> type) {
public <P> SelectionQuery<R> setParameterList(int position, P[] values, BindableType<P> type) {
super.setParameterList( position, values, type );
return this;
}
@Override
public <P> SelectionQuery setParameterList(QueryParameter<P> parameter, Collection<? extends P> values) {
public <P> SelectionQuery<R> setParameterList(QueryParameter<P> parameter, Collection<? extends P> values) {
super.setParameterList( parameter, values );
return this;
}
@Override
public <P> SelectionQuery setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType) {
public <P> SelectionQuery<R> setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType) {
super.setParameterList( parameter, values, javaType );
return this;
}
@Override
public <P> SelectionQuery setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, BindableType<P> type) {
public <P> SelectionQuery<R> setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, BindableType<P> type) {
super.setParameterList( parameter, values, type );
return this;
}
@Override
public <P> SelectionQuery setParameterList(QueryParameter<P> parameter, P[] values) {
public <P> SelectionQuery<R> setParameterList(QueryParameter<P> parameter, P[] values) {
super.setParameterList( parameter, values );
return this;
}
@Override
public <P> SelectionQuery setParameterList(QueryParameter<P> parameter, P[] values, Class<P> javaType) {
public <P> SelectionQuery<R> setParameterList(QueryParameter<P> parameter, P[] values, Class<P> javaType) {
super.setParameterList( parameter, values, javaType );
return this;
}
@Override
public <P> SelectionQuery setParameterList(QueryParameter<P> parameter, P[] values, BindableType<P> type) {
public <P> SelectionQuery<R> setParameterList(QueryParameter<P> parameter, P[] values, BindableType<P> type) {
super.setParameterList( parameter, values, type );
return this;
}
@Override
public SelectionQuery setProperties(Map map) {
public SelectionQuery<R> setProperties(Map map) {
super.setProperties( map );
return this;
}
@Override
public SelectionQuery setProperties(Object bean) {
public SelectionQuery<R> setProperties(Object bean) {
super.setProperties( bean );
return this;
}

View File

@ -40,7 +40,6 @@ import org.hibernate.internal.AbstractSharedSessionContract;
import org.hibernate.internal.util.MathHelper;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.jpa.internal.util.LockModeTypeHelper;
import org.hibernate.jpa.spi.NativeQueryTupleTransformer;
import org.hibernate.metamodel.model.domain.BasicDomainType;
import org.hibernate.query.BindableType;
@ -101,7 +100,6 @@ import jakarta.persistence.Tuple;
import jakarta.persistence.metamodel.SingularAttribute;
import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_LOCK_MODE;
import static org.hibernate.jpa.QueryHints.HINT_NATIVE_SPACES;
/**
* @author Steve Ebersole

View File

@ -25,140 +25,140 @@ import jakarta.persistence.TemporalType;
/**
* @author Steve Ebersole
*/
public interface SqmSelectionQuery extends SqmQuery, SelectionQuery {
public interface SqmSelectionQuery<R> extends SqmQuery, SelectionQuery<R> {
@Override
SqmSelectionQuery setParameter(String name, Object value);
SqmSelectionQuery<R> setParameter(String name, Object value);
@Override
<P> SqmSelectionQuery setParameter(String name, P value, Class<P> type);
<P> SqmSelectionQuery<R> setParameter(String name, P value, Class<P> type);
@Override
<P> SqmSelectionQuery setParameter(String name, P value, BindableType<P> type);
<P> SqmSelectionQuery<R> setParameter(String name, P value, BindableType<P> type);
@Override
SqmSelectionQuery setParameter(String name, Instant value, TemporalType temporalType);
SqmSelectionQuery<R> setParameter(String name, Instant value, TemporalType temporalType);
@Override
SqmSelectionQuery setParameter(String name, Calendar value, TemporalType temporalType);
SqmSelectionQuery<R> setParameter(String name, Calendar value, TemporalType temporalType);
@Override
SqmSelectionQuery setParameter(String name, Date value, TemporalType temporalType);
SqmSelectionQuery<R> setParameter(String name, Date value, TemporalType temporalType);
@Override
SqmSelectionQuery setParameter(int position, Object value);
SqmSelectionQuery<R> setParameter(int position, Object value);
@Override
<P> SqmSelectionQuery setParameter(int position, P value, Class<P> type);
<P> SqmSelectionQuery<R> setParameter(int position, P value, Class<P> type);
@Override
<P> SqmSelectionQuery setParameter(int position, P value, BindableType<P> type);
<P> SqmSelectionQuery<R> setParameter(int position, P value, BindableType<P> type);
@Override
SqmSelectionQuery setParameter(int position, Instant value, TemporalType temporalType);
SqmSelectionQuery<R> setParameter(int position, Instant value, TemporalType temporalType);
@Override
SqmSelectionQuery setParameter(int position, Date value, TemporalType temporalType);
SqmSelectionQuery<R> setParameter(int position, Date value, TemporalType temporalType);
@Override
SqmSelectionQuery setParameter(int position, Calendar value, TemporalType temporalType);
SqmSelectionQuery<R> setParameter(int position, Calendar value, TemporalType temporalType);
@Override
<T> SqmSelectionQuery setParameter(QueryParameter<T> parameter, T value);
<T> SqmSelectionQuery<R> setParameter(QueryParameter<T> parameter, T value);
@Override
<P> SqmSelectionQuery setParameter(QueryParameter<P> parameter, P value, Class<P> type);
<P> SqmSelectionQuery<R> setParameter(QueryParameter<P> parameter, P value, Class<P> type);
@Override
<P> SqmSelectionQuery setParameter(QueryParameter<P> parameter, P val, BindableType<P> type);
<P> SqmSelectionQuery<R> setParameter(QueryParameter<P> parameter, P val, BindableType<P> type);
@Override
<T> SqmSelectionQuery setParameter(Parameter<T> param, T value);
<T> SqmSelectionQuery<R> setParameter(Parameter<T> param, T value);
@Override
SqmSelectionQuery setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType);
SqmSelectionQuery<R> setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType);
@Override
SqmSelectionQuery setParameter(Parameter<Date> param, Date value, TemporalType temporalType);
SqmSelectionQuery<R> setParameter(Parameter<Date> param, Date value, TemporalType temporalType);
@Override
SqmSelectionQuery setParameterList(String name, Collection values);
SqmSelectionQuery<R> setParameterList(String name, Collection values);
@Override
<P> SqmSelectionQuery setParameterList(String name, Collection<? extends P> values, Class<P> javaType);
<P> SqmSelectionQuery<R> setParameterList(String name, Collection<? extends P> values, Class<P> javaType);
@Override
<P> SqmSelectionQuery setParameterList(String name, Collection<? extends P> values, BindableType<P> type);
<P> SqmSelectionQuery<R> setParameterList(String name, Collection<? extends P> values, BindableType<P> type);
@Override
SqmSelectionQuery setParameterList(String name, Object[] values);
SqmSelectionQuery<R> setParameterList(String name, Object[] values);
@Override
<P> SqmSelectionQuery setParameterList(String name, P[] values, Class<P> javaType);
<P> SqmSelectionQuery<R> setParameterList(String name, P[] values, Class<P> javaType);
@Override
<P> SqmSelectionQuery setParameterList(String name, P[] values, BindableType<P> type);
<P> SqmSelectionQuery<R> setParameterList(String name, P[] values, BindableType<P> type);
@Override
SqmSelectionQuery setParameterList(int position, Collection values);
SqmSelectionQuery<R> setParameterList(int position, Collection values);
@Override
<P> SqmSelectionQuery setParameterList(int position, Collection<? extends P> values, Class<P> javaType);
<P> SqmSelectionQuery<R> setParameterList(int position, Collection<? extends P> values, Class<P> javaType);
@Override
<P> SqmSelectionQuery setParameterList(int position, Collection<? extends P> values, BindableType<P> type);
<P> SqmSelectionQuery<R> setParameterList(int position, Collection<? extends P> values, BindableType<P> type);
@Override
SqmSelectionQuery setParameterList(int position, Object[] values);
SqmSelectionQuery<R> setParameterList(int position, Object[] values);
@Override
<P> SqmSelectionQuery setParameterList(int position, P[] values, Class<P> javaType);
<P> SqmSelectionQuery<R> setParameterList(int position, P[] values, Class<P> javaType);
@Override
<P> SqmSelectionQuery setParameterList(int position, P[] values, BindableType<P> type);
<P> SqmSelectionQuery<R> setParameterList(int position, P[] values, BindableType<P> type);
@Override
<P> SqmSelectionQuery setParameterList(QueryParameter<P> parameter, Collection<? extends P> values);
<P> SqmSelectionQuery<R> setParameterList(QueryParameter<P> parameter, Collection<? extends P> values);
@Override
<P> SqmSelectionQuery setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType);
<P> SqmSelectionQuery<R> setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType);
@Override
<P> SqmSelectionQuery setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, BindableType<P> type);
<P> SqmSelectionQuery<R> setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, BindableType<P> type);
@Override
<P> SqmSelectionQuery setParameterList(QueryParameter<P> parameter, P[] values);
<P> SqmSelectionQuery<R> setParameterList(QueryParameter<P> parameter, P[] values);
@Override
<P> SqmSelectionQuery setParameterList(QueryParameter<P> parameter, P[] values, Class<P> javaType);
<P> SqmSelectionQuery<R> setParameterList(QueryParameter<P> parameter, P[] values, Class<P> javaType);
@Override
<P> SqmSelectionQuery setParameterList(QueryParameter<P> parameter, P[] values, BindableType<P> type);
<P> SqmSelectionQuery<R> setParameterList(QueryParameter<P> parameter, P[] values, BindableType<P> type);
@Override
SqmSelectionQuery setProperties(Object bean);
SqmSelectionQuery<R> setProperties(Object bean);
@Override
SqmSelectionQuery setProperties(Map bean);
SqmSelectionQuery<R> setProperties(Map bean);
@Override
SqmSelectionQuery setHibernateFlushMode(FlushMode flushMode);
SqmSelectionQuery<R> setHibernateFlushMode(FlushMode flushMode);
@Override
SqmSelectionQuery setCacheMode(CacheMode cacheMode);
SqmSelectionQuery<R> setCacheMode(CacheMode cacheMode);
@Override
SqmSelectionQuery setCacheable(boolean cacheable);
SqmSelectionQuery<R> setCacheable(boolean cacheable);
@Override
SqmSelectionQuery setCacheRegion(String cacheRegion);
SqmSelectionQuery<R> setCacheRegion(String cacheRegion);
@Override
SqmSelectionQuery setTimeout(int timeout);
SqmSelectionQuery<R> setTimeout(int timeout);
@Override
SqmSelectionQuery setFetchSize(int fetchSize);
SqmSelectionQuery<R> setFetchSize(int fetchSize);
@Override
SqmSelectionQuery setReadOnly(boolean readOnly);
SqmSelectionQuery<R> setReadOnly(boolean readOnly);
}

View File

@ -107,16 +107,16 @@ import jakarta.persistence.PersistenceException;
import jakarta.persistence.TemporalType;
import jakarta.persistence.Tuple;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_SHARED_CACHE_RETRIEVE_MODE;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_SHARED_CACHE_STORE_MODE;
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE;
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_STORE_MODE;
import static org.hibernate.jpa.QueryHints.HINT_CACHEABLE;
import static org.hibernate.jpa.QueryHints.HINT_CACHE_MODE;
import static org.hibernate.jpa.QueryHints.HINT_CACHE_REGION;
import static org.hibernate.jpa.QueryHints.HINT_FETCH_SIZE;
import static org.hibernate.jpa.QueryHints.HINT_FOLLOW_ON_LOCKING;
import static org.hibernate.jpa.QueryHints.HINT_READONLY;
import static org.hibernate.jpa.HibernateHints.HINT_CACHEABLE;
import static org.hibernate.jpa.HibernateHints.HINT_CACHE_MODE;
import static org.hibernate.jpa.HibernateHints.HINT_CACHE_REGION;
import static org.hibernate.jpa.HibernateHints.HINT_FETCH_SIZE;
import static org.hibernate.jpa.HibernateHints.HINT_FOLLOW_ON_LOCKING;
import static org.hibernate.jpa.HibernateHints.HINT_READ_ONLY;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_CACHE_RETRIEVE_MODE;
import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_CACHE_STORE_MODE;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_RETRIEVE_MODE;
import static org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_STORE_MODE;
import static org.hibernate.query.spi.SqlOmittingQueryOptions.omitSqlQueryOptions;
import static org.hibernate.query.sqm.internal.SqmUtil.isSelect;
@ -126,7 +126,7 @@ import static org.hibernate.query.sqm.internal.SqmUtil.isSelect;
* @author Steve Ebersole
*/
public class QuerySqmImpl<R>
extends AbstractSelectionQuery
extends AbstractSelectionQuery<R>
implements SqmQueryImplementor<R>, InterpretationsKeySource, DomainQueryExecutionContext {
/**
@ -603,7 +603,7 @@ public class QuerySqmImpl<R>
}
}
protected List doList() {
protected List<R> doList() {
verifySelect();
getSession().prepareForQueryExecution( requiresTxn( getQueryOptions().getLockOptions().findGreatestLockMode() ) );
@ -645,7 +645,7 @@ public class QuerySqmImpl<R>
executionContextToUse = this;
}
final List<?> list = resolveSelectQueryPlan().performList( executionContextToUse );
final List<R> list = resolveSelectQueryPlan().performList( executionContextToUse );
if ( needsDistinct ) {
int includedCount = -1;
@ -656,9 +656,9 @@ public class QuerySqmImpl<R>
final int max = !hasLimit || getQueryOptions().getLimit().getMaxRows() == null
? getMaxRows( sqmStatement, list.size() )
: getQueryOptions().getLimit().getMaxRows();
final List<Object> tmp = new ArrayList<>( list.size() );
final List<R> tmp = new ArrayList<>( list.size() );
final IdentitySet<Object> distinction = new IdentitySet<>( list.size() );
for ( final Object result : list ) {
for ( final R result : list ) {
if ( !distinction.add( result ) ) {
continue;
}
@ -687,7 +687,7 @@ public class QuerySqmImpl<R>
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Select query plan
private SelectQueryPlan<?> resolveSelectQueryPlan() {
private SelectQueryPlan<R> resolveSelectQueryPlan() {
final QueryInterpretationCache.Key cacheKey = SqmInterpretationsKey.createInterpretationsKey( this );
if ( cacheKey != null ) {
return getSession().getFactory().getQueryEngine().getInterpretationCache().resolveSelectQueryPlan(
@ -700,9 +700,9 @@ public class QuerySqmImpl<R>
}
}
private SelectQueryPlan<?> buildSelectQueryPlan() {
final SqmSelectStatement<?>[] concreteSqmStatements = QuerySplitter.split(
(SqmSelectStatement<?>) getSqmStatement(),
private SelectQueryPlan<R> buildSelectQueryPlan() {
final SqmSelectStatement<R>[] concreteSqmStatements = QuerySplitter.split(
(SqmSelectStatement<R>) getSqmStatement(),
getSession().getFactory()
);
@ -714,8 +714,9 @@ public class QuerySqmImpl<R>
}
}
private SelectQueryPlan<?> buildAggregatedSelectQueryPlan(SqmSelectStatement<?>[] concreteSqmStatements) {
final SelectQueryPlan<?>[] aggregatedQueryPlans = new SelectQueryPlan[ concreteSqmStatements.length ];
private SelectQueryPlan<R> buildAggregatedSelectQueryPlan(SqmSelectStatement<?>[] concreteSqmStatements) {
//noinspection unchecked
final SelectQueryPlan<R>[] aggregatedQueryPlans = new SelectQueryPlan[ concreteSqmStatements.length ];
// todo (6.0) : we want to make sure that certain thing (ResultListTransformer, etc) only get applied at the aggregator-level
@ -727,12 +728,12 @@ public class QuerySqmImpl<R>
);
}
return new AggregatedSelectQueryPlanImpl( aggregatedQueryPlans );
return new AggregatedSelectQueryPlanImpl<>( aggregatedQueryPlans );
}
private <R> SelectQueryPlan<R> buildConcreteSelectQueryPlan(
private <T> SelectQueryPlan<T> buildConcreteSelectQueryPlan(
SqmSelectStatement<?> concreteSqmStatement,
Class<R> resultType,
Class<T> resultType,
QueryOptions queryOptions) {
return new ConcreteSqmSelectQueryPlan<>(
concreteSqmStatement,
@ -1000,7 +1001,7 @@ public class QuerySqmImpl<R>
super.collectHints( hints );
if ( isReadOnly() ) {
hints.put( HINT_READONLY, true );
hints.put( HINT_READ_ONLY, true );
}
putIfNotNull( hints, HINT_FETCH_SIZE, getFetchSize() );
@ -1008,14 +1009,12 @@ public class QuerySqmImpl<R>
if ( isCacheable() ) {
hints.put( HINT_CACHEABLE, true );
putIfNotNull( hints, HINT_CACHE_REGION, getCacheRegion() );
putIfNotNull( hints, HINT_CACHE_MODE, getCacheMode() );
putIfNotNull( hints, JAKARTA_SHARED_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
putIfNotNull( hints, JAKARTA_SHARED_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
//noinspection deprecation
putIfNotNull( hints, JPA_SHARED_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
//noinspection deprecation
putIfNotNull( hints, JPA_SHARED_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
putIfNotNull( hints, HINT_SPEC_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
putIfNotNull( hints, HINT_SPEC_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
putIfNotNull( hints, HINT_JAVAEE_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
putIfNotNull( hints, HINT_JAVAEE_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
}
final AppliedGraph appliedGraph = getQueryOptions().getAppliedGraph();

View File

@ -47,6 +47,7 @@ import org.hibernate.query.spi.SelectQueryPlan;
import org.hibernate.query.sqm.SqmSelectionQuery;
import org.hibernate.query.sqm.internal.SqmInterpretationsKey.InterpretationsKeySource;
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
import org.hibernate.query.sqm.tree.select.SqmSelection;
import jakarta.persistence.FlushModeType;
import jakarta.persistence.LockModeType;
@ -68,7 +69,7 @@ import static org.hibernate.query.spi.SqlOmittingQueryOptions.omitSqlQueryOption
/**
* @author Steve Ebersole
*/
public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSelectionQuery, InterpretationsKeySource {
public class SqmSelectionQueryImpl<R> extends AbstractSelectionQuery<R> implements SqmSelectionQuery<R>, InterpretationsKeySource {
private final String hql;
private final SqmSelectStatement<?> sqm;
@ -76,9 +77,9 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
private final DomainParameterXref domainParameterXref;
private final QueryParameterBindingsImpl parameterBindings;
private final Class<?> resultType;
private final Class<R> resultType;
public SqmSelectQueryImpl(
public SqmSelectionQueryImpl(
String hql,
HqlInterpretation hqlInterpretation,
SharedSessionContractImplementor session) {
@ -91,13 +92,23 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, session.getFactory() );
this.resultType = sqm.getQuerySpec().getSelectClause().getSelections().size() > 1
? Object[].class
: Object.class;
this.resultType = determineResultType( sqm );
setComment( hql );
}
private static <T> Class<T> determineResultType(SqmSelectStatement<?> sqm) {
final List<SqmSelection<?>> selections = sqm.getQuerySpec().getSelectClause().getSelections();
if ( selections.size() == 1 ) {
final SqmSelection<?> sqmSelection = selections.get( 0 );
//noinspection unchecked
return (Class<T>) sqmSelection.getNodeJavaType().getJavaTypeClass();
}
//noinspection unchecked
return (Class<T>) Object[].class;
}
@SuppressWarnings("rawtypes")
public SqmSelectStatement getSqmStatement() {
return sqm;
@ -136,7 +147,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
resetCallback();
}
protected List doList() {
protected List<R> doList() {
getSession().prepareForQueryExecution( requiresTxn( getQueryOptions().getLockOptions().findGreatestLockMode() ) );
final SqmSelectStatement<?> sqmStatement = (SqmSelectStatement<?>) getSqmStatement();
@ -177,7 +188,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
executionContextToUse = this;
}
final List<?> list = resolveQueryPlan().performList( executionContextToUse );
final List<R> list = resolveQueryPlan().performList( executionContextToUse );
if ( needsDistinct ) {
int includedCount = -1;
@ -188,9 +199,9 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
final int max = !hasLimit || getQueryOptions().getLimit().getMaxRows() == null
? getMaxRows( sqmStatement, list.size() )
: getQueryOptions().getLimit().getMaxRows();
final List<Object> tmp = new ArrayList<>( list.size() );
final List<R> tmp = new ArrayList<>( list.size() );
final IdentitySet<Object> distinction = new IdentitySet<>( list.size() );
for ( final Object result : list ) {
for ( final R result : list ) {
if ( !distinction.add( result ) ) {
continue;
}
@ -210,7 +221,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
}
@Override
protected ScrollableResultsImplementor doScroll(ScrollMode scrollMode) {
protected ScrollableResultsImplementor<R> doScroll(ScrollMode scrollMode) {
getSession().prepareForQueryExecution( requiresTxn( getQueryOptions().getLockOptions().findGreatestLockMode() ) );
return resolveQueryPlan().performScroll( scrollMode, this );
@ -220,7 +231,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Query plan
private SelectQueryPlan<?> resolveQueryPlan() {
private SelectQueryPlan<R> resolveQueryPlan() {
final QueryInterpretationCache.Key cacheKey = SqmInterpretationsKey.createInterpretationsKey( this );
if ( cacheKey != null ) {
return getSession().getFactory().getQueryEngine().getInterpretationCache().resolveSelectQueryPlan(
@ -233,7 +244,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
}
}
private SelectQueryPlan<?> buildQueryPlan() {
private SelectQueryPlan<R> buildQueryPlan() {
final SqmSelectStatement<?>[] concreteSqmStatements = QuerySplitter.split(
(SqmSelectStatement<?>) getSqmStatement(),
getSession().getFactory()
@ -247,8 +258,9 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
}
}
private SelectQueryPlan<?> buildAggregatedQueryPlan(SqmSelectStatement<?>[] concreteSqmStatements) {
final SelectQueryPlan<?>[] aggregatedQueryPlans = new SelectQueryPlan[ concreteSqmStatements.length ];
private SelectQueryPlan<R> buildAggregatedQueryPlan(SqmSelectStatement<?>[] concreteSqmStatements) {
//noinspection unchecked
final SelectQueryPlan<R>[] aggregatedQueryPlans = new SelectQueryPlan[ concreteSqmStatements.length ];
// todo (6.0) : we want to make sure that certain thing (ResultListTransformer, etc) only get applied at the aggregator-level
@ -260,12 +272,12 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
);
}
return new AggregatedSelectQueryPlanImpl( aggregatedQueryPlans );
return new AggregatedSelectQueryPlanImpl<>( aggregatedQueryPlans );
}
private <R> SelectQueryPlan<R> buildConcreteQueryPlan(
private <T> SelectQueryPlan<T> buildConcreteQueryPlan(
SqmSelectStatement<?> concreteSqmStatement,
Class<R> resultType,
Class<T> resultType,
QueryOptions queryOptions) {
return new ConcreteSqmSelectQueryPlan<>(
concreteSqmStatement,
@ -282,7 +294,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
// InterpretationsKeySource
@Override
public Class<?> getResultType() {
public Class<R> getResultType() {
return resultType;
}
@ -317,7 +329,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
}
@Override
public SqmSelectionQuery setFlushMode(FlushModeType flushMode) {
public SqmSelectionQuery<R> setFlushMode(FlushModeType flushMode) {
setHibernateFlushMode( FlushModeTypeHelper.getFlushMode( flushMode ) );
return this;
}
@ -333,7 +345,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
* @see #setHibernateLockMode
*/
@Override
public SqmSelectionQuery setLockMode(LockModeType lockMode) {
public SqmSelectionQuery<R> setLockMode(LockModeType lockMode) {
setHibernateLockMode( LockModeTypeHelper.getLockMode( lockMode ) );
return this;
}
@ -342,7 +354,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
* Specify the root LockMode for the query
*/
@Override
public SqmSelectionQuery setHibernateLockMode(LockMode lockMode) {
public SqmSelectionQuery<R> setHibernateLockMode(LockMode lockMode) {
getLockOptions().setLockMode( lockMode );
return this;
}
@ -351,7 +363,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
* Specify a LockMode to apply to a specific alias defined in the query
*/
@Override
public SqmSelectionQuery setAliasSpecificLockMode(String alias, LockMode lockMode) {
public SqmSelectionQuery<R> setAliasSpecificLockMode(String alias, LockMode lockMode) {
getLockOptions().setAliasSpecificLockMode( alias, lockMode );
return this;
}
@ -360,7 +372,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
* Specifies whether follow-on locking should be applied?
*/
@Override
public SqmSelectionQuery setFollowOnLocking(boolean enable) {
public SqmSelectionQuery<R> setFollowOnLocking(boolean enable) {
getLockOptions().setFollowOnLocking( enable );
return this;
}
@ -371,7 +383,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
}
@Override
public SqmSelectionQuery setFetchSize(int fetchSize) {
public SqmSelectionQuery<R> setFetchSize(int fetchSize) {
getQueryOptions().setFetchSize( fetchSize );
return this;
}
@ -384,7 +396,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
}
@Override
public SqmSelectionQuery setReadOnly(boolean readOnly) {
public SqmSelectionQuery<R> setReadOnly(boolean readOnly) {
getQueryOptions().setReadOnly( readOnly );
return this;
}
@ -394,7 +406,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
}
@Override
public SqmSelectionQuery setCacheMode(CacheMode cacheMode) {
public SqmSelectionQuery<R> setCacheMode(CacheMode cacheMode) {
getQueryOptions().setCacheMode( cacheMode );
return this;
}
@ -405,7 +417,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
}
@Override
public SqmSelectionQuery setCacheable(boolean cacheable) {
public SqmSelectionQuery<R> setCacheable(boolean cacheable) {
getQueryOptions().setResultCachingEnabled( cacheable );
return this;
}
@ -416,7 +428,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
}
@Override
public SqmSelectionQuery setCacheRegion(String regionName) {
public SqmSelectionQuery<R> setCacheRegion(String regionName) {
getQueryOptions().setResultCacheRegionName( regionName );
return this;
}
@ -461,242 +473,242 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel
// covariance
@Override
public SqmSelectionQuery setHibernateFlushMode(FlushMode flushMode) {
public SqmSelectionQuery<R> setHibernateFlushMode(FlushMode flushMode) {
super.setHibernateFlushMode( flushMode );
return this;
}
@Override
public SqmSelectionQuery setTimeout(int timeout) {
public SqmSelectionQuery<R> setTimeout(int timeout) {
super.setTimeout( timeout );
return this;
}
@Override
public SqmSelectionQuery setParameter(String name, Object value) {
public SqmSelectionQuery<R> setParameter(String name, Object value) {
super.setParameter( name, value );
return this;
}
@Override
public <P> SqmSelectionQuery setParameter(String name, P value, Class<P> javaType) {
public <P> SqmSelectionQuery<R> setParameter(String name, P value, Class<P> javaType) {
super.setParameter( name, value, javaType );
return this;
}
@Override
public <P> SqmSelectionQuery setParameter(String name, P value, BindableType<P> type) {
public <P> SqmSelectionQuery<R> setParameter(String name, P value, BindableType<P> type) {
super.setParameter( name, value, type );
return this;
}
@Override
public SqmSelectionQuery setParameter(String name, Instant value, TemporalType temporalType) {
public SqmSelectionQuery<R> setParameter(String name, Instant value, TemporalType temporalType) {
super.setParameter( name, value, temporalType );
return this;
}
@Override
public SqmSelectionQuery setParameter(int position, Object value) {
public SqmSelectionQuery<R> setParameter(int position, Object value) {
super.setParameter( position, value );
return this;
}
@Override
public <P> SqmSelectionQuery setParameter(int position, P value, Class<P> javaType) {
public <P> SqmSelectionQuery<R> setParameter(int position, P value, Class<P> javaType) {
super.setParameter( position, value, javaType );
return this;
}
@Override
public <P> SqmSelectionQuery setParameter(int position, P value, BindableType<P> type) {
public <P> SqmSelectionQuery<R> setParameter(int position, P value, BindableType<P> type) {
super.setParameter( position, value, type );
return this;
}
@Override
public SqmSelectionQuery setParameter(int position, Instant value, TemporalType temporalType) {
public SqmSelectionQuery<R> setParameter(int position, Instant value, TemporalType temporalType) {
super.setParameter( position, value, temporalType );
return this;
}
@Override
public <P> SqmSelectionQuery setParameter(QueryParameter<P> parameter, P value) {
public <P> SqmSelectionQuery<R> setParameter(QueryParameter<P> parameter, P value) {
super.setParameter( parameter, value );
return this;
}
@Override
public <P> SqmSelectionQuery setParameter(QueryParameter<P> parameter, P value, Class<P> javaType) {
public <P> SqmSelectionQuery<R> setParameter(QueryParameter<P> parameter, P value, Class<P> javaType) {
super.setParameter( parameter, value, javaType );
return this;
}
@Override
public <P> SqmSelectionQuery setParameter(QueryParameter<P> parameter, P value, BindableType<P> type) {
public <P> SqmSelectionQuery<R> setParameter(QueryParameter<P> parameter, P value, BindableType<P> type) {
super.setParameter( parameter, value, type );
return this;
}
@Override
public <P> SqmSelectionQuery setParameter(Parameter<P> parameter, P value) {
public <P> SqmSelectionQuery<R> setParameter(Parameter<P> parameter, P value) {
super.setParameter( parameter, value );
return this;
}
@Override
public SqmSelectionQuery setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) {
public SqmSelectionQuery<R> setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) {
super.setParameter( param, value, temporalType );
return this;
}
@Override
public SqmSelectionQuery setParameter(Parameter<Date> param, Date value, TemporalType temporalType) {
public SqmSelectionQuery<R> setParameter(Parameter<Date> param, Date value, TemporalType temporalType) {
super.setParameter( param, value, temporalType );
return this;
}
@Override
public SqmSelectionQuery setParameter(String name, Calendar value, TemporalType temporalType) {
public SqmSelectionQuery<R> setParameter(String name, Calendar value, TemporalType temporalType) {
super.setParameter( name, value, temporalType );
return this;
}
@Override
public SqmSelectionQuery setParameter(String name, Date value, TemporalType temporalType) {
public SqmSelectionQuery<R> setParameter(String name, Date value, TemporalType temporalType) {
super.setParameter( name, value, temporalType );
return this;
}
@Override
public SqmSelectionQuery setParameter(int position, Calendar value, TemporalType temporalType) {
public SqmSelectionQuery<R> setParameter(int position, Calendar value, TemporalType temporalType) {
super.setParameter( position, value, temporalType );
return this;
}
@Override
public SqmSelectionQuery setParameter(int position, Date value, TemporalType temporalType) {
public SqmSelectionQuery<R> setParameter(int position, Date value, TemporalType temporalType) {
super.setParameter( position, value, temporalType );
return this;
}
@Override
public SqmSelectionQuery setParameterList(String name, Collection values) {
public SqmSelectionQuery<R> setParameterList(String name, Collection values) {
super.setParameterList( name, values );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(String name, Collection<? extends P> values, Class<P> javaType) {
public <P> SqmSelectionQuery<R> setParameterList(String name, Collection<? extends P> values, Class<P> javaType) {
super.setParameterList( name, values, javaType );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(String name, Collection<? extends P> values, BindableType<P> type) {
public <P> SqmSelectionQuery<R> setParameterList(String name, Collection<? extends P> values, BindableType<P> type) {
super.setParameterList( name, values, type );
return this;
}
@Override
public SqmSelectionQuery setParameterList(String name, Object[] values) {
public SqmSelectionQuery<R> setParameterList(String name, Object[] values) {
super.setParameterList( name, values );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(String name, P[] values, Class<P> javaType) {
public <P> SqmSelectionQuery<R> setParameterList(String name, P[] values, Class<P> javaType) {
super.setParameterList( name, values, javaType );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(String name, P[] values, BindableType<P> type) {
public <P> SqmSelectionQuery<R> setParameterList(String name, P[] values, BindableType<P> type) {
super.setParameterList( name, values, type );
return this;
}
@Override
public SqmSelectionQuery setParameterList(int position, Collection values) {
public SqmSelectionQuery<R> setParameterList(int position, Collection values) {
super.setParameterList( position, values );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(int position, Collection<? extends P> values, Class<P> javaType) {
public <P> SqmSelectionQuery<R> setParameterList(int position, Collection<? extends P> values, Class<P> javaType) {
super.setParameterList( position, values, javaType );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(int position, Collection<? extends P> values, BindableType<P> type) {
public <P> SqmSelectionQuery<R> setParameterList(int position, Collection<? extends P> values, BindableType<P> type) {
super.setParameterList( position, values, type );
return this;
}
@Override
public SqmSelectionQuery setParameterList(int position, Object[] values) {
public SqmSelectionQuery<R> setParameterList(int position, Object[] values) {
super.setParameterList( position, values );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(int position, P[] values, Class<P> javaType) {
public <P> SqmSelectionQuery<R> setParameterList(int position, P[] values, Class<P> javaType) {
super.setParameterList( position, values, javaType );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(int position, P[] values, BindableType<P> type) {
public <P> SqmSelectionQuery<R> setParameterList(int position, P[] values, BindableType<P> type) {
super.setParameterList( position, values, type );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(QueryParameter<P> parameter, Collection<? extends P> values) {
public <P> SqmSelectionQuery<R> setParameterList(QueryParameter<P> parameter, Collection<? extends P> values) {
super.setParameterList( parameter, values );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType) {
public <P> SqmSelectionQuery<R> setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, Class<P> javaType) {
super.setParameterList( parameter, values, javaType );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, BindableType<P> type) {
public <P> SqmSelectionQuery<R> setParameterList(QueryParameter<P> parameter, Collection<? extends P> values, BindableType<P> type) {
super.setParameterList( parameter, values, type );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(QueryParameter<P> parameter, P[] values) {
public <P> SqmSelectionQuery<R> setParameterList(QueryParameter<P> parameter, P[] values) {
super.setParameterList( parameter, values );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(QueryParameter<P> parameter, P[] values, Class<P> javaType) {
public <P> SqmSelectionQuery<R> setParameterList(QueryParameter<P> parameter, P[] values, Class<P> javaType) {
super.setParameterList( parameter, values, javaType );
return this;
}
@Override
public <P> SqmSelectionQuery setParameterList(QueryParameter<P> parameter, P[] values, BindableType<P> type) {
public <P> SqmSelectionQuery<R> setParameterList(QueryParameter<P> parameter, P[] values, BindableType<P> type) {
super.setParameterList( parameter, values, type );
return this;
}
@Override
public SqmSelectionQuery setProperties(Map map) {
public SqmSelectionQuery<R> setProperties(Map map) {
super.setProperties( map );
return this;
}
@Override
public SqmSelectionQuery setProperties(Object bean) {
public SqmSelectionQuery<R> setProperties(Object bean) {
super.setProperties( bean );
return this;
}

View File

@ -11,6 +11,7 @@ import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.query.SelectionQuery;
import org.hibernate.testing.orm.domain.StandardDomainModel;
import org.hibernate.testing.orm.domain.contacts.Contact;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
@ -23,7 +24,17 @@ import org.junit.jupiter.api.Test;
@SessionFactory
public class BasicUntypedQueryTests {
@Test
public void untypedEntitySelectTest(SessionFactoryScope scope) {
public void typedEntitySelectTest(SessionFactoryScope scope) {
scope.inTransaction( (session) -> {
checkResults(
session.createSelectQuery( "select c from Contact c", Contact.class ),
session
);
} );
}
@Test
public void rawEntitySelectTest(SessionFactoryScope scope) {
scope.inTransaction( (session) -> {
checkResults(
session.createSelectQuery( "select c from Contact c" ),
@ -32,7 +43,31 @@ public class BasicUntypedQueryTests {
} );
}
private void checkResults(SelectionQuery query, SessionImplementor session) {
@Test
public void rawScalarSelectTest(SessionFactoryScope scope) {
scope.inTransaction( (session) -> {
checkResults(
session.createSelectQuery( "select c.name from Contact c" ),
session
);
} );
}
@Test
public void typedScalarSelectTest(SessionFactoryScope scope) {
scope.inTransaction( (session) -> {
checkResults(
session.createSelectQuery( "select c.name from Contact c", Contact.Name.class ),
session
);
checkResults(
session.createSelectQuery( "select c.name.first from Contact c", String.class ),
session
);
} );
}
private void checkResults(SelectionQuery<?> query, SessionImplementor session) {
query.list();
query.getResultList();
query.uniqueResult();
@ -41,14 +76,4 @@ public class BasicUntypedQueryTests {
query.scroll( ScrollMode.SCROLL_SENSITIVE ).close();
query.stream().close();
}
@Test
public void untypedScalarSelectTest(SessionFactoryScope scope) {
scope.inTransaction( (session) -> {
checkResults(
session.createSelectQuery( "select c.name from Contact c" ),
session
);
} );
}
}