HHH-14251 Fix issue for Dialects not supporting row value constructor Syntax

This commit is contained in:
Andrea Boriero 2020-10-12 15:07:29 +01:00 committed by Sanne Grinovero
parent ec7a278358
commit 54ea3c15bf
1 changed files with 34 additions and 16 deletions

View File

@ -111,7 +111,7 @@ public class BinaryLogicOperatorNode extends AbstractSelectExpression implements
// mutation depends on the types of nodes involved... // mutation depends on the types of nodes involved...
int comparisonType = getType(); int comparisonType = getType();
String comparisonText = getText(); String comparisonText = getText();
if ( !isInsideSetClause() ) {
switch ( comparisonType ) { switch ( comparisonType ) {
case HqlSqlTokenTypes.EQ: case HqlSqlTokenTypes.EQ:
setType( HqlSqlTokenTypes.AND ); setType( HqlSqlTokenTypes.AND );
@ -126,6 +126,7 @@ public class BinaryLogicOperatorNode extends AbstractSelectExpression implements
default: default:
throw new QuerySyntaxException( comparisonText + " operator not supported on composite types." ); throw new QuerySyntaxException( comparisonText + " operator not supported on composite types." );
} }
}
String[] lhsElementTexts = extractMutationTexts( getLeftHandOperand(), valueElements ); String[] lhsElementTexts = extractMutationTexts( getLeftHandOperand(), valueElements );
String[] rhsElementTexts = extractMutationTexts( getRightHandOperand(), valueElements ); String[] rhsElementTexts = extractMutationTexts( getRightHandOperand(), valueElements );
@ -153,8 +154,10 @@ public class BinaryLogicOperatorNode extends AbstractSelectExpression implements
} }
protected void translate( protected void translate(
int valueElements, int comparisonType, int valueElements,
String comparisonText, String[] lhsElementTexts, int comparisonType,
String comparisonText,
String[] lhsElementTexts,
String[] rhsElementTexts, String[] rhsElementTexts,
ParameterSpecification lhsEmbeddedCompositeParameterSpecification, ParameterSpecification lhsEmbeddedCompositeParameterSpecification,
ParameterSpecification rhsEmbeddedCompositeParameterSpecification, ParameterSpecification rhsEmbeddedCompositeParameterSpecification,
@ -164,14 +167,21 @@ public class BinaryLogicOperatorNode extends AbstractSelectExpression implements
for ( int i = valueElements - 1; i > 0; i-- ) { for ( int i = valueElements - 1; i > 0; i-- ) {
if ( i == 1 ) { if ( i == 1 ) {
AST op1 = getASTFactory().create( comparisonType, comparisonText ); final AST op1;
if ( isInsideSetClause() ) {
op1 = container;
}
else {
op1 = getASTFactory().create( comparisonType, comparisonText );
}
SqlFragment lhs1 = (SqlFragment) getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, lhsElementTexts[0] ); SqlFragment lhs1 = (SqlFragment) getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, lhsElementTexts[0] );
SqlFragment rhs1 = (SqlFragment) getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, rhsElementTexts[0] ); SqlFragment rhs1 = (SqlFragment) getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, rhsElementTexts[0] );
copyReferencedTables( leftHandOperand, lhs1 ); copyReferencedTables( leftHandOperand, lhs1 );
copyReferencedTables( rightHandOperand, rhs1 ); copyReferencedTables( rightHandOperand, rhs1 );
op1.setFirstChild( lhs1 ); op1.setFirstChild( lhs1 );
lhs1.setNextSibling( rhs1 ); lhs1.setNextSibling( rhs1 );
container.setFirstChild( op1 );
AST op2 = getASTFactory().create( comparisonType, comparisonText ); AST op2 = getASTFactory().create( comparisonType, comparisonText );
SqlFragment lhs2 = (SqlFragment) getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, lhsElementTexts[1] ); SqlFragment lhs2 = (SqlFragment) getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, lhsElementTexts[1] );
SqlFragment rhs2 = (SqlFragment) getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, rhsElementTexts[1] ); SqlFragment rhs2 = (SqlFragment) getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, rhsElementTexts[1] );
@ -181,6 +191,10 @@ public class BinaryLogicOperatorNode extends AbstractSelectExpression implements
lhs2.setNextSibling( rhs2 ); lhs2.setNextSibling( rhs2 );
op1.setNextSibling( op2 ); op1.setNextSibling( op2 );
if ( !isInsideSetClause() ) {
container.setFirstChild( op1 );
}
// "pass along" our initial embedded parameter node(s) to the first generated // "pass along" our initial embedded parameter node(s) to the first generated
// sql fragment so that it can be handled later for parameter binding... // sql fragment so that it can be handled later for parameter binding...
if ( lhsEmbeddedCompositeParameterSpecification != null ) { if ( lhsEmbeddedCompositeParameterSpecification != null ) {
@ -206,6 +220,10 @@ public class BinaryLogicOperatorNode extends AbstractSelectExpression implements
} }
} }
private boolean isInsideSetClause() {
return getWalker().getCurrentClauseType() == HqlSqlTokenTypes.SET;
}
private static void copyReferencedTables(Node from, SqlFragment to) { private static void copyReferencedTables(Node from, SqlFragment to) {
if (from instanceof TableReferenceNode) { if (from instanceof TableReferenceNode) {
TableReferenceNode tableReferenceNode = (TableReferenceNode) from; TableReferenceNode tableReferenceNode = (TableReferenceNode) from;