From 3b85ae86586cc7e816255c5fdaa72d07a4872380 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Wed, 6 Nov 2013 10:19:29 +0800 Subject: [PATCH] HHH-8671 WithClauseTest.testWithClause fails on all QA databases --- .../engine/internal/JoinSequence.java | 2 +- .../hql/internal/ast/util/NodeTraverser.java | 30 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/JoinSequence.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/JoinSequence.java index 5d2f5d3177..0c95170394 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/JoinSequence.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/JoinSequence.java @@ -208,7 +208,7 @@ public class JoinSequence { condition = on; } - if ( withClauseFragment != null ) { + if ( withClauseFragment != null && !isManyToManyRoot( join.joinable )) { condition += " and " + withClauseFragment; } diff --git a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/util/NodeTraverser.java b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/util/NodeTraverser.java index ddf0b10a17..689ee535f4 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/util/NodeTraverser.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/util/NodeTraverser.java @@ -23,6 +23,8 @@ * */ package org.hibernate.hql.internal.ast.util; +import java.util.ArrayDeque; +import java.util.Deque; import java.util.Stack; import antlr.collections.AST; @@ -65,24 +67,24 @@ public class NodeTraverser { } visitDepthFirst( ast.getFirstChild() ); } - - private void visitDepthFirst(AST ast){ - if(ast==null){ + + private void visitDepthFirst(AST ast) { + if ( ast == null ) { return; } - Stack stack = new Stack(); - if ( ast != null ) { - stack.push( ast ); - while (!stack.empty()) { - ast = (AST) stack.pop(); - strategy.visit( ast ); - if ( ast.getNextSibling() != null ) - stack.push( ast.getNextSibling() ); - if ( ast.getFirstChild() != null ) - stack.push( ast.getFirstChild() ); + Deque stack = new ArrayDeque(); + stack.addLast( ast ); + while ( !stack.isEmpty() ) { + ast = stack.removeLast(); + strategy.visit( ast ); + if ( ast.getNextSibling() != null ) { + stack.addLast( ast.getNextSibling() ); + } + if ( ast.getFirstChild() != null ) { + stack.addLast( ast.getFirstChild() ); } } } - + }