@@ -295,36 +295,42 @@ protected void visitArithmeticOperand(Expression expression) {
295
295
}
296
296
}
297
297
298
+ private static boolean isStringFunctionWithParameterArg (SelfRenderingExpression expression ) {
299
+ return expression instanceof FunctionExpression fn
300
+ && expression .getExpressionType () != null
301
+ && expression .getExpressionType ().getJdbcTypeCount () == 1
302
+ && expression .getExpressionType ().getSingleJdbcMapping ().getJdbcType ().isString ()
303
+ && fn .getArguments ().stream ().anyMatch ( arg -> arg instanceof SqmParameterInterpretation );
304
+ }
305
+
298
306
@ Override
299
307
public void visitSelfRenderingExpression (SelfRenderingExpression expression ) {
300
- final boolean isStringFunctionWithParameterArg =
301
- expression instanceof FunctionExpression fn
302
- && expression .getExpressionType () != null
303
- && expression .getExpressionType ().getJdbcTypeCount () == 1
304
- && expression .getExpressionType ().getSingleJdbcMapping ().getJdbcType ().isString ()
305
- && fn .getArguments ().stream ().anyMatch ( arg -> arg instanceof SqmParameterInterpretation );
306
- if ( isStringFunctionWithParameterArg ) {
308
+ if ( isStringFunctionWithParameterArg ( expression ) ) {
307
309
append ( "cast(" );
308
- }
309
- super .visitSelfRenderingExpression ( expression );
310
- if ( isStringFunctionWithParameterArg ) {
310
+ super .visitSelfRenderingExpression ( expression );
311
311
append ( " as lvarchar)" );
312
312
}
313
+ else {
314
+ super .visitSelfRenderingExpression ( expression );
315
+ }
316
+ }
317
+
318
+ private static boolean isConcatFunction (Expression expression ) {
319
+ return expression instanceof FunctionExpression fn
320
+ && fn .getFunctionName ().equals ( "concat" );
313
321
}
314
322
315
323
private void caseArgument (Expression expression ) {
316
- // concatenation inside a case must be cast to varchar(255)
317
- // or we get a bunch of trailing whitespace
318
- final boolean concat =
319
- expression instanceof FunctionExpression fn
320
- && fn .getFunctionName ().equals ( "concat" );
321
- if ( concat ) {
324
+ if ( isConcatFunction ( expression ) ) {
325
+ // concatenation inside a case must be cast to varchar(255)
326
+ // or we get a bunch of trailing whitespace
322
327
append ( "cast(" );
323
- }
324
- expression .accept ( this );
325
- if ( concat ) {
328
+ expression .accept ( this );
326
329
append ( " as varchar(255))" );
327
330
}
331
+ else {
332
+ expression .accept ( this );
333
+ }
328
334
}
329
335
330
336
@ Override
0 commit comments