translatePredicate(union.getLeft(), tableName, where);
where.or();
translatePredicate(union.getRight(), tableName, where);
where.closeParen();
} else if (predicate instanceof Literal) {
Literal literal = (Literal)predicate;
if (literal.isInteger()) return tableName; // do nothing, since this is a path constraint and is handled elsewhere
} else if (predicate instanceof AttributeNameTest) {
// This adds the criteria that the attribute exists, and adds it to the select ...
AttributeNameTest attribute = (AttributeNameTest)predicate;
String propertyName = nameFrom(attribute.getNameTest());
// There is nothing in the JCR 1.0 spec that says that a property constrain implies it should be included in the
// result columns
// builder.select(tableName + "." + propertyName);
where.hasProperty(tableName, propertyName);
} else if (predicate instanceof NameTest) {
// This adds the criteria that the child node exists ...
NameTest childName = (NameTest)predicate;
String alias = newAlias();
builder.joinAllNodesAs(alias).onChildNode(tableName, alias);
if (!childName.isWildcard()) where.nodeName(alias).isEqualTo(nameFrom(childName));
tableName = alias;
} else if (predicate instanceof Comparison) {
Comparison comparison = (Comparison)predicate;
Component left = comparison.getLeft();
Component right = comparison.getRight();
Operator operator = comparison.getOperator();
if (left instanceof Literal) {
Component temp = left;
left = right;
right = temp;
operator = operator.reverse();
}
if (left instanceof NodeTest) {
NodeTest nodeTest = (NodeTest)left;
String propertyName = null;
if (nodeTest instanceof AttributeNameTest) {
AttributeNameTest attribute = (AttributeNameTest)left;
propertyName = nameFrom(attribute.getNameTest());
} else if (nodeTest instanceof NameTest) {
NameTest nameTest = (NameTest)left;
propertyName = nameFrom(nameTest);
} else {
throw new InvalidQueryException(query,
"Left hand side of a comparison must be a name test or attribute name test; therefore '"
+ comparison + "' is not valid");
}
if (right instanceof Literal) {
String value = ((Literal)right).getValue();
where.propertyValue(tableName, propertyName).is(operator, value);
} else if (right instanceof FunctionCall) {
FunctionCall call = (FunctionCall)right;
NameTest functionName = call.getName();
List<Component> parameters = call.getParameters();
// Is this a cast ...
String castType = CAST_FUNCTION_NAME_TO_TYPE.get(functionName);
if (castType != null) {
if (parameters.size() == 1 && parameters.get(0).collapse() instanceof Literal) {
// The first parameter can be the type name (or table name) ...
Literal value = (Literal)parameters.get(0).collapse();
where.propertyValue(tableName, propertyName).is(operator).cast(value.getValue()).as(castType);
} else {
throw new InvalidQueryException(query, "A cast function requires one literal parameter; therefore '"
+ comparison + "' is not valid");
}
} else {