diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryObserverForNamedQueryValidation.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryObserverForNamedQueryValidation.java index 97d6886d98..b3ce74171c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryObserverForNamedQueryValidation.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryObserverForNamedQueryValidation.java @@ -34,7 +34,7 @@ class SessionFactoryObserverForNamedQueryValidation implements SessionFactoryObs public void sessionFactoryCreated(SessionFactory factory) { SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) factory; final QueryEngine queryEngine = sessionFactory.getQueryEngine(); - queryEngine.prepare( sessionFactory, metadata ); + queryEngine.getNamedObjectRepository().prepare( sessionFactory, metadata ); if ( sessionFactory.getSessionFactoryOptions().isNamedQueryStartupCheckingEnabled() ) { queryEngine.validateNamedQueries(); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/CastStrEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/CastStrEmulation.java index 0e426b17ec..80bc764cb3 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/CastStrEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/CastStrEmulation.java @@ -53,21 +53,19 @@ public class CastStrEmulation protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { final SqmTypedNode argument = arguments.get( 0 ); return queryEngine.getSqmFunctionRegistry().findFunctionDescriptor( "cast" ) .generateSqmExpression( asList( argument, new SqmCastTarget<>( - typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ), - argument.nodeBuilder() + queryEngine.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.STRING ), + queryEngine.getCriteriaBuilder() ) ), impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/CoalesceIfnullEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/CoalesceIfnullEmulation.java index e017d94bb8..9ca82fc5f7 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/CoalesceIfnullEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/CoalesceIfnullEmulation.java @@ -13,7 +13,6 @@ import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators; import org.hibernate.query.sqm.produce.function.StandardFunctionArgumentTypeResolvers; import org.hibernate.query.sqm.tree.SqmTypedNode; -import org.hibernate.type.spi.TypeConfiguration; import java.util.List; @@ -35,14 +34,12 @@ public class CoalesceIfnullEmulation protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return queryEngine.getSqmFunctionRegistry().findFunctionDescriptor( "coalesce" ) .generateSqmExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/DateTruncEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/DateTruncEmulation.java index 07382aa7e0..a416215db6 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/DateTruncEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/DateTruncEmulation.java @@ -71,8 +71,7 @@ public class DateTruncEmulation extends AbstractSqmFunctionDescriptor implements protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { final NodeBuilder nodeBuilder = queryEngine.getCriteriaBuilder(); final TemporalUnit temporalUnit = ( (SqmExtractUnit) arguments.get( 1 ) ).getUnit(); final String pattern; @@ -113,13 +112,12 @@ public class DateTruncEmulation extends AbstractSqmFunctionDescriptor implements datetime, new SqmFormat( pattern, - typeConfiguration.getBasicTypeForJavaType( String.class ), + nodeBuilder.getTypeConfiguration().getBasicTypeForJavaType( String.class ), nodeBuilder ) ), null, - queryEngine, - typeConfiguration + queryEngine ); final SqmExpression formattedDatetime; if ( literal != null ) { @@ -130,13 +128,12 @@ public class DateTruncEmulation extends AbstractSqmFunctionDescriptor implements formatExpression, new SqmLiteral<>( literal, - typeConfiguration.getBasicTypeForJavaType( String.class ), + nodeBuilder.getTypeConfiguration().getBasicTypeForJavaType( String.class ), nodeBuilder ) ), null, - queryEngine, - typeConfiguration + queryEngine ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/ExtractFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/ExtractFunction.java index 094c770db6..176257375f 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/ExtractFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/ExtractFunction.java @@ -81,8 +81,7 @@ public class ExtractFunction protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { final SqmExtractUnit field = (SqmExtractUnit) arguments.get( 0 ); final SqmExpression originalExpression = (SqmExpression) arguments.get( 1 ); final boolean compositeTemporal = SqmExpressionHelper.isCompositeTemporal( originalExpression ); @@ -91,7 +90,7 @@ public class ExtractFunction TemporalUnit unit = field.getUnit(); switch ( unit ) { case NANOSECOND: - return extractNanoseconds( expression, queryEngine, typeConfiguration ); + return extractNanoseconds( expression, queryEngine ); case NATIVE: throw new SemanticException("can't extract() the field TemporalUnit.NATIVE"); case OFFSET: @@ -101,9 +100,7 @@ public class ExtractFunction ); return new SelfRenderingSqmFunction<>( this, - (sqlAppender, sqlAstArguments, walker) -> { - sqlAstArguments.get( 0 ).accept( walker ); - }, + (sqlAppender, sqlAstArguments, walker) -> sqlAstArguments.get( 0 ).accept( walker ), Collections.singletonList( offsetPath ), null, null, @@ -114,7 +111,7 @@ public class ExtractFunction } else { // use format(arg, 'xxx') to get the offset - return extractOffsetUsingFormat( expression, queryEngine, typeConfiguration ); + return extractOffsetUsingFormat( expression, queryEngine ); } case DATE: case TIME: @@ -122,18 +119,18 @@ public class ExtractFunction // which might be javax.sql.Date / javax.sql.Time or // java.time.LocalDate / java.time.LocalTime depending // on the type of the expression we're extracting from - return extractDateOrTimeUsingCast( expression, field.getType(), queryEngine, typeConfiguration ); + return extractDateOrTimeUsingCast( expression, field.getType(), queryEngine ); case WEEK_OF_MONTH: // use ceiling(extract(day of month, arg)/7.0) - return extractWeek( expression, field, DAY_OF_MONTH, queryEngine, typeConfiguration); + return extractWeek( expression, field, DAY_OF_MONTH, queryEngine ); case WEEK_OF_YEAR: // use ceiling(extract(day of year, arg)/7.0) - return extractWeek( expression, field, DAY_OF_YEAR, queryEngine, typeConfiguration); + return extractWeek( expression, field, DAY_OF_YEAR, queryEngine ); default: // otherwise it's something we expect the SQL dialect // itself to understand, either natively, or via the // method Dialect.extract() - return new SelfRenderingSqmFunction( + return new SelfRenderingSqmFunction<>( this, this, expression == originalExpression ? arguments : List.of( arguments.get( 0 ), expression ), @@ -150,10 +147,10 @@ public class ExtractFunction SqmExpression expressionToExtract, SqmExtractUnit field, TemporalUnit dayOf, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { final NodeBuilder builder = field.nodeBuilder(); + final TypeConfiguration typeConfiguration = queryEngine.getTypeConfiguration(); final BasicType intType = typeConfiguration.getBasicTypeForJavaType( Integer.class ); final BasicType floatType = typeConfiguration.getBasicTypeForJavaType( Float.class ); @@ -164,8 +161,7 @@ public class ExtractFunction .generateSqmExpression( asList( dayOfUnit, expressionToExtract ), intType, - queryEngine, - typeConfiguration + queryEngine ); final SqmExtractUnit dayOfWeekUnit = new SqmExtractUnit<>( DAY_OF_WEEK, intType, builder ); @@ -175,8 +171,7 @@ public class ExtractFunction .generateSqmExpression( asList( dayOfWeekUnit, expressionToExtract ), intType, - queryEngine, - typeConfiguration + queryEngine ); final SqmLiteral seven = new SqmLiteral<>( 7.0f, floatType, builder ); @@ -195,8 +190,7 @@ public class ExtractFunction .generateSqmExpression( asList( daySubtractionInt, new SqmCastTarget<>( floatType, builder ) ), floatType, - queryEngine, - typeConfiguration + queryEngine ); } else { @@ -219,15 +213,13 @@ public class ExtractFunction builder ), intType, // Implicit cast to int - queryEngine, - typeConfiguration + queryEngine ); } private SelfRenderingSqmFunction toLong( SqmExpression arg, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { //Not every database supports round() (looking at you Derby) //so use floor() instead, which is perfectly fine for this // return getFunctionTemplate("round").makeSqmFunctionExpression( @@ -236,23 +228,22 @@ public class ExtractFunction // creationContext.getQueryEngine(), // creationContext.getDomainModel().getTypeConfiguration() // ); - BasicType longType = typeConfiguration.getBasicTypeForJavaType(Long.class); + BasicType longType = queryEngine.getTypeConfiguration().getBasicTypeForJavaType(Long.class); return queryEngine.getSqmFunctionRegistry() .findFunctionDescriptor("floor") .generateSqmExpression( arg, longType, // Implicit cast to long - queryEngine, - typeConfiguration + queryEngine ); } private SelfRenderingSqmFunction extractNanoseconds( SqmExpression expressionToExtract, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { final NodeBuilder builder = expressionToExtract.nodeBuilder(); + final TypeConfiguration typeConfiguration = queryEngine.getTypeConfiguration(); final BasicType floatType = typeConfiguration.getBasicTypeForJavaType(Float.class); final SqmExtractUnit extractSeconds = new SqmExtractUnit<>( SECOND, floatType, builder ); @@ -263,24 +254,22 @@ public class ExtractFunction generateSqmExpression( asList( extractSeconds, expressionToExtract ), floatType, - queryEngine, - typeConfiguration + queryEngine ), billion, floatType, builder ), - queryEngine, - typeConfiguration + queryEngine ); } private SelfRenderingSqmFunction extractOffsetUsingFormat( SqmExpression expressionToExtract, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { final NodeBuilder builder = expressionToExtract.nodeBuilder(); + final TypeConfiguration typeConfiguration = queryEngine.getTypeConfiguration(); final BasicType offsetType = typeConfiguration.getBasicTypeForJavaType(ZoneOffset.class); final BasicType stringType = typeConfiguration.getBasicTypeForJavaType(String.class); @@ -294,16 +283,14 @@ public class ExtractFunction .generateSqmExpression( asList( expressionToExtract, offsetFormat ), offsetType, - queryEngine, - typeConfiguration + queryEngine ); } private SelfRenderingSqmFunction extractDateOrTimeUsingCast( SqmExpression expressionToExtract, ReturnableType type, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { final NodeBuilder builder = expressionToExtract.nodeBuilder(); final SqmCastTarget target = new SqmCastTarget<>( type, builder ); @@ -312,8 +299,7 @@ public class ExtractFunction .generateSqmExpression( asList( expressionToExtract, target ), type, - queryEngine, - typeConfiguration + queryEngine ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/FormatFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/FormatFunction.java index 1bb12b76d5..b5d7078bb9 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/FormatFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/FormatFunction.java @@ -148,8 +148,7 @@ public class FormatFunction extends AbstractSqmFunctionDescriptor implements Fun protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return new FormatSqmFunction<>( this, this, diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/HypotheticalSetWindowEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/HypotheticalSetWindowEmulation.java index c3cd67686d..a4b8c13e84 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/HypotheticalSetWindowEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/HypotheticalSetWindowEmulation.java @@ -49,8 +49,7 @@ public class HypotheticalSetWindowEmulation extends HypotheticalSetFunction { SqmPredicate filter, SqmOrderByClause withinGroupClause, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return new SelfRenderingSqmOrderedSetAggregateFunction<>( this, this, diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/InsertSubstringOverlayEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/InsertSubstringOverlayEmulation.java index 52106f4939..ef17e68792 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/InsertSubstringOverlayEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/InsertSubstringOverlayEmulation.java @@ -65,8 +65,8 @@ public class InsertSubstringOverlayEmulation protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { + TypeConfiguration typeConfiguration = queryEngine.getTypeConfiguration(); final BasicType intType = typeConfiguration.getBasicTypeForJavaType( Integer.class ); final BasicType stringType = typeConfiguration.getBasicTypeForJavaType( String.class ); @@ -76,15 +76,14 @@ public class InsertSubstringOverlayEmulation SqmTypedNode length = arguments.size() > 3 ? arguments.get(3) : queryEngine.getSqmFunctionRegistry().findFunctionDescriptor("length") - .generateSqmExpression( replacement, intType, queryEngine, typeConfiguration ); + .generateSqmExpression( replacement, intType, queryEngine); SqmFunctionDescriptor insert = queryEngine.getSqmFunctionRegistry().findFunctionDescriptor("insert"); if ( insert != null ) { return insert.generateSqmExpression( asList( string, start, length, replacement ), impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } else { @@ -109,8 +108,7 @@ public class InsertSubstringOverlayEmulation SqmTypedNode restString = substring.generateSqmExpression( asList( string, startPlusLength ), impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); if ( strictSubstring ) { restString = new SqmCaseSearched<>( stringType, start.nodeBuilder() ) @@ -121,8 +119,7 @@ public class InsertSubstringOverlayEmulation lengthFunction.generateSqmExpression( asList( string ), intType, - queryEngine, - typeConfiguration + queryEngine ), string.nodeBuilder() ), @@ -134,15 +131,13 @@ public class InsertSubstringOverlayEmulation substring.generateSqmExpression( asList( string, one, startMinusOne ), impliedResultType, - queryEngine, - typeConfiguration + queryEngine ), replacement, restString ), impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/InverseDistributionFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/InverseDistributionFunction.java index 32b386a9dd..eca368529b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/InverseDistributionFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/InverseDistributionFunction.java @@ -60,8 +60,7 @@ public class InverseDistributionFunction extends AbstractSqmSelfRenderingFunctio SqmPredicate filter, SqmOrderByClause withinGroupClause, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return new SelfRenderingInverseDistributionFunction<>( arguments, filter, diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/InverseDistributionWindowEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/InverseDistributionWindowEmulation.java index e1ad3eda13..c8d2cc49ba 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/InverseDistributionWindowEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/InverseDistributionWindowEmulation.java @@ -49,8 +49,7 @@ public class InverseDistributionWindowEmulation extends InverseDistributionFunct SqmPredicate filter, SqmOrderByClause withinGroupClause, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return new SelfRenderingInverseDistributionFunction<>( arguments, filter, diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/LocatePositionEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/LocatePositionEmulation.java index 0c09dbe368..9762955ee1 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/LocatePositionEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/LocatePositionEmulation.java @@ -44,10 +44,9 @@ public class LocatePositionEmulation extends AbstractSqmFunctionDescriptor { protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return queryEngine.getSqmFunctionRegistry().findFunctionDescriptor( "locate" ) - .generateSqmExpression( arguments, impliedResultType, queryEngine, typeConfiguration ); + .generateSqmExpression( arguments, impliedResultType, queryEngine); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/LpadRpadPadEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/LpadRpadPadEmulation.java index 4b5b8feea6..98f69537ca 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/LpadRpadPadEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/LpadRpadPadEmulation.java @@ -57,8 +57,7 @@ public class LpadRpadPadEmulation protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { SqmTrimSpecification padSpec = (SqmTrimSpecification) arguments.get(2); String padName = padSpec.getSpecification() == TrimSpec.LEADING ? "lpad" : "rpad"; return queryEngine.getSqmFunctionRegistry().findFunctionDescriptor( padName ) @@ -74,8 +73,7 @@ public class LpadRpadPadEmulation arguments.get(1) ), impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/NvlCoalesceEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/NvlCoalesceEmulation.java index 076dd784b0..f794bea750 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/NvlCoalesceEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/NvlCoalesceEmulation.java @@ -16,7 +16,6 @@ import org.hibernate.query.sqm.produce.function.StandardFunctionArgumentTypeReso import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers; import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.query.sqm.tree.expression.SqmExpression; -import org.hibernate.type.spi.TypeConfiguration; import java.util.List; @@ -45,8 +44,7 @@ public class NvlCoalesceEmulation protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { SqmFunctionDescriptor nvl = queryEngine.getSqmFunctionRegistry() @@ -64,8 +62,7 @@ public class NvlCoalesceEmulation result = nvl.generateSqmExpression( asList( next, result ), type, - queryEngine, - typeConfiguration + queryEngine ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/OracleTruncFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/OracleTruncFunction.java index 14550f80c1..2b3c74a982 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/OracleTruncFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/OracleTruncFunction.java @@ -11,7 +11,6 @@ import java.util.List; import org.hibernate.query.ReturnableType; import org.hibernate.query.spi.QueryEngine; -import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.TemporalUnit; import org.hibernate.query.sqm.function.FunctionRenderingSupport; import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; @@ -44,9 +43,7 @@ public class OracleTruncFunction extends TruncFunction { protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { - final NodeBuilder nodeBuilder = queryEngine.getCriteriaBuilder(); + QueryEngine queryEngine) { final List> args = new ArrayList<>( arguments ); final FunctionRenderingSupport renderingSupport; final ArgumentsValidator argumentsValidator; @@ -81,8 +78,7 @@ public class OracleTruncFunction extends TruncFunction { return dateTruncEmulation.generateSqmFunctionExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); default: throw new UnsupportedOperationException( "Temporal unit not supported [" + temporalUnit + "]" ); @@ -90,8 +86,8 @@ public class OracleTruncFunction extends TruncFunction { // replace temporal_unit parameter with translated string format literal args.set( 1, new SqmLiteral<>( pattern, - typeConfiguration.getBasicTypeForJavaType( String.class ), - nodeBuilder + queryEngine.getTypeConfiguration().getBasicTypeForJavaType( String.class ), + queryEngine.getCriteriaBuilder() ) ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/PostgreSQLTruncFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/PostgreSQLTruncFunction.java index 2fc4b1ceeb..ccc32b0b73 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/PostgreSQLTruncFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/PostgreSQLTruncFunction.java @@ -39,16 +39,14 @@ public class PostgreSQLTruncFunction extends TruncFunction { protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { final List> args = new ArrayList<>( arguments ); if ( arguments.size() != 2 || !( arguments.get( 1 ) instanceof SqmExtractUnit ) ) { // numeric truncation return postgreSQLTruncRoundFunction.generateSqmFunctionExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } // datetime truncation diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/PostgreSQLTruncRoundFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/PostgreSQLTruncRoundFunction.java index 2eac7323e8..ece88e3bef 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/PostgreSQLTruncRoundFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/PostgreSQLTruncRoundFunction.java @@ -11,7 +11,6 @@ import java.util.List; import org.hibernate.query.ReturnableType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor; -import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; import org.hibernate.query.sqm.function.FunctionRenderingSupport; import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; import org.hibernate.query.sqm.produce.function.ArgumentTypesValidator; @@ -24,7 +23,6 @@ import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.type.descriptor.jdbc.JdbcType; -import org.hibernate.type.spi.TypeConfiguration; import static org.hibernate.query.sqm.produce.function.FunctionParameterType.INTEGER; import static org.hibernate.query.sqm.produce.function.FunctionParameterType.NUMERIC; @@ -108,8 +106,7 @@ public class PostgreSQLTruncRoundFunction extends AbstractSqmFunctionDescriptor protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return new SelfRenderingSqmFunction<>( this, this, diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/SqlServerConvertTruncFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/SqlServerConvertTruncFunction.java index fd89483c0d..197f8c3a1b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/SqlServerConvertTruncFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/SqlServerConvertTruncFunction.java @@ -42,16 +42,14 @@ public class SqlServerConvertTruncFunction extends TruncFunction { protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { final List> args = new ArrayList<>( arguments ); if ( arguments.size() == 2 && arguments.get( 1 ) instanceof SqmExtractUnit ) { // datetime truncation return dateTruncEmulation.generateSqmExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } // numeric truncation diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/SybaseTruncFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/SybaseTruncFunction.java index 2ea5f444a2..79929c5ca2 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/SybaseTruncFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/SybaseTruncFunction.java @@ -23,7 +23,6 @@ import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.type.spi.TypeConfiguration; import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; /** * Custom {@link TruncFunction} for Sybase which uses a dialect-specific emulation function for datetimes @@ -48,16 +47,14 @@ public class SybaseTruncFunction extends TruncFunction { protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { final List> args = new ArrayList<>( arguments ); if ( arguments.size() == 2 && arguments.get( 1 ) instanceof SqmExtractUnit ) { // datetime truncation return dateTruncEmulation.generateSqmFunctionExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } // numeric truncation @@ -112,9 +109,7 @@ public class SybaseTruncFunction extends TruncFunction { protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { - final NodeBuilder nodeBuilder = queryEngine.getCriteriaBuilder(); + QueryEngine queryEngine) { final TemporalUnit temporalUnit = ( (SqmExtractUnit) arguments.get( 1 ) ).getUnit(); final String literal; switch ( temporalUnit ) { @@ -140,19 +135,18 @@ public class SybaseTruncFunction extends TruncFunction { throw new UnsupportedOperationException( "Temporal unit not supported [" + temporalUnit + "]" ); } + final NodeBuilder nodeBuilder = queryEngine.getCriteriaBuilder(); return new SelfRenderingSqmFunction<>( this, this, - literal == null ? - singletonList( arguments.get( 0 ) ) : - asList( - arguments.get( 0 ), - new SqmLiteral<>( - literal, - typeConfiguration.getBasicTypeForJavaType( String.class ), - nodeBuilder - ) - ), + asList( + arguments.get( 0 ), + new SqmLiteral<>( + literal, + queryEngine.getTypeConfiguration().getBasicTypeForJavaType( String.class ), + nodeBuilder + ) + ), impliedResultType, null, getReturnTypeResolver(), diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/TransactSQLStrFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/TransactSQLStrFunction.java index cb0c711afe..f4fd857511 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/TransactSQLStrFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/TransactSQLStrFunction.java @@ -44,14 +44,12 @@ public class TransactSQLStrFunction extends CastStrEmulation implements Function protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { if ( arguments.size() == 1 ) { return super.generateSqmFunctionExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/TruncFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/TruncFunction.java index 8cf32ca21e..a2d825ea67 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/TruncFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/TruncFunction.java @@ -97,8 +97,7 @@ public class TruncFunction extends AbstractSqmFunctionDescriptor { protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { final NodeBuilder nodeBuilder = queryEngine.getCriteriaBuilder(); final List> args = new ArrayList<>( arguments ); final FunctionRenderingSupport renderingSupport; @@ -114,8 +113,7 @@ public class TruncFunction extends AbstractSqmFunctionDescriptor { return dateTruncEmulation.generateSqmFunctionExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } else if ( datetimeTrunc == DatetimeTrunc.TRUNC ) { @@ -150,7 +148,7 @@ public class TruncFunction extends AbstractSqmFunctionDescriptor { // replace temporal_unit parameter with translated string format literal args.set( 1, new SqmLiteral<>( pattern, - typeConfiguration.getBasicTypeForJavaType( String.class ), + nodeBuilder.getTypeConfiguration().getBasicTypeForJavaType( String.class ), nodeBuilder ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index 831842def9..b30b474c73 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -88,6 +88,7 @@ import org.hibernate.procedure.spi.ProcedureCallImplementor; import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.proxy.LazyInitializer; import org.hibernate.query.hql.spi.SqmQueryImplementor; +import org.hibernate.query.internal.QueryEngineImpl; import org.hibernate.query.named.NamedObjectRepository; import org.hibernate.query.named.NamedQueryMemento; import org.hibernate.query.spi.QueryEngine; @@ -260,7 +261,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im // created, then we can split creation of QueryEngine // and SqmFunctionRegistry, instantiating just the // registry here, and doing the engine later - queryEngine = QueryEngine.from( this, bootMetamodel ); + queryEngine = QueryEngineImpl.from( this, bootMetamodel ); // create runtime metamodels (mapping and JPA) final RuntimeMetamodelsImpl runtimeMetamodelsImpl = new RuntimeMetamodelsImpl(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingExpression.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingExpression.java index d1b77c50fa..bd285c585d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingExpression.java @@ -67,8 +67,7 @@ public interface OrderingExpression extends Node { .generateSqmExpression( new SqmSelfRenderingExpression<>( walker -> expression, null, null ), null, - queryEngine, - queryEngine.getTypeConfiguration() + queryEngine ) .convertToSqlAst( converter ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BagAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BagAttributeImpl.java index 8b4afec49a..cec671a02f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BagAttributeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BagAttributeImpl.java @@ -46,7 +46,7 @@ public class BagAttributeImpl alias, joinType, fetched, - creationState.getCreationContext().getQueryEngine().getCriteriaBuilder() + creationState.getCreationContext().getNodeBuilder() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java index 640d6aa7ec..ca09b669df 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java @@ -158,16 +158,11 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl // private final Map, EmbeddableDomainType> jpaEmbeddableTypeMap = new ConcurrentHashMap<>(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - private final ServiceRegistry serviceRegistry; - private final TypeConfiguration typeConfiguration; - private final Map implementorsCache = new ConcurrentHashMap<>(); private final Map, MappingModelExpressible> tupleTypeCache = new ConcurrentHashMap<>(); public MappingMetamodelImpl(TypeConfiguration typeConfiguration, ServiceRegistry serviceRegistry) { - this.serviceRegistry = serviceRegistry; - this.typeConfiguration = typeConfiguration; - this.jpaMetamodel = new JpaMetamodelImpl( typeConfiguration, this, serviceRegistry ); + jpaMetamodel = new JpaMetamodelImpl( typeConfiguration, this, serviceRegistry ); } public JpaMetamodelImplementor getJpaMetamodel() { @@ -180,7 +175,8 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl bootModel.getMappedSuperclassMappingsCopy().forEach( MappedSuperclass::prepareForMappingModel ); bootModel.getEntityBindings().forEach( persistentClass -> persistentClass.prepareForMappingModel( context ) ); - final PersisterFactory persisterFactory = serviceRegistry.getService( PersisterFactory.class ); + final PersisterFactory persisterFactory = + jpaMetamodel.getServiceRegistry().getService( PersisterFactory.class ); final CacheImplementor cache = context.getCache(); processBootEntities( bootModel.getEntityBindings(), @@ -360,7 +356,7 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl @Override public TypeConfiguration getTypeConfiguration() { - return typeConfiguration; + return jpaMetamodel.getTypeConfiguration(); } @Override @@ -370,7 +366,7 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl @Override public ServiceRegistry getServiceRegistry() { - return serviceRegistry; + return jpaMetamodel.getServiceRegistry(); } @Override @@ -532,7 +528,9 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl } try { - final Class clazz = serviceRegistry.getService( ClassLoaderService.class ).classForName( className ); + final Class clazz = + jpaMetamodel.getServiceRegistry().getService( ClassLoaderService.class ) + .classForName( className ); implementors = doGetImplementors( clazz ); if ( implementors.length > 0 ) { implementorsCache.putIfAbsent( className, implementors ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/HqlTranslator.java b/hibernate-core/src/main/java/org/hibernate/query/hql/HqlTranslator.java index 0d0ff29a85..ab53051c41 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/HqlTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/HqlTranslator.java @@ -30,11 +30,4 @@ public interface HqlTranslator { * @return The semantic representation of the incoming query. */ SqmStatement translate(String hql, Class expectedResultType); - - /** - * Give the translator a chance to "shut down" if it needs to - */ - default void close() { - // nothing to do generally speaking - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/BasicDotIdentifierConsumer.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/BasicDotIdentifierConsumer.java index d283e988ce..c3f7bea486 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/BasicDotIdentifierConsumer.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/BasicDotIdentifierConsumer.java @@ -191,8 +191,7 @@ public class BasicDotIdentifierConsumer implements DotIdentifierConsumer { if ( functionDescriptor != null ) { return functionDescriptor.generateSqmExpression( null, - creationContext.getQueryEngine(), - creationContext.getNodeBuilder().getTypeConfiguration() + creationContext.getQueryEngine() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java index 787d5be2f6..3b468be55d 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java @@ -100,7 +100,7 @@ public class FullyQualifiedReflectivePathTerminal if ( namedClass.isEnum() ) { return new SqmEnumLiteral( Enum.valueOf( namedClass, getLocalName() ), - (EnumJavaType) creationState.getCreationContext().getJpaMetamodel().getTypeConfiguration().getJavaTypeRegistry().resolveDescriptor( + (EnumJavaType) creationState.getCreationContext().getTypeConfiguration().getJavaTypeRegistry().resolveDescriptor( namedClass, () -> new EnumJavaType( namedClass ) ), @@ -112,7 +112,7 @@ public class FullyQualifiedReflectivePathTerminal final Field field = namedClass.getField( getLocalName() ); return new SqmFieldLiteral( field, - creationState.getCreationContext().getJpaMetamodel().getTypeConfiguration().getJavaTypeRegistry().resolveDescriptor( + creationState.getCreationContext().getTypeConfiguration().getJavaTypeRegistry().resolveDescriptor( namedClass, () -> new EnumJavaType( namedClass ) ), diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java index ecb73c0606..c2f75058d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java @@ -40,8 +40,6 @@ import org.hibernate.query.sqm.tree.domain.SqmMapJoin; import org.hibernate.query.sqm.tree.domain.SqmSetJoin; import org.hibernate.query.sqm.tree.domain.SqmSingularJoin; import org.hibernate.query.sqm.tree.domain.SqmTreatedPath; -import org.hibernate.query.sqm.tree.domain.SqmTreatedRoot; -import org.hibernate.query.sqm.tree.domain.SqmTreatedSimplePath; import org.hibernate.query.sqm.tree.expression.SqmAny; import org.hibernate.query.sqm.tree.expression.SqmEvery; import org.hibernate.query.sqm.tree.from.SqmCteJoin; @@ -217,7 +215,6 @@ public class QuerySplitter { SqmRoot unmappedPolymorphicFromElement, EntityDomainType mappedDescriptor, SessionFactoryImplementor sessionFactory) { - super( sessionFactory.getServiceRegistry() ); this.unmappedPolymorphicFromElement = unmappedPolymorphicFromElement; this.mappedDescriptor = mappedDescriptor; this.creationContext = sessionFactory; @@ -1291,7 +1288,7 @@ public class QuerySplitter { public Object visitAny(SqmAny sqmAny) { return new SqmAny<>( (SqmSubQuery) sqmAny.getSubquery().accept( this ), - this.creationContext.getNodeBuilder() + creationContext.getNodeBuilder() ); } @@ -1305,7 +1302,7 @@ public class QuerySplitter { sqmEvery.getSubquery().accept( this ); return new SqmEvery<>( (SqmSubQuery) sqmEvery.getSubquery().accept( this ), - this.creationContext.getNodeBuilder() + creationContext.getNodeBuilder() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index 81f5ae28a4..904585ccd0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -2919,8 +2919,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem (SqmExpression) ctx.getChild( 2 ).accept( this ) ), null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -2991,8 +2990,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("mod").generateSqmExpression( asList( left, right ), null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } else { @@ -3061,8 +3059,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("collate").generateSqmExpression( asList( expressionToCollate, castTargetExpression ), null, //why not string? - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -3169,8 +3166,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("current_date") .generateSqmExpression( resolveExpressibleTypeBasic( Date.class ), - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -3179,8 +3175,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("current_time") .generateSqmExpression( resolveExpressibleTypeBasic( Time.class ), - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -3189,8 +3184,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("current_timestamp") .generateSqmExpression( resolveExpressibleTypeBasic( Timestamp.class ), - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -3199,8 +3193,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("instant") .generateSqmExpression( resolveExpressibleTypeBasic( Instant.class ), - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -3209,8 +3202,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("local_date") .generateSqmExpression( resolveExpressibleTypeBasic( LocalDate.class ), - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -3219,8 +3211,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("local_time") .generateSqmExpression( resolveExpressibleTypeBasic( LocalTime.class ), - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -3229,8 +3220,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("local_datetime") .generateSqmExpression( resolveExpressibleTypeBasic( LocalDateTime.class ), - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -3239,8 +3229,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("offset_datetime") .generateSqmExpression( resolveExpressibleTypeBasic( OffsetDateTime.class ), - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -3336,7 +3325,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem case HqlParser.TRUE: return booleanLiteral( true ); case HqlParser.NULL: - return new SqmLiteralNull<>( creationContext.getQueryEngine().getCriteriaBuilder() ); + return new SqmLiteralNull<>( creationContext.getNodeBuilder() ); case HqlParser.BINARY_LITERAL: return binaryLiteral( node.getText() ); default: @@ -3827,7 +3816,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem } private BasicType resolveExpressibleTypeBasic(Class javaType) { - return creationContext.getJpaMetamodel().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); + return creationContext.getTypeConfiguration().standardBasicTypeForJavaType( javaType ); } @Override @@ -3907,8 +3896,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return functionTemplate.generateSqmExpression( functionArguments, null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -3953,8 +3941,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem ? null // this is allowed for e.g. rank(), but not for all : visitOrderByClause( ctx.withinGroupClause().orderByClause(), false ), null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); break; case AGGREGATE: @@ -3962,8 +3949,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem functionArguments, filterExpression, null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); break; case WINDOW: @@ -3973,16 +3959,14 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem null, null, null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); break; default: function = functionTemplate.generateSqmExpression( functionArguments, null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); break; } @@ -4102,8 +4086,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem ? null // this is allowed : visitOrderByClause( ctx.withinGroupClause().orderByClause(), false ), null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ) ); } @@ -4372,7 +4355,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem // expressionToExtract, // null, // creationContext.getQueryEngine(), -// creationContext.getJpaMetamodel().getTypeConfiguration() +// creationContext.getTypeConfiguration() // ); // } } @@ -4380,8 +4363,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("extract").generateSqmExpression( asList( extractFieldExpression, expressionToExtract ), extractFieldExpression.getType(), - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -4399,8 +4381,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor( "trunc" ).generateSqmExpression( secondArg == null ? singletonList( expression ) : asList( expression, secondArg ), null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -4422,8 +4403,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("format").generateSqmExpression( asList( expressionToCast, format ), null, //why not string? - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -4435,8 +4415,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("cast").generateSqmExpression( asList( expressionToCast, castTargetExpression ), castTargetExpression.getType(), - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -4459,7 +4438,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return new SqmCastTarget<>( (ReturnableType) - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getTypeConfiguration() .resolveCastTargetType( targetName ), //TODO: is there some way to interpret as length vs precision/scale here at this point? length, @@ -4477,8 +4456,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("position").generateSqmExpression( asList( pattern, string ), null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -4500,8 +4478,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem ? asList( string, replacement, start ) : asList( string, replacement, start, length ), null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -4522,8 +4499,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem singletonList( argument ), getFilterExpression( ctx ), resolveExpressibleTypeBasic( Boolean.class ), - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ) ); } @@ -4558,8 +4534,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem singletonList( argument ), getFilterExpression( ctx ), resolveExpressibleTypeBasic( Boolean.class ), - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ) ); } @@ -4809,8 +4784,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem return getFunctionDescriptor("substring").generateSqmExpression( length == null ? asList( source, start ) : asList( source, start, length ), null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -4831,8 +4805,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem ? asList( source, length, padSpec, padChar ) : asList( source, length, padSpec ), null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } @@ -4891,8 +4864,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem source ), null, - creationContext.getQueryEngine(), - creationContext.getJpaMetamodel().getTypeConfiguration() + creationContext.getQueryEngine() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/NamedResultSetMappingMementoImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/NamedResultSetMappingMementoImpl.java index a73dd9e860..e7e479e93d 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/NamedResultSetMappingMementoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/NamedResultSetMappingMementoImpl.java @@ -14,7 +14,7 @@ import org.hibernate.query.named.ResultMemento; import org.hibernate.query.results.ResultSetMapping; /** - * Standard `NamedResultSetMappingMemento` implementation + * Standard {@link NamedResultSetMappingMemento} implementation * * @author Steve Ebersole */ diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java index e636709f24..74f78e9242 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java @@ -216,7 +216,7 @@ public class ParameterMetadataImpl implements ParameterMetadataImplementor { return (QueryParameterImplementor

) param; } - final String errorMessage = "Could not resolve jakarta.persistence.Parameter `" + param + "` to org.hibernate.query.QueryParameter"; + final String errorMessage = "Could not resolve jakarta.persistence.Parameter '" + param + "' to org.hibernate.query.QueryParameter"; throw new IllegalArgumentException( errorMessage, new UnknownParameterException( errorMessage ) diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryEngineImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryEngineImpl.java new file mode 100644 index 0000000000..27712f40ae --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryEngineImpl.java @@ -0,0 +1,307 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.query.internal; + +import org.hibernate.boot.model.FunctionContributions; +import org.hibernate.boot.model.FunctionContributor; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.dialect.Dialect; +import org.hibernate.engine.query.spi.NativeQueryInterpreter; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.util.config.ConfigurationHelper; +import org.hibernate.query.hql.HqlTranslator; +import org.hibernate.query.hql.internal.StandardHqlTranslator; +import org.hibernate.query.hql.spi.SqmCreationOptions; +import org.hibernate.query.named.NamedObjectRepository; +import org.hibernate.query.spi.QueryEngine; +import org.hibernate.query.spi.QueryEngineOptions; +import org.hibernate.query.spi.QueryInterpretationCache; +import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.query.sqm.function.SqmFunctionRegistry; +import org.hibernate.query.sqm.internal.SqmCreationOptionsStandard; +import org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder; +import org.hibernate.query.sqm.spi.SqmCreationContext; +import org.hibernate.query.sqm.sql.SqmTranslatorFactory; +import org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.stat.spi.StatisticsImplementor; +import org.hibernate.type.spi.TypeConfiguration; +import org.jboss.logging.Logger; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +import static java.util.Comparator.comparingInt; + +/** + * Aggregation and encapsulation of the components Hibernate uses + * to execute queries (HQL, Criteria and native) + * + * @author Steve Ebersole + */ +public class QueryEngineImpl implements QueryEngine { + + /** + * The default soft reference count. + */ + public static final int DEFAULT_QUERY_PLAN_MAX_COUNT = 2048; + + private static final Logger LOG_HQL_FUNCTIONS = CoreLogging.logger("org.hibernate.HQL_FUNCTIONS"); + + public static QueryEngine from(SessionFactoryImplementor sessionFactory, MetadataImplementor metadata) { + final QueryEngineOptions options = sessionFactory.getSessionFactoryOptions(); + final Dialect dialect = sessionFactory.getJdbcServices().getDialect(); + return new QueryEngineImpl( + sessionFactory, + metadata.getTypeConfiguration(), + resolveHqlTranslator( options, dialect, sessionFactory, new SqmCreationOptionsStandard( options ) ), + resolveSqmTranslatorFactory( options, dialect ), + createFunctionRegistry( sessionFactory, metadata, options, dialect ), + metadata.buildNamedQueryRepository( sessionFactory ), + buildInterpretationCache( sessionFactory::getStatistics, sessionFactory.getProperties() ), + sessionFactory.getServiceRegistry().getService(NativeQueryInterpreter.class) + ); + } + + private static SqmFunctionRegistry createFunctionRegistry( + SessionFactoryImplementor sessionFactory, + MetadataImplementor metadata, + QueryEngineOptions queryEngineOptions, + Dialect dialect) { + final SqmFunctionRegistry sqmFunctionRegistry = metadata.getFunctionRegistry(); + + queryEngineOptions.getCustomSqlFunctionMap().forEach( sqmFunctionRegistry::register ); + + final SqmFunctionRegistry customSqmFunctionRegistry = queryEngineOptions.getCustomSqmFunctionRegistry(); + if ( customSqmFunctionRegistry != null ) { + customSqmFunctionRegistry.overlay( sqmFunctionRegistry ); + } + + //TODO: probably better to turn this back into an anonymous class + final FunctionContributions functionContributions = new QueryEngineImpl.FunctionContributionsImpl( + sessionFactory.getServiceRegistry(), + metadata.getTypeConfiguration(), + sqmFunctionRegistry + ); + for ( FunctionContributor contributor : sortedFunctionContributors( sessionFactory.getServiceRegistry() ) ) { + contributor.contributeFunctions( functionContributions ); + } + + dialect.initializeFunctionRegistry( functionContributions ); + + if ( LOG_HQL_FUNCTIONS.isDebugEnabled() ) { + sqmFunctionRegistry.getFunctionsByName().forEach( + entry -> LOG_HQL_FUNCTIONS.debug( entry.getValue().getSignature( entry.getKey() ) ) + ); + } + + return sqmFunctionRegistry; + } + + private final TypeConfiguration typeConfiguration; + private final NamedObjectRepository namedObjectRepository; + private final NativeQueryInterpreter nativeQueryInterpreter; + private final QueryInterpretationCache interpretationCache; + private final NodeBuilder criteriaBuilder; + private final HqlTranslator hqlTranslator; + private final SqmTranslatorFactory sqmTranslatorFactory; + private final SqmFunctionRegistry sqmFunctionRegistry; + + private QueryEngineImpl( + SessionFactoryImplementor sessionFactory, + TypeConfiguration typeConfiguration, + HqlTranslator hqlTranslator, + SqmTranslatorFactory sqmTranslatorFactory, + SqmFunctionRegistry functionRegistry, + NamedObjectRepository namedObjectRepository, + QueryInterpretationCache interpretationCache, + NativeQueryInterpreter nativeQueryInterpreter) { + this.typeConfiguration = typeConfiguration; + this.sqmFunctionRegistry = functionRegistry; + this.sqmTranslatorFactory = sqmTranslatorFactory; + this.hqlTranslator = hqlTranslator; + this.namedObjectRepository = namedObjectRepository; + this.interpretationCache = interpretationCache; + this.nativeQueryInterpreter = nativeQueryInterpreter; + final SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions(); + this.criteriaBuilder = new SqmCriteriaNodeBuilder( + sessionFactory.getUuid(), + sessionFactory.getName(), + this, + sessionFactoryOptions.getJpaCompliance().isJpaQueryComplianceEnabled(), + sessionFactoryOptions.getCriteriaValueHandlingMode(), + () -> sessionFactory + ); + } + + private static HqlTranslator resolveHqlTranslator( + QueryEngineOptions runtimeOptions, + Dialect dialect, + SqmCreationContext sqmCreationContext, + SqmCreationOptions sqmCreationOptions) { + if ( runtimeOptions.getCustomHqlTranslator() != null ) { + return runtimeOptions.getCustomHqlTranslator(); + } + else if ( dialect.getHqlTranslator() != null ) { + return dialect.getHqlTranslator(); + } + else { + return new StandardHqlTranslator( sqmCreationContext, sqmCreationOptions ); + } + } + + private static SqmTranslatorFactory resolveSqmTranslatorFactory( + QueryEngineOptions runtimeOptions, + Dialect dialect) { + if ( runtimeOptions.getCustomSqmTranslatorFactory() != null ) { + return runtimeOptions.getCustomSqmTranslatorFactory(); + } + else if ( dialect.getSqmTranslatorFactory() != null ) { + return dialect.getSqmTranslatorFactory(); + } + else { + return new StandardSqmTranslatorFactory(); + } + } + + private static List sortedFunctionContributors(ServiceRegistry serviceRegistry) { + Collection functionContributors = + serviceRegistry.getService(ClassLoaderService.class) + .loadJavaServices(FunctionContributor.class); + List contributors = new ArrayList<>( functionContributors ); + contributors.sort( + comparingInt( FunctionContributor::ordinal ) + .thenComparing( a -> a.getClass().getCanonicalName() ) + ); + return contributors; + } + + private static QueryInterpretationCache buildInterpretationCache( + Supplier statisticsSupplier, + Map properties) { + final boolean explicitUseCache = ConfigurationHelper.getBoolean( + AvailableSettings.QUERY_PLAN_CACHE_ENABLED, + properties, + // enabled by default + true + ); + + final Integer explicitMaxPlanSize = ConfigurationHelper.getInteger( + AvailableSettings.QUERY_PLAN_CACHE_MAX_SIZE, + properties + ); + + if ( explicitUseCache || explicitMaxPlanSize != null && explicitMaxPlanSize > 0 ) { + final int size = explicitMaxPlanSize != null + ? explicitMaxPlanSize + : DEFAULT_QUERY_PLAN_MAX_COUNT; + + return new QueryInterpretationCacheStandardImpl( size, statisticsSupplier ); + } + else { + // disabled + return new QueryInterpretationCacheDisabledImpl( statisticsSupplier ); + } + } + + @Override + public void validateNamedQueries() { + namedObjectRepository.validateNamedQueries( this ); + } + + @Override + public NamedObjectRepository getNamedObjectRepository() { + return namedObjectRepository; + } + + @Override + public TypeConfiguration getTypeConfiguration() { + return typeConfiguration; + } + + @Override + public NodeBuilder getCriteriaBuilder() { + return criteriaBuilder; + } + + public HqlTranslator getHqlTranslator() { + return hqlTranslator; + } + + @Override + public SqmTranslatorFactory getSqmTranslatorFactory() { + return sqmTranslatorFactory; + } + + @Override + public NativeQueryInterpreter getNativeQueryInterpreter() { + return nativeQueryInterpreter; + } + + @Override + public QueryInterpretationCache getInterpretationCache() { + return interpretationCache; + } + + @Override + public SqmFunctionRegistry getSqmFunctionRegistry() { + return sqmFunctionRegistry; + } + + @Override + public void close() { + if ( namedObjectRepository != null ) { + namedObjectRepository.close(); + } + + if ( interpretationCache != null ) { + interpretationCache.close(); + } + + if ( sqmFunctionRegistry != null ) { + sqmFunctionRegistry.close(); + } + } + + private static class FunctionContributionsImpl implements FunctionContributions { + private final ServiceRegistry serviceRegistry; + private final TypeConfiguration typeConfiguration; + private final SqmFunctionRegistry functionRegistry; + + public FunctionContributionsImpl( + ServiceRegistry serviceRegistry, + TypeConfiguration typeConfiguration, + SqmFunctionRegistry functionRegistry) { + this.serviceRegistry = serviceRegistry; + this.typeConfiguration = typeConfiguration; + this.functionRegistry = functionRegistry; + } + + @Override + public TypeConfiguration getTypeConfiguration() { + return typeConfiguration; + } + + @Override + public SqmFunctionRegistry getFunctionRegistry() { + return functionRegistry; + } + + @Override + public ServiceRegistry getServiceRegistry() { + return serviceRegistry; + } + } + +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/ResultMementoBasicStandard.java b/hibernate-core/src/main/java/org/hibernate/query/internal/ResultMementoBasicStandard.java index a4b2dd5f88..7781442b3c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/ResultMementoBasicStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/ResultMementoBasicStandard.java @@ -30,25 +30,29 @@ import jakarta.persistence.AttributeConverter; import jakarta.persistence.ColumnResult; /** - * Implementation of ResultMappingMemento for scalar (basic) results. - * - * Ultimately a scalar result is defined as a column name and a BasicType with the following notes:

    + * Implementation of {@link ResultMementoBasic} for scalar (basic) results. + *

    + * Ultimately a scalar result is defined as a column name and a {@link BasicType} + * with the following notes: + *

      *
    • - * For JPA mappings, the column name is required. For `hbm.xml` mappings, it is optional (positional) + * For JPA mappings, the column name is required. For {@code hbm.xml} + * mappings, it is optional (positional) *
    • *
    • - * Ultimately, when reading values, we need the {@link BasicType}. We know the BasicType in a few - * different ways:
        + * Ultimately, when reading values, we need the {@link BasicType}. We + * know the {@code BasicType} in a few different ways:
          *
        • - * If we know an explicit Type, that is used. + * If we know an explicit {@code Type}, that is used. *
        • *
        • - * If we do not know the Type, but do know the Java type then we determine the BasicType - * based on the reported SQL type and its known mapping to the specified Java type + * If we do not know the {@code Type}, but do know the Java type + * then we determine the {@code BasicType} based on the reported + * SQL type and its known mapping to the specified Java type *
        • *
        • - * If we know neither, we use the reported SQL type and its recommended Java type to - * resolve the BasicType to use + * If we know neither, we use the reported SQL type and its + * recommended Java type to resolve the {@code BasicType} to use *
        • *
        * @@ -62,7 +66,7 @@ public class ResultMementoBasicStandard implements ResultMementoBasic { private final ResultBuilderBasicValued builder; /** - * Creation of ScalarResultMappingMemento for JPA descriptor + * Creation for JPA descriptor */ public ResultMementoBasicStandard( ColumnResult definition, diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java index 2832dd6cb5..d7c23cb18e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java @@ -6,301 +6,43 @@ */ package org.hibernate.query.spi; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.function.Supplier; - import org.hibernate.Incubating; -import org.hibernate.boot.Metadata; -import org.hibernate.boot.model.FunctionContributions; -import org.hibernate.boot.model.FunctionContributor; -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.boot.spi.MetadataImplementor; -import org.hibernate.boot.spi.SessionFactoryOptions; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.dialect.Dialect; import org.hibernate.engine.query.spi.NativeQueryInterpreter; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.internal.CoreLogging; -import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.query.hql.HqlTranslator; -import org.hibernate.query.hql.internal.StandardHqlTranslator; -import org.hibernate.query.hql.spi.SqmCreationOptions; -import org.hibernate.query.internal.QueryInterpretationCacheDisabledImpl; -import org.hibernate.query.internal.QueryInterpretationCacheStandardImpl; import org.hibernate.query.named.NamedObjectRepository; +import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.function.SqmFunctionRegistry; -import org.hibernate.query.sqm.internal.SqmCreationOptionsStandard; -import org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder; -import org.hibernate.query.sqm.spi.SqmCreationContext; import org.hibernate.query.sqm.sql.SqmTranslatorFactory; -import org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory; -import org.hibernate.service.ServiceRegistry; -import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.type.spi.TypeConfiguration; -import org.jboss.logging.Logger; - -import static java.util.Comparator.comparingInt; - /** * Aggregation and encapsulation of the components Hibernate uses * to execute queries (HQL, Criteria and native) * * @author Steve Ebersole + * @author Gavin King */ @Incubating -public class QueryEngine { +public interface QueryEngine { - /** - * The default soft reference count. - */ - public static final int DEFAULT_QUERY_PLAN_MAX_COUNT = 2048; + NativeQueryInterpreter getNativeQueryInterpreter(); - private static final Logger LOG_HQL_FUNCTIONS = CoreLogging.logger( "org.hibernate.HQL_FUNCTIONS" ); + QueryInterpretationCache getInterpretationCache(); - public static QueryEngine from(SessionFactoryImplementor sessionFactory, MetadataImplementor metadata) { - final QueryEngineOptions options = sessionFactory.getSessionFactoryOptions(); - final Dialect dialect = sessionFactory.getJdbcServices().getDialect(); - return new QueryEngine( - sessionFactory, - metadata.getTypeConfiguration(), - resolveHqlTranslator( options, dialect, sessionFactory, new SqmCreationOptionsStandard( options ) ), - resolveSqmTranslatorFactory( options, dialect ), - createFunctionRegistry( sessionFactory, metadata, options, dialect ), - metadata.buildNamedQueryRepository( sessionFactory ), - buildInterpretationCache( sessionFactory::getStatistics, sessionFactory.getProperties() ) - ); - } + SqmFunctionRegistry getSqmFunctionRegistry(); - private static SqmFunctionRegistry createFunctionRegistry( - SessionFactoryImplementor sessionFactory, - MetadataImplementor metadata, - QueryEngineOptions queryEngineOptions, - Dialect dialect) { - final SqmFunctionRegistry sqmFunctionRegistry = metadata.getFunctionRegistry(); + TypeConfiguration getTypeConfiguration(); - queryEngineOptions.getCustomSqlFunctionMap().forEach( sqmFunctionRegistry::register ); + NodeBuilder getCriteriaBuilder(); - final SqmFunctionRegistry customSqmFunctionRegistry = queryEngineOptions.getCustomSqmFunctionRegistry(); - if ( customSqmFunctionRegistry != null ) { - customSqmFunctionRegistry.overlay( sqmFunctionRegistry ); - } + void close(); - //TODO: probably better to turn this back into an anonymous class - final FunctionContributions functionContributions = new FunctionContributionsImpl( - sessionFactory.getServiceRegistry(), - metadata.getTypeConfiguration(), - sqmFunctionRegistry - ); - for ( FunctionContributor contributor : sortedFunctionContributors( sessionFactory.getServiceRegistry() ) ) { - contributor.contributeFunctions( functionContributions ); - } + void validateNamedQueries(); - dialect.initializeFunctionRegistry( functionContributions ); + NamedObjectRepository getNamedObjectRepository(); - if ( LOG_HQL_FUNCTIONS.isDebugEnabled() ) { - sqmFunctionRegistry.getFunctionsByName().forEach( - entry -> LOG_HQL_FUNCTIONS.debug( entry.getValue().getSignature( entry.getKey() ) ) - ); - } - - return sqmFunctionRegistry; - } - - private final NamedObjectRepository namedObjectRepository; - private final NativeQueryInterpreter nativeQueryInterpreter; - private final QueryInterpretationCache interpretationCache; - private final SqmCriteriaNodeBuilder criteriaBuilder; - private final HqlTranslator hqlTranslator; - private final SqmTranslatorFactory sqmTranslatorFactory; - private final SqmFunctionRegistry sqmFunctionRegistry; - private final TypeConfiguration typeConfiguration; - - private QueryEngine( - SessionFactoryImplementor sessionFactory, - TypeConfiguration typeConfiguration, - HqlTranslator hqlTranslator, - SqmTranslatorFactory sqmTranslatorFactory, - SqmFunctionRegistry functionRegistry, - NamedObjectRepository namedObjectRepository, - QueryInterpretationCache interpretationCache) { - this.typeConfiguration = typeConfiguration; - this.sqmFunctionRegistry = functionRegistry; - this.sqmTranslatorFactory = sqmTranslatorFactory; - this.hqlTranslator = hqlTranslator; - this.namedObjectRepository = namedObjectRepository; - this.interpretationCache = interpretationCache; - this.nativeQueryInterpreter = sessionFactory.getServiceRegistry().getService( NativeQueryInterpreter.class ); - final SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions(); - this.criteriaBuilder = new SqmCriteriaNodeBuilder( - sessionFactory.getUuid(), - sessionFactory.getName(), - this, - sessionFactoryOptions.getJpaCompliance().isJpaQueryComplianceEnabled(), - sessionFactoryOptions.getCriteriaValueHandlingMode(), - sessionFactory.getServiceRegistry(), - () -> sessionFactory - ); - } - - private static HqlTranslator resolveHqlTranslator( - QueryEngineOptions runtimeOptions, - Dialect dialect, - SqmCreationContext sqmCreationContext, - SqmCreationOptions sqmCreationOptions) { - if ( runtimeOptions.getCustomHqlTranslator() != null ) { - return runtimeOptions.getCustomHqlTranslator(); - } - else if ( dialect.getHqlTranslator() != null ) { - return dialect.getHqlTranslator(); - } - else { - return new StandardHqlTranslator( sqmCreationContext, sqmCreationOptions ); - } - } - - private static SqmTranslatorFactory resolveSqmTranslatorFactory( - QueryEngineOptions runtimeOptions, - Dialect dialect) { - if ( runtimeOptions.getCustomSqmTranslatorFactory() != null ) { - return runtimeOptions.getCustomSqmTranslatorFactory(); - } - else if ( dialect.getSqmTranslatorFactory() != null ) { - return dialect.getSqmTranslatorFactory(); - } - else { - return new StandardSqmTranslatorFactory(); - } - } - - private static List sortedFunctionContributors(ServiceRegistry serviceRegistry) { - List contributors = new ArrayList<>( - serviceRegistry.getService( ClassLoaderService.class ) - .loadJavaServices( FunctionContributor.class ) ); - contributors.sort( comparingInt( FunctionContributor::ordinal ) - .thenComparing( a -> a.getClass().getCanonicalName() ) ); - return contributors; - } - - private static QueryInterpretationCache buildInterpretationCache( - Supplier statisticsSupplier, - Map properties) { - final boolean explicitUseCache = ConfigurationHelper.getBoolean( - AvailableSettings.QUERY_PLAN_CACHE_ENABLED, - properties, - // enabled by default - true - ); - - final Integer explicitMaxPlanSize = ConfigurationHelper.getInteger( - AvailableSettings.QUERY_PLAN_CACHE_MAX_SIZE, - properties - ); - - if ( explicitUseCache || ( explicitMaxPlanSize != null && explicitMaxPlanSize > 0 ) ) { - final int size = explicitMaxPlanSize != null - ? explicitMaxPlanSize - : DEFAULT_QUERY_PLAN_MAX_COUNT; - - return new QueryInterpretationCacheStandardImpl( size, statisticsSupplier ); - } - else { - // disabled - return new QueryInterpretationCacheDisabledImpl( statisticsSupplier ); - } - } - - public void prepare(SessionFactoryImplementor sessionFactory, Metadata bootMetamodel) { - namedObjectRepository.prepare( sessionFactory, bootMetamodel ); - } - - public void validateNamedQueries() { - namedObjectRepository.validateNamedQueries( this ); - } - public NamedObjectRepository getNamedObjectRepository() { - return namedObjectRepository; - } - - public SqmCriteriaNodeBuilder getCriteriaBuilder() { - return criteriaBuilder; - } - - public HqlTranslator getHqlTranslator() { - return hqlTranslator; - } - - public SqmTranslatorFactory getSqmTranslatorFactory() { - return sqmTranslatorFactory; - } - - public NativeQueryInterpreter getNativeQueryInterpreter() { - return nativeQueryInterpreter; - } - - public QueryInterpretationCache getInterpretationCache() { - return interpretationCache; - } - - public SqmFunctionRegistry getSqmFunctionRegistry() { - return sqmFunctionRegistry; - } - - public TypeConfiguration getTypeConfiguration() { - return typeConfiguration; - } - - public void close() { - if ( namedObjectRepository != null ) { - namedObjectRepository.close(); - } - - if ( criteriaBuilder != null ) { - criteriaBuilder.close(); - } - - if ( hqlTranslator != null ) { - hqlTranslator.close(); - } - - if ( interpretationCache != null ) { - interpretationCache.close(); - } - - if ( sqmFunctionRegistry != null ) { - sqmFunctionRegistry.close(); - } - } - - private static class FunctionContributionsImpl implements FunctionContributions { - private final ServiceRegistry serviceRegistry; - private final TypeConfiguration typeConfiguration; - private final SqmFunctionRegistry functionRegistry; - - public FunctionContributionsImpl( - ServiceRegistry serviceRegistry, - TypeConfiguration typeConfiguration, - SqmFunctionRegistry functionRegistry) { - this.serviceRegistry = serviceRegistry; - this.typeConfiguration = typeConfiguration; - this.functionRegistry = functionRegistry; - } - - @Override - public TypeConfiguration getTypeConfiguration() { - return typeConfiguration; - } - - @Override - public SqmFunctionRegistry getFunctionRegistry() { - return functionRegistry; - } - - @Override - public ServiceRegistry getServiceRegistry() { - return serviceRegistry; - } - } + HqlTranslator getHqlTranslator(); + SqmTranslatorFactory getSqmTranslatorFactory(); } + diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java index beb5ba8f2d..cd94c662a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java @@ -432,10 +432,6 @@ public class NativeQueryImpl return callback; } - public SessionFactoryImplementor getSessionFactory() { - return getSession().getFactory(); - } - @Override public QueryParameterBindings getQueryParameterBindings() { return parameterBindings; @@ -661,8 +657,7 @@ public class NativeQueryImpl } }; - return getSessionFactory().getQueryEngine() - .getNativeQueryInterpreter() + return getSessionFactory().getQueryEngine().getNativeQueryInterpreter() .createQueryPlan( queryDefinition, getSessionFactory() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java index 822064ab7e..b728bca0f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java @@ -24,7 +24,6 @@ import org.hibernate.query.criteria.JpaCoalesce; import org.hibernate.query.criteria.JpaCompoundSelection; import org.hibernate.query.criteria.JpaExpression; import org.hibernate.query.criteria.JpaParameterExpression; -import org.hibernate.query.criteria.JpaPath; import org.hibernate.query.criteria.JpaSearchedCase; import org.hibernate.query.criteria.JpaSelection; import org.hibernate.query.criteria.JpaSimpleCase; @@ -48,7 +47,6 @@ import org.hibernate.query.sqm.tree.select.SqmSelectStatement; import org.hibernate.query.sqm.tree.select.SqmSortSpecification; import org.hibernate.query.sqm.tree.select.SqmSubQuery; import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; -import org.hibernate.service.ServiceRegistry; import org.hibernate.type.BasicType; import org.hibernate.type.spi.TypeConfiguration; @@ -78,8 +76,6 @@ public interface NodeBuilder extends HibernateCriteriaBuilder { boolean isJpaQueryComplianceEnabled(); - ServiceRegistry getServiceRegistry(); - QueryEngine getQueryEngine(); SqmTuple tuple( @@ -135,7 +131,7 @@ public interface NodeBuilder extends HibernateCriteriaBuilder { SqmInsertSelectStatement createCriteriaInsertSelect(Class targetEntity); @Override - SqmExpression abs(Expression x); + SqmExpression abs(Expression x); @Override SqmExpression cast(JpaExpression expression, Class castTargetJavaType); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmFunctionDescriptor.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmFunctionDescriptor.java index 25aa11832f..ea37a65dfd 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmFunctionDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmFunctionDescriptor.java @@ -19,7 +19,6 @@ import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolv import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; import org.hibernate.query.sqm.tree.select.SqmOrderByClause; -import org.hibernate.type.spi.TypeConfiguration; /** * @author Steve Ebersole @@ -99,15 +98,13 @@ public abstract class AbstractSqmFunctionDescriptor implements SqmFunctionDescri public final SelfRenderingSqmFunction generateSqmExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { - argumentsValidator.validate( arguments, getName(), typeConfiguration ); + QueryEngine queryEngine) { + argumentsValidator.validate( arguments, getName(), queryEngine.getTypeConfiguration() ); return generateSqmFunctionExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } @@ -116,16 +113,14 @@ public abstract class AbstractSqmFunctionDescriptor implements SqmFunctionDescri List> arguments, SqmPredicate filter, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { - argumentsValidator.validate( arguments, getName(), typeConfiguration ); + QueryEngine queryEngine) { + argumentsValidator.validate( arguments, getName(), queryEngine.getTypeConfiguration() ); return generateSqmAggregateFunctionExpression( arguments, filter, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } @@ -135,17 +130,15 @@ public abstract class AbstractSqmFunctionDescriptor implements SqmFunctionDescri SqmPredicate filter, SqmOrderByClause withinGroupClause, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { - argumentsValidator.validate( arguments, getName(), typeConfiguration ); + QueryEngine queryEngine) { + argumentsValidator.validate( arguments, getName(), queryEngine.getTypeConfiguration() ); return generateSqmOrderedSetAggregateFunctionExpression( arguments, filter, withinGroupClause, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } @@ -156,9 +149,8 @@ public abstract class AbstractSqmFunctionDescriptor implements SqmFunctionDescri Boolean respectNulls, Boolean fromFirst, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { - argumentsValidator.validate( arguments, getName(), typeConfiguration ); + QueryEngine queryEngine) { + argumentsValidator.validate( arguments, getName(), queryEngine.getTypeConfiguration() ); return generateSqmWindowFunctionExpression( arguments, @@ -166,8 +158,7 @@ public abstract class AbstractSqmFunctionDescriptor implements SqmFunctionDescri respectNulls, fromFirst, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } @@ -175,34 +166,32 @@ public abstract class AbstractSqmFunctionDescriptor implements SqmFunctionDescri * Return an SQM node or subtree representing an invocation of this function * with the given arguments. This method may be overridden in the case of * function descriptors that wish to customize creation of the node. - * @param arguments the arguments of the function invocation + * + * @param arguments the arguments of the function invocation * @param impliedResultType the function return type as inferred from its usage */ protected abstract SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration); + QueryEngine queryEngine); /** * Return an SQM node or subtree representing an invocation of this aggregate function * with the given arguments. This method may be overridden in the case of * function descriptors that wish to customize creation of the node. * - * @param arguments the arguments of the function invocation + * @param arguments the arguments of the function invocation * @param impliedResultType the function return type as inferred from its usage */ protected SelfRenderingSqmAggregateFunction generateSqmAggregateFunctionExpression( List> arguments, SqmPredicate filter, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return (SelfRenderingSqmAggregateFunction) generateSqmExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } @@ -211,7 +200,7 @@ public abstract class AbstractSqmFunctionDescriptor implements SqmFunctionDescri * with the given arguments. This method may be overridden in the case of * function descriptors that wish to customize creation of the node. * - * @param arguments the arguments of the function invocation + * @param arguments the arguments of the function invocation * @param impliedResultType the function return type as inferred from its usage */ protected SelfRenderingSqmAggregateFunction generateSqmOrderedSetAggregateFunctionExpression( @@ -219,13 +208,11 @@ public abstract class AbstractSqmFunctionDescriptor implements SqmFunctionDescri SqmPredicate filter, SqmOrderByClause withinGroupClause, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return (SelfRenderingSqmAggregateFunction) generateSqmExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } @@ -234,7 +221,7 @@ public abstract class AbstractSqmFunctionDescriptor implements SqmFunctionDescri * with the given arguments. This method may be overridden in the case of * function descriptors that wish to customize creation of the node. * - * @param arguments the arguments of the function invocation + * @param arguments the arguments of the function invocation * @param respectNulls * @param fromFirst * @param impliedResultType the function return type as inferred from its usage @@ -245,13 +232,11 @@ public abstract class AbstractSqmFunctionDescriptor implements SqmFunctionDescri Boolean respectNulls, Boolean fromFirst, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return (SelfRenderingSqmWindowFunction) generateSqmExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmSelfRenderingFunctionDescriptor.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmSelfRenderingFunctionDescriptor.java index 7713c6757b..fea4ee4325 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmSelfRenderingFunctionDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmSelfRenderingFunctionDescriptor.java @@ -14,7 +14,6 @@ import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver; import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; import org.hibernate.query.sqm.tree.select.SqmOrderByClause; -import org.hibernate.type.spi.TypeConfiguration; import java.util.List; @@ -54,8 +53,7 @@ public abstract class AbstractSqmSelfRenderingFunctionDescriptor protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { switch ( functionKind ) { case ORDERED_SET_AGGREGATE: return generateOrderedSetAggregateSqmExpression( @@ -63,16 +61,14 @@ public abstract class AbstractSqmSelfRenderingFunctionDescriptor null, null, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); case AGGREGATE: return generateAggregateSqmExpression( arguments, null, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); case WINDOW: return generateWindowSqmExpression( @@ -81,8 +77,7 @@ public abstract class AbstractSqmSelfRenderingFunctionDescriptor null, null, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); default: return new SelfRenderingSqmFunction<>( @@ -103,8 +98,7 @@ public abstract class AbstractSqmSelfRenderingFunctionDescriptor List> arguments, SqmPredicate filter, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { if ( functionKind != FunctionKind.AGGREGATE ) { throw new UnsupportedOperationException( "The function " + getName() + " is not an aggregate function" ); } @@ -127,8 +121,7 @@ public abstract class AbstractSqmSelfRenderingFunctionDescriptor SqmPredicate filter, SqmOrderByClause withinGroupClause, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { if ( functionKind != FunctionKind.ORDERED_SET_AGGREGATE ) { throw new UnsupportedOperationException( "The function " + getName() + " is not an ordered set-aggregate function" ); } @@ -153,8 +146,7 @@ public abstract class AbstractSqmSelfRenderingFunctionDescriptor Boolean respectNulls, Boolean fromFirst, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { if ( functionKind != FunctionKind.WINDOW ) { throw new UnsupportedOperationException( "The function " + getName() + " is not a window function" ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/JdbcEscapeFunctionDescriptor.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/JdbcEscapeFunctionDescriptor.java index ac42420ca4..cde831c73d 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/JdbcEscapeFunctionDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/JdbcEscapeFunctionDescriptor.java @@ -9,7 +9,6 @@ package org.hibernate.query.sqm.function; import org.hibernate.query.ReturnableType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.tree.SqmTypedNode; -import org.hibernate.type.spi.TypeConfiguration; import java.util.List; @@ -34,15 +33,13 @@ public class JdbcEscapeFunctionDescriptor protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { final SelfRenderingSqmFunction delegate = wrapped.generateSqmExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); return new SelfRenderingSqmFunction<>( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/MultipatternSqmFunctionDescriptor.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/MultipatternSqmFunctionDescriptor.java index 5cdb4d61d0..3819be976b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/MultipatternSqmFunctionDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/MultipatternSqmFunctionDescriptor.java @@ -115,14 +115,12 @@ public class MultipatternSqmFunctionDescriptor extends AbstractSqmFunctionDescri protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return functions[ arguments.size() ] .generateSqmExpression( arguments, impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunctionDescriptor.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunctionDescriptor.java index 75517bd1b7..6ea894f98f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunctionDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunctionDescriptor.java @@ -12,7 +12,6 @@ import org.hibernate.query.sqm.produce.function.ArgumentsValidator; import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; import org.hibernate.query.sqm.tree.select.SqmOrderByClause; -import org.hibernate.type.spi.TypeConfiguration; import java.util.List; @@ -55,11 +54,10 @@ public interface SqmFunctionDescriptor { SelfRenderingSqmFunction generateSqmExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration); + QueryEngine queryEngine); /** - * Like {@link #generateSqmExpression(List, ReturnableType, QueryEngine, TypeConfiguration)}, + * Like {@link #generateSqmExpression(List, ReturnableType, QueryEngine)}, * but also accepts a {@code filter} predicate. *

        * This method is intended for aggregate functions. @@ -68,13 +66,12 @@ public interface SqmFunctionDescriptor { List> arguments, SqmPredicate filter, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { throw new UnsupportedOperationException( "Not an aggregate function" ); } /** - * Like {@link #generateSqmExpression(List, ReturnableType, QueryEngine, TypeConfiguration)}, + * Like {@link #generateSqmExpression(List, ReturnableType, QueryEngine)}, * but also accepts a {@code filter} predicate and an {@code order by} clause. *

        * This method is intended for ordered set aggregate functions. @@ -84,13 +81,12 @@ public interface SqmFunctionDescriptor { SqmPredicate filter, SqmOrderByClause withinGroupClause, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { throw new UnsupportedOperationException( "Not an ordered set aggregate function" ); } /** - * Like {@link #generateSqmExpression(List, ReturnableType, QueryEngine, TypeConfiguration)} + * Like {@link #generateSqmExpression(List, ReturnableType, QueryEngine)} * but also accepts a {@code filter} predicate. *

        * This method is intended for window functions. @@ -101,8 +97,7 @@ public interface SqmFunctionDescriptor { Boolean respectNulls, Boolean fromFirst, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { throw new UnsupportedOperationException( "Not a window function" ); } @@ -112,13 +107,11 @@ public interface SqmFunctionDescriptor { default SelfRenderingSqmFunction generateSqmExpression( SqmTypedNode argument, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return generateSqmExpression( singletonList(argument), impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } @@ -127,13 +120,11 @@ public interface SqmFunctionDescriptor { */ default SelfRenderingSqmFunction generateSqmExpression( ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return generateSqmExpression( emptyList(), impliedResultType, - queryEngine, - typeConfiguration + queryEngine ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java index 19bc1f6a39..50bbeec9eb 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java @@ -15,8 +15,6 @@ import jakarta.persistence.Tuple; import org.hibernate.AssertionFailure; import org.hibernate.InstantiationException; import org.hibernate.ScrollMode; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; @@ -27,21 +25,17 @@ import org.hibernate.metamodel.mapping.MappingModelExpressible; import org.hibernate.query.Query; import org.hibernate.query.TupleTransformer; import org.hibernate.query.spi.DomainQueryExecutionContext; -import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.spi.QueryOptions; import org.hibernate.query.spi.QueryParameterImplementor; import org.hibernate.query.spi.ScrollableResultsImplementor; import org.hibernate.query.spi.SelectQueryPlan; import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess; import org.hibernate.query.sqm.sql.SqmTranslation; -import org.hibernate.query.sqm.sql.SqmTranslator; -import org.hibernate.query.sqm.sql.SqmTranslatorFactory; import org.hibernate.query.sqm.tree.expression.SqmParameter; import org.hibernate.query.sqm.tree.select.SqmDynamicInstantiation; import org.hibernate.query.sqm.tree.select.SqmSelectStatement; import org.hibernate.query.sqm.tree.select.SqmSelection; import org.hibernate.sql.ast.SqlAstTranslator; -import org.hibernate.sql.ast.SqlAstTranslatorFactory; import org.hibernate.sql.ast.spi.FromClauseAccess; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; @@ -336,33 +330,32 @@ public class ConcreteSqmSelectQueryPlan implements SelectQueryPlan { DomainQueryExecutionContext executionContext) { final SharedSessionContractImplementor session = executionContext.getSession(); final SessionFactoryImplementor sessionFactory = session.getFactory(); - final QueryEngine queryEngine = sessionFactory.getQueryEngine(); - final SqmTranslatorFactory sqmTranslatorFactory = queryEngine.getSqmTranslatorFactory(); + final SqmTranslation sqmInterpretation = + sessionFactory.getQueryEngine().getSqmTranslatorFactory() + .createSelectTranslator( + sqm, + executionContext.getQueryOptions(), + domainParameterXref, + executionContext.getQueryParameterBindings(), + executionContext.getSession().getLoadQueryInfluencers(), + sessionFactory, + true + ) + .translate(); - final SqmTranslator sqmConverter = sqmTranslatorFactory.createSelectTranslator( - sqm, - executionContext.getQueryOptions(), - domainParameterXref, - executionContext.getQueryParameterBindings(), - executionContext.getSession().getLoadQueryInfluencers(), - sessionFactory, - true - ); + final FromClauseAccess tableGroupAccess = sqmInterpretation.getFromClauseAccess(); - final SqmTranslation sqmInterpretation = sqmConverter.translate(); - final FromClauseAccess tableGroupAccess = sqmConverter.getFromClauseAccess(); - - final JdbcServices jdbcServices = sessionFactory.getJdbcServices(); - final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); - final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory(); - final SqlAstTranslator selectTranslator = sqlAstTranslatorFactory.buildSelectTranslator( - sessionFactory, - sqmInterpretation.getSqlAst() - ); + final SqlAstTranslator selectTranslator = + sessionFactory.getJdbcServices().getJdbcEnvironment().getSqlAstTranslatorFactory() + .buildSelectTranslator( + sessionFactory, + sqmInterpretation.getSqlAst() + ); final Map, Map, List>> jdbcParamsXref = SqmUtil.generateJdbcParamsXref( domainParameterXref, sqmInterpretation::getJdbcParamsBySqmParam ); + final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings( executionContext.getQueryParameterBindings(), domainParameterXref, @@ -377,11 +370,10 @@ public class ConcreteSqmSelectQueryPlan implements SelectQueryPlan { }, session ); - final JdbcOperationQuerySelect jdbcSelect = selectTranslator.translate( jdbcParameterBindings, executionContext.getQueryOptions() ); return new CacheableSqmInterpretation( sqmInterpretation.getSqlAst(), - jdbcSelect, + selectTranslator.translate( jdbcParameterBindings, executionContext.getQueryOptions() ), tableGroupAccess, jdbcParamsXref, sqmInterpretation.getSqmParameterMappingModelTypeResolutions(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleDeleteQueryPlan.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleDeleteQueryPlan.java index 9e39658ac3..8af42a7279 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleDeleteQueryPlan.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleDeleteQueryPlan.java @@ -19,20 +19,16 @@ import org.hibernate.metamodel.mapping.MappingModelExpressible; import org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper; import org.hibernate.query.spi.DomainQueryExecutionContext; import org.hibernate.query.spi.NonSelectQueryPlan; -import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.spi.QueryParameterImplementor; import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper; import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess; import org.hibernate.query.sqm.sql.SqmTranslation; -import org.hibernate.query.sqm.sql.SqmTranslator; -import org.hibernate.query.sqm.sql.SqmTranslatorFactory; import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; import org.hibernate.query.sqm.tree.expression.SqmParameter; import org.hibernate.spi.NavigablePath; import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.tree.delete.DeleteStatement; import org.hibernate.sql.ast.tree.expression.Expression; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.from.MutatingTableReferenceGroupWrapper; import org.hibernate.sql.ast.tree.from.NamedTableReference; import org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate; @@ -67,19 +63,18 @@ public class SimpleDeleteQueryPlan implements NonSelectQueryPlan { protected SqlAstTranslator createDeleteTranslator(DomainQueryExecutionContext executionContext) { final SessionFactoryImplementor factory = executionContext.getSession().getFactory(); - final QueryEngine queryEngine = factory.getQueryEngine(); - final SqmTranslatorFactory translatorFactory = queryEngine.getSqmTranslatorFactory(); - final SqmTranslator translator = translatorFactory.createSimpleDeleteTranslator( - sqmDelete, - executionContext.getQueryOptions(), - domainParameterXref, - executionContext.getQueryParameterBindings(), - executionContext.getSession().getLoadQueryInfluencers(), - factory - ); - - sqmInterpretation = translator.translate(); + sqmInterpretation = + factory.getQueryEngine().getSqmTranslatorFactory(). + createSimpleDeleteTranslator( + sqmDelete, + executionContext.getQueryOptions(), + domainParameterXref, + executionContext.getQueryParameterBindings(), + executionContext.getSession().getLoadQueryInfluencers(), + factory + ) + .translate(); this.jdbcParamsXref = SqmUtil.generateJdbcParamsXref( domainParameterXref, diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleInsertQueryPlan.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleInsertQueryPlan.java index 83c9b01ceb..a1f2b60c52 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleInsertQueryPlan.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleInsertQueryPlan.java @@ -16,17 +16,13 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.metamodel.mapping.MappingModelExpressible; import org.hibernate.query.spi.DomainQueryExecutionContext; import org.hibernate.query.spi.NonSelectQueryPlan; -import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.spi.QueryParameterImplementor; import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess; import org.hibernate.query.sqm.sql.SqmTranslation; -import org.hibernate.query.sqm.sql.SqmTranslator; -import org.hibernate.query.sqm.sql.SqmTranslatorFactory; import org.hibernate.query.sqm.tree.expression.SqmParameter; import org.hibernate.query.sqm.tree.insert.SqmInsertStatement; import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.spi.FromClauseAccess; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.insert.InsertStatement; import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert; import org.hibernate.sql.exec.spi.JdbcParameterBindings; @@ -53,19 +49,18 @@ public class SimpleInsertQueryPlan implements NonSelectQueryPlan { private SqlAstTranslator createInsertTranslator(DomainQueryExecutionContext executionContext) { final SessionFactoryImplementor factory = executionContext.getSession().getFactory(); - final QueryEngine queryEngine = factory.getQueryEngine(); - final SqmTranslatorFactory translatorFactory = queryEngine.getSqmTranslatorFactory(); - final SqmTranslator translator = translatorFactory.createInsertTranslator( - sqmInsert, - executionContext.getQueryOptions(), - domainParameterXref, - executionContext.getQueryParameterBindings(), - executionContext.getSession().getLoadQueryInfluencers(), - factory - ); - - final SqmTranslation sqmInterpretation = translator.translate(); + final SqmTranslation sqmInterpretation = + factory.getQueryEngine().getSqmTranslatorFactory() + .createInsertTranslator( + sqmInsert, + executionContext.getQueryOptions(), + domainParameterXref, + executionContext.getQueryParameterBindings(), + executionContext.getSession().getLoadQueryInfluencers(), + factory + ) + .translate(); tableGroupAccess = sqmInterpretation.getFromClauseAccess(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleUpdateQueryPlan.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleUpdateQueryPlan.java index df47eb4694..a7b2205ea5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleUpdateQueryPlan.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SimpleUpdateQueryPlan.java @@ -16,17 +16,13 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.metamodel.mapping.MappingModelExpressible; import org.hibernate.query.spi.DomainQueryExecutionContext; import org.hibernate.query.spi.NonSelectQueryPlan; -import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.spi.QueryParameterImplementor; import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess; import org.hibernate.query.sqm.sql.SqmTranslation; -import org.hibernate.query.sqm.sql.SqmTranslator; -import org.hibernate.query.sqm.sql.SqmTranslatorFactory; import org.hibernate.query.sqm.tree.expression.SqmParameter; import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.spi.FromClauseAccess; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.ast.tree.update.UpdateStatement; import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate; import org.hibernate.sql.exec.spi.JdbcParameterBindings; @@ -102,19 +98,18 @@ public class SimpleUpdateQueryPlan implements NonSelectQueryPlan { private SqlAstTranslator createUpdateTranslator(DomainQueryExecutionContext executionContext) { final SessionFactoryImplementor factory = executionContext.getSession().getFactory(); - final QueryEngine queryEngine = factory.getQueryEngine(); - final SqmTranslatorFactory translatorFactory = queryEngine.getSqmTranslatorFactory(); - final SqmTranslator translator = translatorFactory.createSimpleUpdateTranslator( - sqmUpdate, - executionContext.getQueryOptions(), - domainParameterXref, - executionContext.getQueryParameterBindings(), - executionContext.getSession().getLoadQueryInfluencers(), - factory - ); - - final SqmTranslation sqmInterpretation = translator.translate(); + final SqmTranslation sqmInterpretation = + factory.getQueryEngine().getSqmTranslatorFactory() + .createSimpleUpdateTranslator( + sqmUpdate, + executionContext.getQueryOptions(), + domainParameterXref, + executionContext.getQueryParameterBindings(), + executionContext.getSession().getLoadQueryInfluencers(), + factory + ) + .translate(); tableGroupAccess = sqmInterpretation.getFromClauseAccess(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java index 49556ccb8b..80098bae87 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java @@ -148,7 +148,6 @@ import org.hibernate.query.sqm.tree.select.SqmSelectableNode; import org.hibernate.query.sqm.tree.select.SqmSortSpecification; import org.hibernate.query.sqm.tree.select.SqmSubQuery; import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; -import org.hibernate.service.ServiceRegistry; import org.hibernate.type.BasicType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.java.EnumJavaType; @@ -189,7 +188,6 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, private final String name; private final transient boolean jpaComplianceEnabled; private final transient QueryEngine queryEngine; - private final transient ServiceRegistry serviceRegistry; private final transient Supplier sessionFactory; private final transient ValueHandlingMode criteriaValueHandlingMode; private transient BasicType booleanType; @@ -202,9 +200,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, QueryEngine queryEngine, boolean jpaComplianceEnabled, ValueHandlingMode criteriaValueHandlingMode, - ServiceRegistry serviceRegistry, Supplier sessionFactory) { - this.serviceRegistry = serviceRegistry; this.sessionFactory = sessionFactory; this.queryEngine = queryEngine; this.uuid = uuid; @@ -226,7 +222,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, @Override public TypeConfiguration getTypeConfiguration() { - return queryEngine.getTypeConfiguration(); + return getQueryEngine().getTypeConfiguration(); } @Override @@ -326,11 +322,6 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return characterType; } - @Override - public ServiceRegistry getServiceRegistry() { - return serviceRegistry; - } - @Override public QueryEngine getQueryEngine() { return queryEngine; @@ -341,18 +332,13 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getSessionFactory().getJpaMetamodel(); } - public void close() { - // for potential future use - } - - @SuppressWarnings("unchecked,rawtypes") @Override public SqmSelectStatement createQuery() { // IMPORTANT: we want to pass null here for the result-type // to indicate that we do not know. this will allow later // calls to `SqmSelectStatement#select`, `SqmSelectStatement#multiSelect`, // etc. to influence the result type - return new SqmSelectStatement( Object.class, this ); + return new SqmSelectStatement<>( Object.class, this ); } @Override @@ -485,8 +471,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "cast" ).generateSqmExpression( asList( (SqmTypedNode) expression, new SqmCastTarget<>( type, this ) ), type, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -812,8 +797,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "avg" ).generateSqmExpression( (SqmTypedNode) argument, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -824,8 +808,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "sum" ).generateSqmExpression( typedNode, (ReturnableType) typedNode.getNodeType(), - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -834,8 +817,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "sum" ).generateSqmExpression( (SqmTypedNode) argument, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -844,8 +826,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "sum" ).generateSqmExpression( (SqmTypedNode) argument, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -854,8 +835,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "max" ).generateSqmExpression( (SqmTypedNode) argument, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -864,21 +844,20 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "min" ).generateSqmExpression( (SqmTypedNode) argument, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @Override public > SqmExpression greatest(Expression argument) { return queryEngine.getSqmFunctionRegistry().findFunctionDescriptor( "max" ) - .generateSqmExpression( (SqmTypedNode) argument, null, queryEngine, getTypeConfiguration() ); + .generateSqmExpression( (SqmTypedNode) argument, null, queryEngine); } @Override public > SqmExpression least(Expression argument) { return queryEngine.getSqmFunctionRegistry().findFunctionDescriptor( "min" ) - .generateSqmExpression( (SqmTypedNode) argument, null, queryEngine, getTypeConfiguration() ); + .generateSqmExpression( (SqmTypedNode) argument, null, queryEngine); } @Override @@ -886,18 +865,16 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "count" ).generateSqmExpression( (SqmTypedNode) argument, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @Override public SqmExpression countDistinct(Expression argument) { return getFunctionDescriptor( "count" ).generateSqmExpression( - new SqmDistinct<>( (SqmExpression) argument, getQueryEngine().getCriteriaBuilder() ), + new SqmDistinct<>( (SqmExpression) argument, this ), null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -906,8 +883,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "sign" ).generateSqmExpression( (SqmExpression) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -916,8 +892,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "ceiling" ).generateSqmExpression( (SqmExpression) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -926,8 +901,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "floor" ).generateSqmExpression( (SqmExpression) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -936,8 +910,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "exp" ).generateSqmExpression( (SqmExpression) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -946,8 +919,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "ln" ).generateSqmExpression( (SqmExpression) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -956,8 +928,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "power" ).generateSqmExpression( Arrays.asList( (SqmExpression) x, (SqmExpression) y), null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -966,8 +937,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "power" ).generateSqmExpression( Arrays.asList( (SqmExpression) x, value( y ) ), null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -976,8 +946,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "round" ).generateSqmExpression( Arrays.asList( (SqmExpression) x, value( n ) ), null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -986,8 +955,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "truncate" ).generateSqmExpression( Arrays.asList( (SqmExpression) x, value( n ) ), null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -1005,8 +973,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "abs" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -1024,7 +991,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, operator, leftHandExpression, rightHandExpression, - (SqmExpressible) getDomainModel().getTypeConfiguration().resolveArithmeticType( + (SqmExpressible) getTypeConfiguration().resolveArithmeticType( leftHandExpression.getNodeType(), rightHandExpression.getNodeType(), operator @@ -1164,8 +1131,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "sqrt" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -1364,8 +1330,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "concat" ).generateSqmExpression( asList( xSqmExpression, ySqmExpression ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -1377,8 +1342,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "concat" ).generateSqmExpression( asList( xSqmExpression, ySqmExpression ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -1390,8 +1354,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "concat" ).generateSqmExpression( asList( xSqmExpression, ySqmExpression ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -1403,8 +1366,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "concat" ).generateSqmExpression( asList( xSqmExpression, ySqmExpression ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -1424,8 +1386,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "substring" ).generateSqmExpression( len == null ? asList( source, from ) : asList( source, from, len ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -1483,8 +1444,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "trim" ).generateSqmExpression( arguments, null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -1538,8 +1498,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "lower" ).generateSqmExpression( (SqmExpression) x, null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -1548,8 +1507,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "upper" ).generateSqmExpression( (SqmExpression) x, null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -1558,8 +1516,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "length" ).generateSqmExpression( (SqmExpression) argument, null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -1594,8 +1551,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor("locate").generateSqmExpression( arguments, null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -1631,8 +1587,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor("current_date") .generateSqmExpression( null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -1641,8 +1596,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor("current_timestamp") .generateSqmExpression( null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -1651,8 +1605,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor("current_time") .generateSqmExpression( null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -1660,11 +1613,10 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, public SqmFunction currentInstant() { return getFunctionDescriptor("current_timestamp") .generateSqmExpression( - getJpaMetamodel().getTypeConfiguration() + getTypeConfiguration() .getBasicTypeRegistry() .resolve( StandardBasicTypes.INSTANT ), - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -1673,8 +1625,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor("local_date") .generateSqmExpression( null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -1683,8 +1634,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor("local_datetime") .generateSqmExpression( null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -1693,8 +1643,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor("local_time") .generateSqmExpression( null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -1715,8 +1664,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return functionTemplate.generateSqmExpression( expressionList( args ), resultType, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -1941,8 +1889,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor("nullif").generateSqmExpression( asList( first, second ), type, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -2712,8 +2659,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "sql" ).generateSqmExpression( sqmArguments, getTypeConfiguration().getBasicTypeForJavaType( type ), - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -2723,8 +2669,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "format" ).generateSqmExpression( asList( (SqmExpression) datetime, sqmFormat ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -2742,8 +2687,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, (SqmTypedNode) datetime ), null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -2785,8 +2729,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, new SqmExtractUnit<>( temporalUnit, getIntegerType(), this ) ), null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -2886,8 +2829,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, ? asList( sqmString, sqmReplacement, sqmStart ) : asList( sqmString, sqmReplacement, sqmStart, (SqmExpression) length ) ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -2963,8 +2905,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, ? asList( source, sqmLength, padSpec, (SqmExpression) padChar ) : asList( source, sqmLength, padSpec ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -2973,8 +2914,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "repeat" ).generateSqmExpression( asList( (SqmExpression) x, (SqmExpression) times ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -2998,8 +2938,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "left" ).generateSqmExpression( asList( (SqmExpression) x, (SqmExpression) length ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -3013,8 +2952,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "right" ).generateSqmExpression( asList( (SqmExpression) x, (SqmExpression) length ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -3046,8 +2984,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, (SqmExpression) replacement ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -3057,8 +2994,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "collate" ).generateSqmExpression( asList( (SqmExpression) x, sqmCollation ), null, - getQueryEngine(), - getJpaMetamodel().getTypeConfiguration() + getQueryEngine() ); } @@ -3068,8 +3004,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "log10" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3083,8 +3018,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "log" ).generateSqmExpression( asList( (SqmTypedNode) b, (SqmTypedNode) x ), null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3092,8 +3026,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, public SqmFunction pi() { return getFunctionDescriptor( "pi" ).generateSqmExpression( null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3102,8 +3035,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "sin" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3112,8 +3044,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "cos" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3122,8 +3053,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "tan" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3132,8 +3062,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "asin" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3142,8 +3071,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "acos" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3152,8 +3080,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "atan" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3172,8 +3099,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "atan2" ).generateSqmExpression( asList( (SqmTypedNode) y, (SqmTypedNode) x ), null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3182,8 +3108,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "sinh" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3192,8 +3117,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "cosh" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3202,8 +3126,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "tanh" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3212,8 +3135,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "degrees" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3222,8 +3144,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return getFunctionDescriptor( "radians" ).generateSqmExpression( (SqmTypedNode) x, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); } @@ -3275,8 +3196,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, SqmExpression function = getFunctionDescriptor( name ).generateSqmExpression( expressionList( args ), null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); return new SqmOver<>( function, (SqmWindow) window ); } @@ -3363,8 +3283,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, expressionList( args ), sqmFilter, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); if ( window == null ) { return function; @@ -3466,8 +3385,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, sqmFilter, withinGroupClause, null, - queryEngine, - getJpaMetamodel().getTypeConfiguration() + queryEngine ); if ( window == null ) { return function; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java index bece556f97..911d88f323 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java @@ -44,7 +44,6 @@ import org.hibernate.query.sqm.tree.SqmStatement; import org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter; import org.hibernate.query.sqm.tree.expression.SqmJpaCriteriaParameterWrapper; import org.hibernate.query.sqm.tree.expression.SqmParameter; -import org.hibernate.query.sqm.tree.jpa.ParameterCollector; import org.hibernate.query.sqm.tree.select.SqmSelectStatement; import org.hibernate.spi.NavigablePath; import org.hibernate.sql.ast.SqlTreeCreationException; @@ -58,6 +57,8 @@ import org.hibernate.type.JavaObjectType; import org.hibernate.type.descriptor.converter.spi.BasicValueConverter; import org.hibernate.type.spi.TypeConfiguration; +import static org.hibernate.query.sqm.tree.jpa.ParameterCollector.collectParameters; + /** * Helper utilities for dealing with SQM * @@ -450,13 +451,7 @@ public class SqmUtil { public static SqmStatement.ParameterResolutions resolveParameters(SqmStatement statement) { if ( statement.getQuerySource() == SqmQuerySource.CRITERIA ) { final CriteriaParameterCollector parameterCollector = new CriteriaParameterCollector(); - - ParameterCollector.collectParameters( - statement, - parameterCollector::process, - statement.nodeBuilder().getServiceRegistry() - ); - + collectParameters( statement, parameterCollector::process ); return parameterCollector.makeResolution(); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/AbstractCteMutationHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/AbstractCteMutationHandler.java index 2bba1396b1..816f4f5aba 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/AbstractCteMutationHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/AbstractCteMutationHandler.java @@ -58,7 +58,6 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.basic.BasicResult; import org.hibernate.sql.results.internal.SqlSelectionImpl; import org.hibernate.sql.results.spi.ListResultsConsumer; -import org.hibernate.type.spi.TypeConfiguration; /** * Defines how identifier values are selected from the updatable/deletable tables. @@ -218,12 +217,10 @@ public abstract class AbstractCteMutationHandler extends AbstractMutationHandler SessionFactoryImplementor factory, MultiTableSqmMutationConverter sqmConverter) { final SqmExpression arg = new SqmStar( factory.getNodeBuilder() ); - final TypeConfiguration typeConfiguration = factory.getJpaMetamodel().getTypeConfiguration(); return factory.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor( "count" ).generateSqmExpression( arg, null, - factory.getQueryEngine(), - typeConfiguration + factory.getQueryEngine() ).convertToSqlAst( sqmConverter ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java index 9f659dde74..3a3ac4b9ac 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java @@ -667,8 +667,7 @@ public class CteInsertHandler implements InsertHandler { return factory.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor( "count" ).generateSqmExpression( arg, null, - factory.getQueryEngine(), - typeConfiguration + factory.getQueryEngine() ).convertToSqlAst( sqmConverter ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/BaseSemanticQueryWalker.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/BaseSemanticQueryWalker.java index 9124d588ce..325d7e611a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/BaseSemanticQueryWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/BaseSemanticQueryWalker.java @@ -110,7 +110,6 @@ import org.hibernate.query.sqm.tree.select.SqmSubQuery; import org.hibernate.query.sqm.tree.update.SqmAssignment; import org.hibernate.query.sqm.tree.update.SqmSetClause; import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; -import org.hibernate.service.ServiceRegistry; /** * Base support for an SQM walker @@ -118,15 +117,6 @@ import org.hibernate.service.ServiceRegistry; * @author Steve Ebersole */ public abstract class BaseSemanticQueryWalker implements SemanticQueryWalker { - private final ServiceRegistry serviceRegistry; - - public BaseSemanticQueryWalker(ServiceRegistry serviceRegistry) { - this.serviceRegistry = serviceRegistry; - } - - public ServiceRegistry getServiceRegistry() { - return serviceRegistry; - } @Override public Object visitSelectStatement(SqmSelectStatement statement) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/SqmCreationContext.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/SqmCreationContext.java index b2ce5836d1..4ffc5a264f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/SqmCreationContext.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/SqmCreationContext.java @@ -11,6 +11,7 @@ import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.service.ServiceRegistry; +import org.hibernate.type.spi.TypeConfiguration; /** * The context in which all SQM creations occur (think SessionFactory). @@ -31,6 +32,10 @@ public interface SqmCreationContext { return getJpaMetamodel().getServiceRegistry(); } + default TypeConfiguration getTypeConfiguration() { + return getJpaMetamodel().getTypeConfiguration(); + } + QueryEngine getQueryEngine(); default NodeBuilder getNodeBuilder() { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 681fba496c..35e5bb19a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -194,7 +194,6 @@ import org.hibernate.query.sqm.tree.domain.SqmPluralPartJoin; import org.hibernate.query.sqm.tree.domain.SqmPluralValuedSimplePath; import org.hibernate.query.sqm.tree.domain.SqmSimplePath; import org.hibernate.query.sqm.tree.domain.SqmTreatedPath; -import org.hibernate.query.sqm.tree.domain.SqmTreatedRoot; import org.hibernate.query.sqm.tree.expression.Conversion; import org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter; import org.hibernate.query.sqm.tree.expression.SqmAliasedNodeRef; @@ -520,8 +519,6 @@ public abstract class BaseSqmToSqlAstConverter extends Base DomainParameterXref domainParameterXref, QueryParameterBindings domainParameterBindings, boolean deduplicateSelectionItems) { - super( creationContext.getServiceRegistry() ); - this.inferrableTypeAccessStack.push( () -> null ); this.creationContext = creationContext; this.jpaQueryComplianceEnabled = creationContext @@ -6133,8 +6130,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base .generateSqmExpression( sqmCoalesce.getArguments(), null, - queryEngine, - sessionFactory.getTypeConfiguration() + queryEngine ) .accept( this ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/FakeSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/FakeSqmToSqlAstConverter.java index 5b7de88ffa..efe0bf0a88 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/FakeSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/FakeSqmToSqlAstConverter.java @@ -39,7 +39,6 @@ public class FakeSqmToSqlAstConverter extends BaseSemanticQueryWalker implements private final SqlAstCreationState creationState; public FakeSqmToSqlAstConverter(SqlAstCreationState creationState) { - super( creationState.getCreationContext().getServiceRegistry() ); this.creationState = creationState; } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/AbstractSqmStatement.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/AbstractSqmStatement.java index 0be7c2a676..11a97f6e91 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/AbstractSqmStatement.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/AbstractSqmStatement.java @@ -16,6 +16,8 @@ import org.hibernate.query.sqm.internal.ParameterCollector; import org.hibernate.query.sqm.internal.SqmUtil; import org.hibernate.query.sqm.tree.expression.SqmParameter; +import static org.hibernate.query.sqm.tree.jpa.ParameterCollector.collectParameters; + /** * @author Steve Ebersole */ @@ -70,12 +72,7 @@ public abstract class AbstractSqmStatement extends AbstractSqmNode implements public Set> getSqmParameters() { if ( querySource == SqmQuerySource.CRITERIA ) { assert parameters == null : "SqmSelectStatement (as Criteria) should not have collected parameters"; - - return org.hibernate.query.sqm.tree.jpa.ParameterCollector.collectParameters( - this, - sqmParameter -> {}, - nodeBuilder().getServiceRegistry() - ); + return collectParameters( this ); } return parameters == null ? Collections.emptySet() : Collections.unmodifiableSet( parameters ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmFrom.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmFrom.java index 54d7c40024..435586775a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmFrom.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmFrom.java @@ -159,7 +159,6 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements SqmCreationState creationState) { // Try to resolve an existing attribute join without ON clause SqmPath resolvedPath = null; - ModelPartContainer modelPartContainer = null; for ( SqmJoin sqmJoin : getSqmJoins() ) { // We can only match singular joins here, as plural path parts are interpreted like sub-queries if ( sqmJoin instanceof SqmSingularJoin @@ -355,7 +354,6 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements } @Override - @SuppressWarnings("unchecked") public SqmSetJoin join(SetAttribute attribute, JoinType jt) { final SqmSetJoin join = buildSetJoin( (SetPersistentAttribute) attribute, @@ -372,7 +370,6 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements } @Override - @SuppressWarnings("unchecked") public SqmListJoin join(ListAttribute attribute, JoinType jt) { final SqmListJoin join = buildListJoin( (ListPersistentAttribute) attribute, @@ -611,7 +608,7 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements } private void validateComplianceFromSubQuery() { - if ( nodeBuilder().getDomainModel().getJpaCompliance().isJpaQueryComplianceEnabled() ) { + if ( nodeBuilder().isJpaQueryComplianceEnabled() ) { throw new IllegalStateException( "The JPA specification does not support subqueries in the from clause. " + "Please disable the JPA query compliance if you want to use this feature." ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapEntryReference.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapEntryReference.java index ec6330504d..0486bfd917 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapEntryReference.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapEntryReference.java @@ -47,10 +47,9 @@ public class SqmMapEntryReference this.mapPath = mapPath; this.nodeBuilder = nodeBuilder; - this.mapEntryTypeDescriptor = nodeBuilder.getDomainModel() - .getTypeConfiguration() - .getJavaTypeRegistry() - .getDescriptor( Map.Entry.class ); + this.mapEntryTypeDescriptor = + nodeBuilder.getTypeConfiguration().getJavaTypeRegistry() + .getDescriptor( Map.Entry.class ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java index e6a11eb415..adb8719b3e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java @@ -114,8 +114,7 @@ public interface SqmExpression extends SqmSelectableNode, JpaExpression .generateSqmExpression( asList( this, target ), (ReturnableType) type, - queryEngine, - nodeBuilder().getTypeConfiguration() + queryEngine ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpressionHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpressionHelper.java index 04266b2ca4..da9534aa3e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpressionHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpressionHelper.java @@ -29,8 +29,6 @@ import org.hibernate.type.descriptor.java.JavaTypeHelper; import org.hibernate.type.descriptor.java.JdbcDateJavaType; import org.hibernate.type.descriptor.java.JdbcTimeJavaType; import org.hibernate.type.descriptor.java.JdbcTimestampJavaType; -import org.hibernate.type.descriptor.java.TemporalJavaType; -import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.usertype.internal.AbstractTimeZoneStorageCompositeUserType; import org.hibernate.usertype.internal.OffsetTimeCompositeUserType; @@ -68,8 +66,8 @@ public class SqmExpressionHelper { return new SqmLiteral<>( literal, - creationState.getCreationContext().getJpaMetamodel().getTypeConfiguration().standardBasicTypeForJavaType( Timestamp.class ), - creationState.getCreationContext().getQueryEngine().getCriteriaBuilder() + creationState.getCreationContext().getTypeConfiguration().standardBasicTypeForJavaType( Timestamp.class ), + creationState.getCreationContext().getNodeBuilder() ); } @@ -95,8 +93,8 @@ public class SqmExpressionHelper { return new SqmLiteral<>( literal, - creationState.getCreationContext().getJpaMetamodel().getTypeConfiguration().standardBasicTypeForJavaType( Date.class ), - creationState.getCreationContext().getQueryEngine().getCriteriaBuilder() + creationState.getCreationContext().getTypeConfiguration().standardBasicTypeForJavaType( Date.class ), + creationState.getCreationContext().getNodeBuilder() ); } @@ -106,8 +104,8 @@ public class SqmExpressionHelper { return new SqmLiteral<>( literal, - creationState.getCreationContext().getJpaMetamodel().getTypeConfiguration().standardBasicTypeForJavaType( Time.class ), - creationState.getCreationContext().getQueryEngine().getCriteriaBuilder() + creationState.getCreationContext().getTypeConfiguration().standardBasicTypeForJavaType( Time.class ), + creationState.getCreationContext().getNodeBuilder() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/ParameterCollector.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/ParameterCollector.java index 774e1a60c1..b3a098713e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/ParameterCollector.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/ParameterCollector.java @@ -35,7 +35,6 @@ import org.hibernate.query.sqm.tree.predicate.SqmLikePredicate; import org.hibernate.query.sqm.tree.predicate.SqmMemberOfPredicate; import org.hibernate.query.sqm.tree.predicate.SqmNullnessPredicate; import org.hibernate.query.sqm.tree.select.SqmSelectStatement; -import org.hibernate.service.ServiceRegistry; /** * todo (6.0) : how is this different from {@link org.hibernate.query.sqm.internal.ParameterCollector}? @@ -44,21 +43,21 @@ import org.hibernate.service.ServiceRegistry; */ public class ParameterCollector extends BaseSemanticQueryWalker { + public static Set> collectParameters(SqmStatement statement) { + return collectParameters( statement, parameter -> {} ); + } + public static Set> collectParameters( SqmStatement statement, - Consumer> consumer, - ServiceRegistry serviceRegistry) { - final ParameterCollector collector = new ParameterCollector( serviceRegistry, consumer ); + Consumer> consumer) { + final ParameterCollector collector = new ParameterCollector( consumer ); statement.accept( collector ); return collector.parameterExpressions == null ? Collections.emptySet() : collector.parameterExpressions; } - private ParameterCollector( - ServiceRegistry serviceRegistry, - Consumer> consumer) { - super( serviceRegistry ); + private ParameterCollector(Consumer> consumer) { this.consumer = consumer; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java index e287092825..9a7cb8df4b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java @@ -249,7 +249,7 @@ public abstract class AbstractSqmSelectQuery } private void validateComplianceFromSubQuery() { - if ( nodeBuilder().getDomainModel().getJpaCompliance().isJpaQueryComplianceEnabled() ) { + if ( nodeBuilder().isJpaQueryComplianceEnabled() ) { throw new IllegalStateException( "The JPA specification does not support subqueries in the from clause. " + "Please disable the JPA query compliance if you want to use this feature." ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectStatement.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectStatement.java index 7488c35b81..780f5f43af 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectStatement.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectStatement.java @@ -34,7 +34,8 @@ import org.hibernate.query.sqm.tree.cte.SqmCteStatement; import org.hibernate.query.sqm.tree.expression.ValueBindJpaCriteriaParameter; import org.hibernate.query.sqm.tree.expression.SqmParameter; import org.hibernate.query.sqm.tree.from.SqmFromClause; -import org.hibernate.query.sqm.tree.jpa.ParameterCollector; + +import static org.hibernate.query.sqm.tree.jpa.ParameterCollector.collectParameters; /** * @author Steve Ebersole @@ -201,12 +202,7 @@ public class SqmSelectStatement extends AbstractSqmSelectQuery implements public Set> getSqmParameters() { if ( querySource == SqmQuerySource.CRITERIA ) { assert parameters == null : "SqmSelectStatement (as Criteria) should not have collected parameters"; - - return ParameterCollector.collectParameters( - this, - sqmParameter -> {}, - nodeBuilder().getServiceRegistry() - ); + return collectParameters( this ); } return parameters == null ? Collections.emptySet() : Collections.unmodifiableSet( parameters ); @@ -258,7 +254,7 @@ public class SqmSelectStatement extends AbstractSqmSelectQuery implements @Override @SuppressWarnings("unchecked") public SqmSelectStatement select(Selection selection) { - if ( nodeBuilder().getDomainModel().getJpaCompliance().isJpaQueryComplianceEnabled() ) { + if ( nodeBuilder().isJpaQueryComplianceEnabled() ) { checkSelectionIsJpaCompliant( selection ); } getQuerySpec().setSelection( (JpaSelection) selection ); @@ -269,9 +265,8 @@ public class SqmSelectStatement extends AbstractSqmSelectQuery implements } @Override - @SuppressWarnings("unchecked") public SqmSelectStatement multiselect(Selection... selections) { - if ( nodeBuilder().getDomainModel().getJpaCompliance().isJpaQueryComplianceEnabled() ) { + if ( nodeBuilder().isJpaQueryComplianceEnabled() ) { for ( Selection selection : selections ) { checkSelectionIsJpaCompliant( selection ); } @@ -285,7 +280,7 @@ public class SqmSelectStatement extends AbstractSqmSelectQuery implements @Override @SuppressWarnings("unchecked") public SqmSelectStatement multiselect(List> selectionList) { - if ( nodeBuilder().getDomainModel().getJpaCompliance().isJpaQueryComplianceEnabled() ) { + if ( nodeBuilder().isJpaQueryComplianceEnabled() ) { for ( Selection selection : selectionList ) { checkSelectionIsJpaCompliant( selection ); } @@ -449,7 +444,7 @@ public class SqmSelectStatement extends AbstractSqmSelectQuery implements } private void validateComplianceFetchOffset() { - if ( nodeBuilder().getDomainModel().getJpaCompliance().isJpaQueryComplianceEnabled() ) { + if ( nodeBuilder().isJpaQueryComplianceEnabled() ) { throw new IllegalStateException( "The JPA specification does not support the fetch or offset clause. " + "Please disable the JPA query compliance if you want to use this feature." ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java index 68beb442b8..676f4835dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java @@ -413,7 +413,7 @@ public class SqmSubQuery extends AbstractSqmSelectQuery implements SqmSele } private void validateComplianceMultiselect() { - if ( nodeBuilder().getDomainModel().getJpaCompliance().isJpaQueryComplianceEnabled() ) { + if ( nodeBuilder().isJpaQueryComplianceEnabled() ) { throw new IllegalStateException( "The JPA specification does not support subqueries having multiple select items. " + "Please disable the JPA query compliance if you want to use this feature." ); @@ -421,7 +421,7 @@ public class SqmSubQuery extends AbstractSqmSelectQuery implements SqmSele } private void validateComplianceOrderBy() { - if ( nodeBuilder().getDomainModel().getJpaCompliance().isJpaQueryComplianceEnabled() ) { + if ( nodeBuilder().isJpaQueryComplianceEnabled() ) { throw new IllegalStateException( "The JPA specification does not support subqueries having an order by clause. " + "Please disable the JPA query compliance if you want to use this feature." ); @@ -429,7 +429,7 @@ public class SqmSubQuery extends AbstractSqmSelectQuery implements SqmSele } private void validateComplianceFetchOffset() { - if ( nodeBuilder().getDomainModel().getJpaCompliance().isJpaQueryComplianceEnabled() ) { + if ( nodeBuilder().isJpaQueryComplianceEnabled() ) { throw new IllegalStateException( "The JPA specification does not support subqueries having a fetch or offset clause. " + "Please disable the JPA query compliance if you want to use this feature." ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/EntityJoinTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/EntityJoinTest.java index f7508cbb77..abfadac44c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/EntityJoinTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/EntityJoinTest.java @@ -21,14 +21,11 @@ import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.query.SemanticException; -import org.hibernate.query.hql.HqlTranslator; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.spi.QueryOptions; import org.hibernate.query.spi.QueryParameterBindings; import org.hibernate.query.sqm.internal.DomainParameterXref; import org.hibernate.query.sqm.sql.SqmTranslation; -import org.hibernate.query.sqm.sql.SqmTranslator; -import org.hibernate.query.sqm.sql.SqmTranslatorFactory; import org.hibernate.query.sqm.tree.SqmStatement; import org.hibernate.query.sqm.tree.select.SqmSelectStatement; import org.hibernate.sql.ast.tree.from.LazyTableGroup; @@ -187,21 +184,22 @@ public class EntityJoinTest { .findEntityDescriptor( Customer.class ); final QueryEngine queryEngine = factory.getQueryEngine(); - final HqlTranslator hqlTranslator = queryEngine.getHqlTranslator(); - final SqmTranslatorFactory sqmTranslatorFactory = queryEngine.getSqmTranslatorFactory(); - final SqmStatement sqm = hqlTranslator.translate( qry, null ); + final SqmStatement sqm = + queryEngine.getHqlTranslator().translate( qry, null ); - final SqmTranslator selectTranslator = sqmTranslatorFactory.createSelectTranslator( - (SqmSelectStatement) sqm, - QueryOptions.NONE, - DomainParameterXref.empty(), - QueryParameterBindings.NO_PARAM_BINDINGS, - LoadQueryInfluencers.NONE, - factory, - true - ); - final SqmTranslation sqmTranslation = selectTranslator.translate(); + final SqmTranslation sqmTranslation = + queryEngine.getSqmTranslatorFactory() + .createSelectTranslator( + (SqmSelectStatement) sqm, + QueryOptions.NONE, + DomainParameterXref.empty(), + QueryParameterBindings.NO_PARAM_BINDINGS, + LoadQueryInfluencers.NONE, + factory, + true + ) + .translate(); final SelectStatement sqlAst = sqmTranslation.getSqlAst(); final List roots = sqlAst.getQuerySpec().getFromClause().getRoots(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/sql/results/AbstractResultTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/sql/results/AbstractResultTests.java index 30cca8d06d..1bc329b235 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/sql/results/AbstractResultTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/sql/results/AbstractResultTests.java @@ -12,8 +12,6 @@ import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.spi.QueryOptions; import org.hibernate.query.spi.QueryParameterBindings; import org.hibernate.query.sqm.internal.DomainParameterXref; -import org.hibernate.query.sqm.sql.SqmTranslator; -import org.hibernate.query.sqm.sql.SqmTranslatorFactory; import org.hibernate.query.sqm.tree.select.SqmSelectStatement; import org.hibernate.sql.ast.tree.select.SelectStatement; @@ -28,19 +26,20 @@ public class AbstractResultTests { protected SelectStatement interpret(String hql, QueryParameterBindings parameterBindings, SessionFactoryImplementor sessionFactory) { final QueryEngine queryEngine = sessionFactory.getQueryEngine(); - final SqmSelectStatement sqm = (SqmSelectStatement) queryEngine.getHqlTranslator().translate( hql, null ); + final SqmSelectStatement sqm = (SqmSelectStatement) + queryEngine.getHqlTranslator().translate( hql, null ); - final SqmTranslatorFactory sqmTranslatorFactory = queryEngine.getSqmTranslatorFactory(); - final SqmTranslator sqmConverter = sqmTranslatorFactory.createSelectTranslator( - sqm, - QueryOptions.NONE, - DomainParameterXref.from( sqm ), - parameterBindings, - LoadQueryInfluencers.NONE, - sessionFactory, - true - ); - - return sqmConverter.translate().getSqlAst(); + return queryEngine.getSqmTranslatorFactory() + .createSelectTranslator( + sqm, + QueryOptions.NONE, + DomainParameterXref.from( sqm ), + parameterBindings, + LoadQueryInfluencers.NONE, + sessionFactory, + true + ) + .translate() + .getSqlAst(); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/function/OrderByFragmentFunction.java b/hibernate-envers/src/main/java/org/hibernate/envers/function/OrderByFragmentFunction.java index 08df908d6b..6599f70727 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/function/OrderByFragmentFunction.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/function/OrderByFragmentFunction.java @@ -39,7 +39,6 @@ import org.hibernate.sql.ast.tree.from.NamedTableReference; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.ast.tree.select.QuerySpec; -import org.hibernate.type.spi.TypeConfiguration; /** * Envers specific FunctionContributor @@ -63,8 +62,7 @@ public class OrderByFragmentFunction extends AbstractSqmFunctionDescriptor { protected SelfRenderingSqmFunction generateSqmFunctionExpression( List> arguments, ReturnableType impliedResultType, - QueryEngine queryEngine, - TypeConfiguration typeConfiguration) { + QueryEngine queryEngine) { return new OrderByFragmentSelfRenderingSqmFunction<>( this, arguments, impliedResultType, queryEngine ); }