HHH-15046: db2 version override for SQLAstTranslator

This commit is contained in:
Atgoogat 2022-01-24 13:36:48 +01:00 committed by Christian Beikov
parent 706bd15222
commit 77ea0c7c1f
3 changed files with 15 additions and 10 deletions

View File

@ -51,7 +51,7 @@ public class DB2SqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAst
@Override @Override
public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) { public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) {
if ( getDialectVersion().isSameOrAfter( 11 ) ) { if ( getDB2Version().isSameOrAfter( 11 ) ) {
booleanExpressionPredicate.getExpression().accept( this ); booleanExpressionPredicate.getExpression().accept( this );
} }
else { else {
@ -132,12 +132,12 @@ public class DB2SqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAst
// Check if current query part is already row numbering to avoid infinite recursion // Check if current query part is already row numbering to avoid infinite recursion
return getQueryPartForRowNumbering() != queryPart && ( return getQueryPartForRowNumbering() != queryPart && (
useOffsetFetchClause( queryPart ) && !isRowsOnlyFetchClauseType( queryPart ) useOffsetFetchClause( queryPart ) && !isRowsOnlyFetchClauseType( queryPart )
|| getDialectVersion().isBefore( 11, 1 ) && ( queryPart.isRoot() && hasLimit() || !( queryPart.getFetchClauseExpression() instanceof Literal ) ) || getDB2Version().isBefore( 11, 1 ) && ( queryPart.isRoot() && hasLimit() || !( queryPart.getFetchClauseExpression() instanceof Literal ) )
); );
} }
protected boolean supportsOffsetClause() { protected boolean supportsOffsetClause() {
return getDialectVersion().isSameOrAfter( 11, 1 ); return getDB2Version().isSameOrAfter( 11, 1 );
} }
@Override @Override
@ -228,7 +228,7 @@ public class DB2SqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAst
@Override @Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) { protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
if ( getDialectVersion().isSameOrAfter( 11, 1 ) ) { if ( getDB2Version().isSameOrAfter( 11, 1 ) ) {
renderComparisonStandard( lhs, operator, rhs ); renderComparisonStandard( lhs, operator, rhs );
} }
else { else {
@ -296,12 +296,8 @@ public class DB2SqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAst
// For DB2 we use #renderReturningClause to render a wrapper around the DML statement // For DB2 we use #renderReturningClause to render a wrapper around the DML statement
} }
private DatabaseVersion getDialectVersion() { public DatabaseVersion getDB2Version() {
final var dialect = getDialect(); return this.getDialect().getVersion();
if (dialect instanceof DB2Dialect) {
return ((DB2Dialect) dialect).getDB2Version();
}
return dialect.getVersion();
} }
} }

View File

@ -48,4 +48,8 @@ public class DB2iSqlAstTranslator<T extends JdbcOperation> extends DB2SqlAstTran
renderComparisonStandard( lhs, operator, rhs ); renderComparisonStandard( lhs, operator, rhs );
} }
@Override
public DatabaseVersion getDB2Version() {
return DatabaseVersion.make(9, 0);
}
} }

View File

@ -75,4 +75,9 @@ public class DB2zSqlAstTranslator<T extends JdbcOperation> extends DB2SqlAstTran
append( CLOSE_PARENTHESIS ); append( CLOSE_PARENTHESIS );
renderDerivedTableReference( tableReference ); renderDerivedTableReference( tableReference );
} }
@Override
public DatabaseVersion getDB2Version() {
return DatabaseVersion.make(9, 0);
}
} }