@@ -295,36 +295,42 @@ protected void visitArithmeticOperand(Expression expression) {
295295 }
296296 }
297297
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+
298306 @ Override
299307 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 ) ) {
307309 append ( "cast(" );
308- }
309- super .visitSelfRenderingExpression ( expression );
310- if ( isStringFunctionWithParameterArg ) {
310+ super .visitSelfRenderingExpression ( expression );
311311 append ( " as lvarchar)" );
312312 }
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" );
313321 }
314322
315323 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
322327 append ( "cast(" );
323- }
324- expression .accept ( this );
325- if ( concat ) {
328+ expression .accept ( this );
326329 append ( " as varchar(255))" );
327330 }
331+ else {
332+ expression .accept ( this );
333+ }
328334 }
329335
330336 @ Override
0 commit comments