// Now add the criteria ...
where.search(alias, value);
tableName = alias;
} else if (param1 instanceof PathExpression) {
// refers to a descendant node ...
PathExpression pathExpr = (PathExpression)param1;
if (pathExpr.getLastStep().collapse() instanceof AttributeNameTest) {
AttributeNameTest attributeName = (AttributeNameTest)pathExpr.getLastStep().collapse();
pathExpr = pathExpr.withoutLast();
String searchTable = translatePredicate(pathExpr, tableName, where);
if (attributeName.getNameTest().isWildcard()) {
where.search(searchTable, value);
} else {
where.search(searchTable, nameFrom(attributeName.getNameTest()), value);
}
} else {
String searchTable = translatePredicate(param1, tableName, where);
where.search(searchTable, value);
}
} else {
throw new InvalidQueryException(query,
"The first parameter of 'jcr:contains' must be a relative path (e.g., '.', an attribute name, a child name, etc.); therefore '"
+ predicate + "' is not valid");
}
} else if (functionName.matches("jcr", "deref")) {
throw new InvalidQueryException(query,
"The 'jcr:deref' function is not required by JCR and is not currently supported; therefore '"
+ predicate + "' is not valid");
} else {
throw new InvalidQueryException(query,
"Only the 'jcr:like' and 'jcr:contains' functions are allowed in a predicate; therefore '"
+ predicate + "' is not valid");
}
} else if (predicate instanceof PathExpression) {
// Requires that the descendant node with the relative path does exist ...
PathExpression pathExpr = (PathExpression)predicate;
List<StepExpression> steps = pathExpr.getSteps();
OrderBy orderBy = pathExpr.getOrderBy();
assert steps.size() > 1; // 1 or 0 would have been collapsed ...
Component firstStep = steps.get(0).collapse();
if (firstStep instanceof ContextItem) {
// Remove the context and retry ...
return translatePredicate(new PathExpression(true, steps.subList(1, steps.size()), orderBy), tableName, where);
}
if (firstStep instanceof NameTest) {
// Special case where this is similar to '[a/@id]'
NameTest childName = (NameTest)firstStep;
String alias = newAlias();
builder.joinAllNodesAs(alias).onChildNode(tableName, alias);
if (!childName.isWildcard()) {
where.nodeName(alias).isEqualTo(nameFrom(childName));
}
return translatePredicate(new PathExpression(true, steps.subList(1, steps.size()), orderBy), alias, where);
}
if (firstStep instanceof DescendantOrSelf) {
// Special case where this is similar to '[a/@id]'
String alias = newAlias();
builder.joinAllNodesAs(alias).onDescendant(tableName, alias);
return translatePredicate(new PathExpression(true, steps.subList(1, steps.size()), orderBy), alias, where);
}
// Add the join ...
String alias = newAlias();
builder.joinAllNodesAs(alias).onDescendant(tableName, alias);
// Now add the criteria ...