HHH-3749 : limit FromElement reuse
git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_3@15873 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
9bfb17b497
commit
7b943f0089
|
@ -28,7 +28,6 @@ import org.hibernate.QueryException;
|
|||
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 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
|
|||
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) {
|
||||
|
|
Loading…
Reference in New Issue