deal with more casts
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
dd036023cf
commit
14e0f12654
|
@ -63,7 +63,6 @@ import org.hibernate.query.spi.QueryOptions;
|
||||||
import org.hibernate.query.spi.QueryParameterBindings;
|
import org.hibernate.query.spi.QueryParameterBindings;
|
||||||
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
import org.hibernate.query.spi.ScrollableResultsImplementor;
|
||||||
import org.hibernate.query.spi.SelectQueryPlan;
|
import org.hibernate.query.spi.SelectQueryPlan;
|
||||||
import org.hibernate.query.sqm.SqmPathSource;
|
|
||||||
import org.hibernate.query.sqm.internal.SqmInterpretationsKey.InterpretationsKeySource;
|
import org.hibernate.query.sqm.internal.SqmInterpretationsKey.InterpretationsKeySource;
|
||||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
||||||
import org.hibernate.query.sqm.spi.NamedSqmQueryMemento;
|
import org.hibernate.query.sqm.spi.NamedSqmQueryMemento;
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.query.sqm.tree.select;
|
package org.hibernate.query.sqm.tree.select;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -40,6 +39,8 @@ import jakarta.persistence.criteria.Predicate;
|
||||||
import jakarta.persistence.criteria.Selection;
|
import jakarta.persistence.criteria.Selection;
|
||||||
import jakarta.persistence.metamodel.EntityType;
|
import jakarta.persistence.metamodel.EntityType;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptySet;
|
||||||
|
import static java.util.Collections.unmodifiableSet;
|
||||||
import static org.hibernate.query.sqm.spi.SqmCreationHelper.combinePredicates;
|
import static org.hibernate.query.sqm.spi.SqmCreationHelper.combinePredicates;
|
||||||
import static org.hibernate.query.sqm.SqmQuerySource.CRITERIA;
|
import static org.hibernate.query.sqm.SqmQuerySource.CRITERIA;
|
||||||
import static org.hibernate.query.sqm.tree.SqmCopyContext.noParamCopyContext;
|
import static org.hibernate.query.sqm.tree.SqmCopyContext.noParamCopyContext;
|
||||||
|
@ -168,8 +169,8 @@ public class SqmSelectStatement<T> extends AbstractSqmSelectQuery<T> implements
|
||||||
public SqmQuerySpec<T> getQuerySpec() {
|
public SqmQuerySpec<T> getQuerySpec() {
|
||||||
if ( querySource == CRITERIA ) {
|
if ( querySource == CRITERIA ) {
|
||||||
final SqmQueryPart<T> queryPart = getQueryPart();
|
final SqmQueryPart<T> queryPart = getQueryPart();
|
||||||
if ( queryPart instanceof SqmQuerySpec<?> ) {
|
if ( queryPart instanceof SqmQuerySpec<T> querySpec ) {
|
||||||
return (SqmQuerySpec<T>) queryPart;
|
return querySpec;
|
||||||
}
|
}
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Query group can't be treated as query spec. Use JpaSelectCriteria#getQueryPart to access query group details"
|
"Query group can't be treated as query spec. Use JpaSelectCriteria#getQueryPart to access query group details"
|
||||||
|
@ -185,8 +186,8 @@ public class SqmSelectStatement<T> extends AbstractSqmSelectQuery<T> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean producesUniqueResults(SqmQueryPart<?> queryPart) {
|
private boolean producesUniqueResults(SqmQueryPart<?> queryPart) {
|
||||||
if ( queryPart instanceof SqmQuerySpec<?> ) {
|
if ( queryPart instanceof SqmQuerySpec<?> querySpec ) {
|
||||||
return ( (SqmQuerySpec<?>) queryPart ).producesUniqueResults();
|
return querySpec.producesUniqueResults();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// For query groups we have to assume that duplicates are possible
|
// For query groups we have to assume that duplicates are possible
|
||||||
|
@ -199,13 +200,15 @@ public class SqmSelectStatement<T> extends AbstractSqmSelectQuery<T> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean containsCollectionFetches(SqmQueryPart<?> queryPart) {
|
private boolean containsCollectionFetches(SqmQueryPart<?> queryPart) {
|
||||||
if ( queryPart instanceof SqmQuerySpec<?> ) {
|
if ( queryPart instanceof SqmQuerySpec<?> querySpec ) {
|
||||||
return ( (SqmQuerySpec<?>) queryPart ).containsCollectionFetches();
|
return querySpec.containsCollectionFetches();
|
||||||
|
}
|
||||||
|
else if ( queryPart instanceof SqmQueryGroup<?> queryGroup ) {
|
||||||
|
// We only have to check the first one
|
||||||
|
return containsCollectionFetches( queryGroup.getQueryParts().get( 0 ) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// We only have to check the first one
|
throw new IllegalStateException("No SqmQueryPart");
|
||||||
final SqmQueryGroup<?> queryGroup = (SqmQueryGroup<?>) queryPart;
|
|
||||||
return containsCollectionFetches( queryGroup.getQueryParts().get( 0 ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,13 +217,15 @@ public class SqmSelectStatement<T> extends AbstractSqmSelectQuery<T> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean usesDistinct(SqmQueryPart<?> queryPart) {
|
private boolean usesDistinct(SqmQueryPart<?> queryPart) {
|
||||||
if ( queryPart instanceof SqmQuerySpec<?> ) {
|
if ( queryPart instanceof SqmQuerySpec<?> querySpec ) {
|
||||||
return ( (SqmQuerySpec<?>) queryPart ).getSelectClause().isDistinct();
|
return querySpec.getSelectClause().isDistinct();
|
||||||
|
}
|
||||||
|
else if ( queryPart instanceof SqmQueryGroup<?> queryGroup ) {
|
||||||
|
// We only have to check the first one
|
||||||
|
return usesDistinct( queryGroup.getQueryParts().get( 0 ) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// We only have to check the first one
|
throw new IllegalStateException("No SqmQueryPart");
|
||||||
final SqmQueryGroup<?> queryGroup = (SqmQueryGroup<?>) queryPart;
|
|
||||||
return usesDistinct( queryGroup.getQueryParts().get( 0 ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,8 +235,9 @@ public class SqmSelectStatement<T> extends AbstractSqmSelectQuery<T> implements
|
||||||
assert parameters == null : "SqmSelectStatement (as Criteria) should not have collected parameters";
|
assert parameters == null : "SqmSelectStatement (as Criteria) should not have collected parameters";
|
||||||
return collectParameters( this );
|
return collectParameters( this );
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
return parameters == null ? Collections.emptySet() : Collections.unmodifiableSet( parameters );
|
return parameters == null ? emptySet() : unmodifiableSet( parameters );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -249,7 +255,6 @@ public class SqmSelectStatement<T> extends AbstractSqmSelectQuery<T> implements
|
||||||
if ( parameters == null ) {
|
if ( parameters == null ) {
|
||||||
parameters = new LinkedHashSet<>();
|
parameters = new LinkedHashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters.add( parameter );
|
parameters.add( parameter );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +274,8 @@ public class SqmSelectStatement<T> extends AbstractSqmSelectQuery<T> implements
|
||||||
String name,
|
String name,
|
||||||
AbstractQuery<X> baseCriteria,
|
AbstractQuery<X> baseCriteria,
|
||||||
boolean unionDistinct,
|
boolean unionDistinct,
|
||||||
Function<JpaCteCriteria<X>, AbstractQuery<X>> recursiveCriteriaProducer) {
|
Function<JpaCteCriteria<X>,
|
||||||
|
AbstractQuery<X>> recursiveCriteriaProducer) {
|
||||||
if ( baseCriteria instanceof SqmSubQuery<?> ) {
|
if ( baseCriteria instanceof SqmSubQuery<?> ) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Invalid query type provided to root query 'with' method, " +
|
"Invalid query type provided to root query 'with' method, " +
|
||||||
|
|
Loading…
Reference in New Issue