private Path getPath(JPQLNode node, boolean pcOnly, boolean inner) {
// resolve the first element against the aliases map ...
// i.e., the path "SELECT x.id FROM SomeClass x where x.id > 10"
// will need to have "x" in the alias map in order to resolve
Path path = null;
final String name = firstChild(node).text;
final Value val = getVariable(name, false);
// handle the case where the class name is the alias
// for the candidate (we don't use variables for this)
if (name.equalsIgnoreCase(ctx().schemaAlias)) {
if (ctx().subquery != null) {
path = factory.newPath(ctx().subquery);
path.setMetaData(ctx().subquery.getMetaData());
} else {
path = factory.newPath();
path.setMetaData(ctx().meta);
}
} else if (getMetaDataForAlias(name) != null)
path = newPath(null, getMetaDataForAlias(name));
else if (val instanceof Path)
path = (Path) val;
else if (val.getMetaData() != null)
path = newPath(val, val.getMetaData());
else
throw parseException(EX_USER, "path-invalid",
new Object[]{ assemble(node), name }, null);
path.setSchemaAlias(name);
// walk through the children and assemble the path
boolean allowNull = !inner;
for (int i = 1; i < node.children.length; i++) {
if (path.isXPath()) {
for (int j = i; j <node.children.length; j++)
path = (Path) traverseXPath(path, node.children[j].text);
return path;
}
path = (Path) traversePath(path, node.children[i].text, pcOnly,
allowNull);
if (ctx().getParent() != null && ctx().getVariable(path.getSchemaAlias()) == null) {
path.setSubqueryContext(ctx(), name);
}
// all traversals but the first one will always be inner joins
allowNull = false;
}