Skip to content
Merged
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 @@ -153,8 +153,11 @@ public SelfRenderingInverseDistributionFunction(

@Override
protected ReturnableType<?> resolveResultType(TypeConfiguration typeConfiguration) {
return (ReturnableType<?>) withinGroupClause.getSortSpecifications().get( 0 ).getSortExpression()
.getExpressible();
return (ReturnableType<?>)
getWithinGroup().getSortSpecifications().get( 0 )
.getSortExpression()
.getExpressible()
.getSqmType();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
* @author Steve Ebersole
*/
public interface DomainType<J> extends SqmExpressible<J> {

@Override
default DomainType<J> getSqmType() {
return this;
}

/**
* The name of the type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public interface EntityDomainType<J> extends IdentifiableDomainType<J>, EntityTy

@Override
Collection<? extends EntityDomainType<? extends J>> getSubTypes();

@Override
default DomainType<J> getSqmType() {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
* @author Steve Ebersole
*/
public interface MappedSuperclassDomainType<J> extends IdentifiableDomainType<J>, MappedSuperclassType<J>, SqmPathSource<J> {
@Override
default DomainType<J> getSqmType() {
return IdentifiableDomainType.super.getSqmType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.hibernate.metamodel.model.domain.internal;

import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.metamodel.model.domain.SimpleDomainType;
import org.hibernate.query.ReturnableType;
import org.hibernate.query.sqm.SqmPathSource;
Expand Down Expand Up @@ -61,6 +62,11 @@ public BasicType<D> getSqmPathType() {
return (BasicType<D>) super.getSqmPathType();
}

@Override
public DomainType<D> getSqmType() {
return getSqmPathType();
}

@Override
public JavaType<D> getExpressibleJavaType() {
return getSqmPathType().getExpressibleJavaType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.hibernate.metamodel.model.domain.internal;

import org.hibernate.metamodel.model.domain.BasicDomainType;
import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.query.ReturnableType;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath;
Expand Down Expand Up @@ -41,6 +42,11 @@ public BasicDomainType<J> getSqmPathType() {
return (BasicDomainType<J>) super.getSqmPathType();
}

@Override
public DomainType<J> getSqmType() {
return getSqmPathType();
}

@Override
public SqmPathSource<?> findSubPathSource(String name) {
throw new IllegalStateException( "Basic paths cannot be dereferenced" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public PersistenceType getPersistenceType() {
public Class<D> getJavaType() {
return getExpressibleJavaType().getJavaTypeClass();
}

@Override
public DomainType<D> getSqmType() {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,7 @@ private String[] doGetImplementors(Class<?> clazz) throws MappingException {
@Override
public MappingModelExpressible<?> resolveMappingExpressible(
SqmExpressible<?> sqmExpressible,
Function<NavigablePath,
TableGroup> tableGroupLocator) {
Function<NavigablePath, TableGroup> tableGroupLocator) {
if ( sqmExpressible instanceof SqmPath ) {
final SqmPath<?> sqmPath = (SqmPath<?>) sqmExpressible;
final NavigablePath navigablePath = sqmPath.getNavigablePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ else if ( sqmPath.getNodeType() instanceof EntityDomainType<?> ) {
else {
return new AnonymousTupleSimpleSqmPathSource<>(
name,
(DomainType<? extends Object>) component.getExpressible(),
component.getExpressible().getSqmType(),
BindableType.SINGULAR_ATTRIBUTE
);
}
Expand Down Expand Up @@ -244,6 +244,11 @@ public DomainType<?> getSqmPathType() {
return this;
}

@Override
public DomainType<T> getSqmType() {
return this;
}

@Override
public SqmPath<T> createSqmPath(SqmPath<?> lhs, SqmPathSource<?> intermediatePathSource) {
throw new UnsupportedMappingException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -121,6 +122,7 @@
import org.hibernate.query.sqm.tree.domain.SqmPath;
import org.hibernate.query.sqm.tree.domain.SqmPluralValuedSimplePath;
import org.hibernate.query.sqm.tree.domain.SqmPolymorphicRootDescriptor;
import org.hibernate.query.sqm.tree.expression.AbstractSqmParameter;
import org.hibernate.query.sqm.tree.expression.SqmAliasedNodeRef;
import org.hibernate.query.sqm.tree.expression.SqmAny;
import org.hibernate.query.sqm.tree.expression.SqmAnyDiscriminatorValue;
Expand Down Expand Up @@ -310,6 +312,7 @@

private ParameterCollector parameterCollector;
private ParameterStyle parameterStyle;
private Map<Object, AbstractSqmParameter<?>> parameters;

private boolean isExtractingJdbcTemporalType;
// Provides access to the current CTE that is being processed, which is potentially recursive
Expand Down Expand Up @@ -3832,14 +3835,14 @@
HqlParser.NamedParameterContext ctx,
SqmExpressible<T> expressibleType) {
parameterStyle = parameterStyle.withNamed();
final SqmNamedParameter<T> param = new SqmNamedParameter<>(
ctx.getChild( 1 ).getText(),
parameterDeclarationContextStack.getCurrent().isMultiValuedBindingAllowed(),
expressibleType,
creationContext.getNodeBuilder()
return resolveParameter(
new SqmNamedParameter<>(
ctx.getChild( 1 ).getText(),
parameterDeclarationContextStack.getCurrent().isMultiValuedBindingAllowed(),
expressibleType,
creationContext.getNodeBuilder()
)
);
parameterCollector.addParameter( param );
return param;
}

@Override
Expand All @@ -3854,14 +3857,28 @@
throw new SemanticException( "Unlabeled ordinal parameter ('?' rather than ?1)" );
}
parameterStyle = parameterStyle.withPositional();
final SqmPositionalParameter<T> param = new SqmPositionalParameter<>(
Integer.parseInt( ctx.getChild( 1 ).getText() ),
parameterDeclarationContextStack.getCurrent().isMultiValuedBindingAllowed(),
expressibleType,
creationContext.getNodeBuilder()
return resolveParameter(
new SqmPositionalParameter<>(
Integer.parseInt( ctx.getChild( 1 ).getText() ),
parameterDeclarationContextStack.getCurrent().isMultiValuedBindingAllowed(),
expressibleType,
creationContext.getNodeBuilder()
)
);
parameterCollector.addParameter( param );
return param;
}

private <T extends AbstractSqmParameter<?>> T resolveParameter(T parameter) {
if ( parameters == null ) {
parameters = new HashMap<>();
}
final Object key = parameter.getName() == null ? parameter.getPosition() : parameter.getName();
final AbstractSqmParameter<?> existingParameter = parameters.putIfAbsent( key, parameter );
if ( existingParameter == null ) {
parameterCollector.addParameter( parameter );
return parameter;
}
//noinspection unchecked
return (T) existingParameter;
}


Expand Down Expand Up @@ -4488,7 +4505,7 @@
else if ( argumentChild instanceof HqlParser.PredicateContext ) {
if ( getCreationOptions().useStrictJpaCompliance() ) {
throw new StrictJpaComplianceViolation( StrictJpaComplianceViolation.Type.FUNCTION_CALL );
}

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException Note

Potential uncaught 'java.lang.NumberFormatException'.
final SqmExpression<?> argument = (SqmExpression<?>) argumentChild.accept( this );

return applyOverClause(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.hibernate.query.sqm;

import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.query.BindableType;
import org.hibernate.query.sqm.tree.expression.SqmExpression;
import org.hibernate.type.descriptor.java.JavaType;
Expand Down Expand Up @@ -38,4 +39,6 @@ default boolean isInstance(J value) {
default SqmExpressible<J> resolveExpressible(SessionFactoryImplementor sessionFactory) {
return this;
}

DomainType<J> getSqmType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ default SqmExpressible<J> getExpressible() {
return (SqmExpressible<J>) getSqmPathType();
}

@Override
default DomainType<J> getSqmType() {
return (DomainType<J>) getSqmPathType();
}

/**
* Indicates if this path source is generically typed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,11 @@ public JavaType<T> getExpressibleJavaType() {
public Class<T> getBindableJavaType() {
return javaType.getJavaTypeClass();
}

@Override
public DomainType<T> getSqmType() {
return null;
}
}

@Override
Expand Down Expand Up @@ -1902,8 +1907,8 @@ public <T> SqmCoalesce<T> coalesce() {
public <Y> JpaCoalesce<Y> coalesce(Expression<? extends Y> x, Expression<? extends Y> y) {
@SuppressWarnings("unchecked")
final SqmExpressible<Y> sqmExpressible = (SqmExpressible<Y>) highestPrecedenceType(
( (SqmExpression<? extends Y>) x ).getNodeType(),
( (SqmExpression<? extends Y>) y ).getNodeType()
( (SqmExpression<? extends Y>) x ).getExpressible(),
( (SqmExpression<? extends Y>) y ).getExpressible()
);
return new SqmCoalesce<>(
sqmExpressible,
Expand Down Expand Up @@ -1934,9 +1939,9 @@ public <Y> SqmExpression<Y> nullif(Expression<Y> x, Y y) {
private <Y> SqmExpression<Y> createNullifFunctionNode(SqmExpression<Y> first, SqmExpression<Y> second) {
//noinspection unchecked
final ReturnableType<Y> type = (ReturnableType<Y>) highestPrecedenceType(
first.getNodeType(),
second.getNodeType()
);
first.getExpressible(),
second.getExpressible()
).getSqmType();

return getFunctionDescriptor("nullif").generateSqmExpression(
asList( first, second ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.sql.SqmToSqlAstConverter;
import org.hibernate.query.sqm.tree.SqmTypedNode;
import org.hibernate.query.sqm.tree.cte.SqmCteTable;
import org.hibernate.query.sqm.tree.domain.AbstractSqmSpecificPluralPartPath;
import org.hibernate.query.sqm.tree.domain.SqmPath;
import org.hibernate.query.sqm.tree.domain.SqmPolymorphicRootDescriptor;
import org.hibernate.query.sqm.tree.domain.SqmTreatedPath;
import org.hibernate.spi.NavigablePath;
import org.hibernate.sql.ast.tree.from.TableGroup;
Expand Down Expand Up @@ -212,13 +214,34 @@ private static ModelPart resolveSqmPath(
}

if ( sqmPath.getLhs() == null ) {
final EntityDomainType<?> entityDomainType = (EntityDomainType<?>) sqmPath.getReferencedPathSource();
return domainModel.findEntityDescriptor( entityDomainType.getHibernateEntityName() );
final SqmPathSource<?> referencedPathSource = sqmPath.getReferencedPathSource();
if ( referencedPathSource instanceof EntityDomainType<?> ) {
final EntityDomainType<?> entityDomainType = (EntityDomainType<?>) referencedPathSource;
return domainModel.findEntityDescriptor( entityDomainType.getHibernateEntityName() );
}
assert referencedPathSource instanceof SqmCteTable<?>;
return null;
}
final TableGroup lhsTableGroup = tableGroupLocator.apply( sqmPath.getLhs().getNavigablePath() );
final ModelPartContainer modelPart;
if ( lhsTableGroup == null ) {
modelPart = (ModelPartContainer) resolveSqmPath( sqmPath.getLhs(), domainModel, tableGroupLocator );
if ( modelPart == null ) {
// There are many reasons for why this situation can happen,
// but they all boil down to a parameter being compared against a SqmPath.

// * If the parameter is used in multiple queries (CTE or subquery),
// resolving the parameter type based on a SqmPath from a query context other than the current one will fail.

// * If the parameter is compared to paths with a polymorphic root,
// the parameter has a SqmPath set as SqmExpressible
// which is still referring to the polymorphic navigable path,
// but during query splitting, the SqmRoot in the query is replaced with a root for a subtype.
// Unfortunately, we can't copy the parameter to reset the SqmExpressible,
// because we currently build only a single DomainParameterXref, instead of one per query split,
// so we have to handle this here instead
return null;
}
}
else {
modelPart = lhsTableGroup.getModelPart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ else if ( domainParamBinding.isMultiValued() ) {
final Iterator<?> valueItr = bindValues.iterator();

// the original SqmParameter is the one we are processing.. create a binding for it..
final Object firstValue = valueItr.next();
for ( int i = 0; i < jdbcParamsBinds.size(); i++ ) {
final JdbcParametersList jdbcParams = jdbcParamsBinds.get( i );
createValueBindings(
Expand All @@ -387,31 +388,38 @@ else if ( domainParamBinding.isMultiValued() ) {
domainParamBinding,
parameterType,
jdbcParams,
valueItr.next(),
firstValue,
tableGroupLocator,
session
);
}

// an then one for each of the expansions
final List<SqmParameter<?>> expansions = domainParameterXref.getExpansions( sqmParameter );
assert expansions.size() == bindValues.size() - 1;
final int expansionCount = bindValues.size() - 1;
final int parameterUseCount = jdbcParamsBinds.size();
assert expansions.size() == expansionCount * parameterUseCount;
int expansionPosition = 0;
while ( valueItr.hasNext() ) {
final SqmParameter<?> expansionSqmParam = expansions.get( expansionPosition++ );
final List<JdbcParametersList> jdbcParamBinds = jdbcParamMap.get( expansionSqmParam );
for ( int i = 0; i < jdbcParamBinds.size(); i++ ) {
JdbcParametersList expansionJdbcParams = jdbcParamBinds.get( i );
createValueBindings(
jdbcParameterBindings,
queryParam, domainParamBinding,
parameterType,
expansionJdbcParams,
valueItr.next(),
tableGroupLocator,
session
);
final Object expandedValue = valueItr.next();
for ( int j = 0; j < parameterUseCount; j++ ) {
final SqmParameter<?> expansionSqmParam = expansions.get( expansionPosition + j * expansionCount );
final List<JdbcParametersList> jdbcParamBinds = jdbcParamMap.get( expansionSqmParam );
for ( int i = 0; i < jdbcParamBinds.size(); i++ ) {
JdbcParametersList expansionJdbcParams = jdbcParamBinds.get( i );
createValueBindings(
jdbcParameterBindings,
queryParam,
domainParamBinding,
parameterType,
expansionJdbcParams,
expandedValue,
tableGroupLocator,
session
);
}
}
expansionPosition++;
}
}
else if ( domainParamBinding.getBindValue() == null ) {
Expand Down
Loading