[hibernate-commits] Hibernate SVN: r15873 - core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Feb 3 16:38:29 EST 2009


Author: steve.ebersole at jboss.com
Date: 2009-02-03 16:38:29 -0500 (Tue, 03 Feb 2009)
New Revision: 15873

Modified:
   core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java
Log:
HHH-3749 : limit FromElement reuse

Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java	2009-02-03 20:49:00 UTC (rev 15872)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/DotNode.java	2009-02-03 21:38:29 UTC (rev 15873)
@@ -28,7 +28,6 @@
 import org.hibernate.engine.JoinSequence;
 import org.hibernate.hql.CollectionProperties;
 import org.hibernate.hql.antlr.SqlTokenTypes;
-import org.hibernate.hql.ast.util.ASTPrinter;
 import org.hibernate.hql.ast.util.ASTUtil;
 import org.hibernate.hql.ast.util.ColumnHelper;
 import org.hibernate.persister.collection.QueryableCollection;
@@ -435,10 +434,8 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 		boolean found = elem != null;
-		// even though we might find a pre-existing element by join path, for FromElements originating in a from-clause
-		// we should only ever use the found element if the aliases match (null != null here).  Implied joins are
-		// always (?) ok to reuse.
-		boolean useFoundFromElement = found && ( elem.isImplied() || areSame( classAlias, elem.getClassAlias() ) );
+		// even though we might find a pre-existing element by join path, we may not be able to reuse it...
+		boolean useFoundFromElement = found && canReuse( elem, classAlias );
 
 		if ( ! useFoundFromElement ) {
 			// If this is an implied join in a from element, then use the impled join type which is part of the
@@ -472,9 +469,28 @@
 		setFromElement( elem );	// This 'dot' expression now refers to the resulting from element.
 	}
 
+	private boolean canReuse(FromElement fromElement, String requestedAlias) {
+		// implicit joins are always(?) ok to reuse
+		if ( isImplicitJoin( fromElement ) ) {
+			return true;
+		}
+
+		// if the from-clauses are the same, we can be a little more aggressive in terms of what we reuse
+		if ( fromElement.getFromClause() == getWalker().getCurrentFromClause() ) {
+			return true;
+		}
+
+		// otherwise (subquery case) dont reuse the fromElement if we are processing the from-clause of the subquery
+		return getWalker().getCurrentClauseType() != SqlTokenTypes.FROM;
+	}
+
+	private boolean isImplicitJoin(FromElement fromElement) {
+		return fromElement.isImplied();
+	}
+
 	private boolean areSame(String alias1, String alias2) {
 		// again, null != null here
-		return !StringHelper.isEmpty( alias1 ) && !StringHelper.isEmpty( alias2 ) && alias1.equals( alias2 );
+		return StringHelper.isNotEmpty( alias1 ) && StringHelper.isNotEmpty( alias2 ) && alias1.equals( alias2 );
 	}
 
 	private void setImpliedJoin(FromElement elem) {




More information about the hibernate-commits mailing list