Skip to content

Commit f2f8026

Browse files
committed
cleanups related to function registry
1 parent d269637 commit f2f8026

File tree

16 files changed

+255
-335
lines changed

16 files changed

+255
-335
lines changed

hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryObserverForNamedQueryValidation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SessionFactoryObserverForNamedQueryValidation implements SessionFactoryObs
3232

3333
@Override
3434
public void sessionFactoryCreated(SessionFactory factory) {
35-
SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) factory;
35+
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) factory;
3636
final QueryEngine queryEngine = sessionFactory.getQueryEngine();
3737
queryEngine.getNamedObjectRepository().prepare( sessionFactory, metadata );
3838
if ( sessionFactory.getSessionFactoryOptions().isNamedQueryStartupCheckingEnabled() ) {

hibernate-core/src/main/java/org/hibernate/dialect/function/CastFunction.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import org.hibernate.query.ReturnableType;
1616
import org.hibernate.query.sqm.CastType;
1717
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
18+
import org.hibernate.query.sqm.function.FunctionRenderer;
1819
import org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression;
19-
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
2020
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
2121
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators;
2222
import org.hibernate.query.sqm.produce.function.StandardFunctionArgumentTypeResolvers;
@@ -54,13 +54,10 @@ public CastFunction(Dialect dialect, int preferredSqlTypeCodeForBoolean) {
5454
}
5555

5656
private CastType getBooleanCastType(int preferredSqlTypeCodeForBoolean) {
57-
switch ( preferredSqlTypeCodeForBoolean ) {
58-
case Types.BIT:
59-
case Types.SMALLINT:
60-
case Types.TINYINT:
61-
return CastType.INTEGER_BOOLEAN;
62-
}
63-
return CastType.BOOLEAN;
57+
return switch (preferredSqlTypeCodeForBoolean) {
58+
case Types.BIT, Types.SMALLINT, Types.TINYINT -> CastType.INTEGER_BOOLEAN;
59+
default -> CastType.BOOLEAN;
60+
};
6461
}
6562

6663
@Override
@@ -94,26 +91,26 @@ public static void renderCastArrayToString(
9491
Dialect dialect,
9592
SqlAstTranslator<?> walker) {
9693
final SessionFactoryImplementor sessionFactory = walker.getSessionFactory();
97-
final BasicType<?> stringType = sessionFactory.getTypeConfiguration()
98-
.getBasicTypeForJavaType( String.class );
99-
final SqmFunctionRegistry functionRegistry = sessionFactory.getQueryEngine()
100-
.getSqmFunctionRegistry();
101-
final SqmFunctionDescriptor concatDescriptor = functionRegistry.findFunctionDescriptor( "concat" );
102-
final SqmFunctionDescriptor arrayToStringDescriptor = functionRegistry.findFunctionDescriptor( "array_to_string" );
94+
final BasicType<?> stringType = sessionFactory.getTypeConfiguration().getBasicTypeForJavaType( String.class );
95+
final SqmFunctionRegistry functionRegistry = sessionFactory.getQueryEngine().getSqmFunctionRegistry();
96+
final FunctionRenderer concatDescriptor =
97+
(FunctionRenderer) functionRegistry.findFunctionDescriptor( "concat" );
98+
final FunctionRenderer arrayToStringDescriptor =
99+
(FunctionRenderer) functionRegistry.findFunctionDescriptor( "array_to_string" );
103100
final boolean caseWhen = dialect.isEmptyStringTreatedAsNull();
104101
if ( caseWhen ) {
105102
sqlAppender.append( "case when " );
106103
arrayArgument.accept( walker );
107104
sqlAppender.append( " is null then null else " );
108105
}
109106

110-
( (AbstractSqmSelfRenderingFunctionDescriptor) concatDescriptor ).render(
107+
concatDescriptor.render(
111108
sqlAppender,
112109
List.of(
113110
new QueryLiteral<>( "[", stringType ),
114111
new SelfRenderingFunctionSqlAstExpression(
115112
"array_to_string",
116-
( (AbstractSqmSelfRenderingFunctionDescriptor) arrayToStringDescriptor ),
113+
arrayToStringDescriptor,
117114
List.of(
118115
arrayArgument,
119116
new QueryLiteral<>( ",", stringType ),

hibernate-core/src/main/java/org/hibernate/dialect/function/CountFunction.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.hibernate.query.sqm.CastType;
1818
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
1919
import org.hibernate.query.sqm.function.FunctionKind;
20+
import org.hibernate.query.sqm.function.FunctionRenderer;
2021
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators;
2122
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
2223
import org.hibernate.query.sqm.produce.function.internal.PatternRenderer;
@@ -182,16 +183,15 @@ else if ( !dialect.supportsTupleDistinctCounts() ) {
182183
// '' -> \0 + argumentNumber
183184
// In the end, the expression looks like the following:
184185
// count(distinct coalesce(nullif(coalesce(col1 || '', '\0'), ''), '\01') || '\0' || coalesce(nullif(coalesce(col2 || '', '\0'), ''), '\02'))
185-
final AbstractSqmSelfRenderingFunctionDescriptor chr =
186-
(AbstractSqmSelfRenderingFunctionDescriptor) translator.getSessionFactory()
187-
.getQueryEngine()
188-
.getSqmFunctionRegistry()
189-
.findFunctionDescriptor( "chr" );
186+
final FunctionRenderer chrFunction =
187+
(FunctionRenderer)
188+
translator.getSessionFactory().getQueryEngine()
189+
.getSqmFunctionRegistry()
190+
.findFunctionDescriptor( "chr" );
190191
final List<Expression> chrArguments = List.of(
191192
new QueryLiteral<>(
192193
0,
193-
translator.getSessionFactory()
194-
.getTypeConfiguration()
194+
translator.getSessionFactory().getTypeConfiguration()
195195
.getBasicTypeForJavaType( Integer.class )
196196
)
197197
);
@@ -215,15 +215,15 @@ else if ( !dialect.supportsTupleDistinctCounts() ) {
215215
sqlAppender.appendSql( "''" );
216216
}
217217
sqlAppender.appendSql( SqlAppender.COMMA_SEPARATOR_CHAR );
218-
chr.render( sqlAppender, chrArguments, returnType, translator );
218+
chrFunction.render( sqlAppender, chrArguments, returnType, translator );
219219
sqlAppender.appendSql( "),'')," );
220-
chr.render( sqlAppender, chrArguments, returnType, translator );
220+
chrFunction.render( sqlAppender, chrArguments, returnType, translator );
221221
sqlAppender.appendSql( concatOperator );
222222
sqlAppender.appendSql( "'" );
223223
sqlAppender.appendSql( argumentNumber );
224224
sqlAppender.appendSql( "')" );
225225
sqlAppender.appendSql( concatOperator );
226-
chr.render( sqlAppender, chrArguments, returnType, translator );
226+
chrFunction.render( sqlAppender, chrArguments, returnType, translator );
227227
sqlAppender.appendSql( concatOperator );
228228
sqlAppender.appendSql( "coalesce(nullif(coalesce(" );
229229
needsConcat = renderCastedArgument( sqlAppender, translator, expressions.get( i ) );
@@ -234,9 +234,9 @@ else if ( !dialect.supportsTupleDistinctCounts() ) {
234234
sqlAppender.appendSql( "''" );
235235
}
236236
sqlAppender.appendSql( SqlAppender.COMMA_SEPARATOR_CHAR );
237-
chr.render( sqlAppender, chrArguments, returnType, translator );
237+
chrFunction.render( sqlAppender, chrArguments, returnType, translator );
238238
sqlAppender.appendSql( "),'')," );
239-
chr.render( sqlAppender, chrArguments, returnType, translator );
239+
chrFunction.render( sqlAppender, chrArguments, returnType, translator );
240240
sqlAppender.appendSql( concatOperator );
241241
sqlAppender.appendSql( "'" );
242242
sqlAppender.appendSql( argumentNumber );
@@ -424,8 +424,7 @@ else if ( sourceType == CastType.OTHER && sourceMapping.getJdbcType().isArray()
424424

425425
private boolean canReplaceWithStar(SqlAstNode arg, SqlAstTranslator<?> translator) {
426426
// To determine if we can replace the argument with a star, we must know if the argument is nullable
427-
if ( arg instanceof AbstractSqmPathInterpretation<?> ) {
428-
final AbstractSqmPathInterpretation<?> pathInterpretation = (AbstractSqmPathInterpretation<?>) arg;
427+
if ( arg instanceof AbstractSqmPathInterpretation<?> pathInterpretation ) {
429428
final TableGroup tableGroup = pathInterpretation.getTableGroup();
430429
final Expression sqlExpression = pathInterpretation.getSqlExpression();
431430
final JdbcMappingContainer expressionType = sqlExpression.getExpressionType();

0 commit comments

Comments
 (0)