HHH-14201 Fix test issues of NaturalIdDereferenceTest

This commit is contained in:
Christian Beikov 2020-09-14 14:34:33 +02:00
parent 20e5a5659b
commit 7ef5336fec
3 changed files with 20 additions and 7 deletions

View File

@ -193,13 +193,13 @@ whereClauseExpr
orderExprs { String ordExp = null; String ordDir = null; String ordNul = null; } orderExprs { String ordExp = null; String ordDir = null; String ordNul = null; }
// TODO: remove goofy space before the comma when we don't have to regression test anymore. // TODO: remove goofy space before the comma when we don't have to regression test anymore.
// Dialect is provided a hook to render each ORDER BY element, so the expression is being captured instead of // Dialect is provided a hook to render each ORDER BY element(except SQL_TOKEN), so the expression is being captured instead of
// printing to the SQL output directly. See Dialect#renderOrderByElement(String, String, String, NullPrecedence). // printing to the SQL output directly. See Dialect#renderOrderByElement(String, String, String, NullPrecedence).
: { captureExpressionStart(); } ( e:expr ) { captureExpressionFinish(); ordExp = resetCapture(); } : { captureExpressionStart(); } ( e:expr ) { captureExpressionFinish(); ordExp = resetCapture(); }
(dir:orderDirection { ordDir = #dir.getText(); })? (ordNul=nullOrdering)? (dir:orderDirection { ordDir = #dir.getText(); })? (ordNul=nullOrdering)?
// SQL Tokens without a direction and null ordering can be passed through as-is. // SQL Tokens can be passed through as-is.
// These tokens could be mapping defined order by fragments which are already rendered via the dialect hook // These tokens could be mapping defined order by fragments which are already rendered via the dialect hook
{ out( #e.getType() == SQL_TOKEN && ordDir == null && ordNul == null ? ordExp : renderOrderByElement( ordExp, ordDir, ordNul ) ); } { out( #e.getType() == SQL_TOKEN ? ordExp : renderOrderByElement( ordExp, ordDir, ordNul ) ); }
( {out(", "); } orderExprs )? ( {out(", "); } orderExprs )?
; ;

View File

@ -91,13 +91,23 @@ public class FromClause extends HqlSqlWalkerNode implements HqlSqlTokenTypes, Di
} }
} }
void moveFromElementToEnd(FromElement element) {
fromElements.remove( element );
fromElements.add( element );
}
public void finishInit() { public void finishInit() {
// Insert EntityJoinFromElements while maintaining their original position during depth-first traversal. // Insert the from elements into the AST in the same order as they were added to the HQL AST
FromElement lastFromElement = null; FromElement lastFromElement = null;
for ( FromElement fromElement : fromElements ) { for ( FromElement fromElement : fromElements ) {
if ( fromElement instanceof EntityJoinFromElement ) { if ( fromElement instanceof ComponentJoin ) {
assert lastFromElement != null; // Component joins are no "real" joins, so they can't be put into the AST
ASTUtil.insertChild( lastFromElement, fromElement ); continue;
}
fromElement.setFirstChild( null );
fromElement.setNextSibling( null );
if ( lastFromElement != null ) {
ASTUtil.appendChild( lastFromElement, fromElement );
} }
lastFromElement = fromElement; lastFromElement = fromElement;
} }

View File

@ -642,6 +642,9 @@ public class FromElement extends HqlSqlWalkerNode implements DisplayableNode, Pa
} }
public void setWithClauseFragment(AST ast, String withClauseFragment) { public void setWithClauseFragment(AST ast, String withClauseFragment) {
// Normally, the from element is added first, but since the with clause could introduce joins,
// we have to move the from element to the end to retain the proper join order
getFromClause().moveFromElementToEnd( this );
this.withClauseAst = ast; this.withClauseAst = ast;
this.withClauseFragment = withClauseFragment; this.withClauseFragment = withClauseFragment;
} }