Fix issues with respecting padding and limit for in list rendering

This commit is contained in:
Christian Beikov 2022-03-31 16:40:50 +02:00
parent ad828a0a4a
commit fa7cb3f0e9
2 changed files with 14 additions and 19 deletions

View File

@ -4894,9 +4894,9 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
listExpression.accept( this );
separator = COMA_SEPARATOR;
itemNumber++;
// If we encounter an expression that is not a parameter, we reset the inExprLimit and bindValueMaxCount
// If we encounter an expression that is not a parameter or literal, we reset the inExprLimit and bindValueMaxCount
// and just render through the in list expressions as they are without padding/splitting
if ( !( listExpression instanceof JdbcParameter || listExpression instanceof SqmParameterInterpretation ) ) {
if ( !( listExpression instanceof JdbcParameter || listExpression instanceof SqmParameterInterpretation || listExpression instanceof Literal ) ) {
inExprLimit = 0;
bindValueMaxCount = bindValueCount;
}
@ -4909,7 +4909,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
if ( inExprLimit > 0 && bindValueCount > inExprLimit ) {
do {
append( ") and " );
append( ") or " );
inListPredicate.getTestExpression().accept( this );
if ( inListPredicate.isNegated() ) {
appendSql( " not" );
@ -4927,19 +4927,14 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
} while ( iterator.hasNext() );
}
int i;
if ( inExprLimit > 0 && bindValueCount > inExprLimit ) {
i = bindValueCount % inExprLimit;
}
else {
i = bindValueCount;
}
if ( inClauseParameterPaddingEnabled ) {
final Expression lastExpression = itemAccessor.apply( listExpressions.get( listExpressions.size() - 1 ) );
for ( ; i < bindValueMaxCount; i++ ) {
for ( ; itemNumber < bindValueMaxCount; itemNumber++ ) {
appendSql( separator );
lastExpression.accept( this );
separator = COMA_SEPARATOR;
}
}
appendSql( CLOSE_PARENTHESIS );
}

View File

@ -142,7 +142,7 @@ public class MaxInExpressionParameterPaddingTest {
expectedInClause.append( ",?" );
}
expectedInClause.append( ")" );
expectedInClause.append( " and p1_0.id in(?)" );
expectedInClause.append( " or p1_0.id in(?)" );
assertTrue( statementInspector.getSqlQueries().get( 0 ).endsWith( expectedInClause.toString() ) );
}
@ -168,7 +168,7 @@ public class MaxInExpressionParameterPaddingTest {
expectedInClause.append( ",?" );
}
expectedInClause.append( ")" );
expectedInClause.append( " and p1_0.id in(?,?,?,?)" );
expectedInClause.append( " or p1_0.id in(?,?,?,?)" );
assertTrue( statementInspector.getSqlQueries().get( 0 ).endsWith( expectedInClause.toString() ) );
}
@ -194,12 +194,12 @@ public class MaxInExpressionParameterPaddingTest {
expectedInClause.append( ",?" );
}
expectedInClause.append( ")" );
expectedInClause.append( " and p1_0.id in(?");
expectedInClause.append( " or p1_0.id in(?");
for ( int i = 1; i < MAX_COUNT; i++ ) {
expectedInClause.append( ",?" );
}
expectedInClause.append( ")" );
expectedInClause.append( " and p1_0.id in(?,?,?,?)" );
expectedInClause.append( " or p1_0.id in(?,?,?,?)" );
assertTrue( statementInspector.getSqlQueries().get( 0 ).endsWith( expectedInClause.toString() ) );