Fix for issue OPENJPA-51. It should also resolve issue OPENJPA-173.

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@534623 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David J. Wisneski 2007-05-02 21:35:55 +00:00
parent 43c931014a
commit d5d214c182
1 changed files with 27 additions and 7 deletions

View File

@ -158,6 +158,13 @@ public class SelectImpl
// from select if this select selects from a tmp table created by another
private SelectImpl _from = null;
private SelectImpl _outer = null;
// bitSet indicating if an alias is removed from parent select
// bit 0 : correspond to alias 0
// bit 1 : correspond to alias 1, etc.
// if the bit is set, the corresponding alias has been removed from parent
// and recorded under subselect.
private int _removedAliasFromParent = 0;
/**
* Helper method to return the proper table alias for the given alias index.
@ -1487,8 +1494,13 @@ public class SelectImpl
private void removeParentJoins(PathJoins pj) {
if (_parent == null)
return;
if (_parent._joins != null && !_parent._joins.isEmpty())
pj.joins().removeAll(_parent._joins.joins());
if (_parent._joins != null && !_parent._joins.isEmpty()) {
boolean removed = false;
if (_removedAliasFromParent > 0)
removed = _parent._joins.joins().removeAll(pj.joins());
if (!removed)
pj.joins().removeAll(_parent._joins.joins());
}
if (!pj.isEmpty())
_parent.removeParentJoins(pj);
}
@ -1897,9 +1909,15 @@ public class SelectImpl
}
}
if (!fromParent && _parent != null) {
alias = _parent.findAlias(table, key, false, this);
if (alias != null)
boolean removeAliasFromParent = key.toString().contains(":");
alias = _parent.findAlias(table, key, removeAliasFromParent, this);
if (alias != null) {
if (removeAliasFromParent) {
recordTableAlias(table, key, alias);
_removedAliasFromParent |= (1 << alias.intValue());
}
return alias;
}
}
if (_subsels != null) {
SelectImpl sub;
@ -1913,9 +1931,11 @@ public class SelectImpl
if (sub._tables != null)
sub._tables.remove(alias);
} else {
alias = sub.findAlias(table, key, true, null);
if (!fromParent && alias != null)
recordTableAlias(table, key, alias);
if (fromSub == null) {
alias = sub.findAlias(table, key, true, null);
if (!fromParent && alias != null)
recordTableAlias(table, key, alias);
}
}
}
}