use of org.apache.jackrabbit.oak.query.ast.ConstraintImpl in project jackrabbit-oak by apache.
the class SQL2Parser method parseCondition.
private ConstraintImpl parseCondition(DynamicOperandImpl left) throws ParseException {
ConstraintImpl c;
if (readIf("=")) {
c = factory.comparison(left, Operator.EQUAL, parseStaticOperand());
} else if (readIf("<>")) {
c = factory.comparison(left, Operator.NOT_EQUAL, parseStaticOperand());
} else if (readIf("<")) {
c = factory.comparison(left, Operator.LESS_THAN, parseStaticOperand());
} else if (readIf(">")) {
c = factory.comparison(left, Operator.GREATER_THAN, parseStaticOperand());
} else if (readIf("<=")) {
c = factory.comparison(left, Operator.LESS_OR_EQUAL, parseStaticOperand());
} else if (readIf(">=")) {
c = factory.comparison(left, Operator.GREATER_OR_EQUAL, parseStaticOperand());
} else if (readIf("LIKE")) {
c = factory.comparison(left, Operator.LIKE, parseStaticOperand());
if (supportSQL1) {
if (readIf("ESCAPE")) {
StaticOperandImpl esc = parseStaticOperand();
if (!(esc instanceof LiteralImpl)) {
throw getSyntaxError("only ESCAPE '\' is supported");
}
PropertyValue v = ((LiteralImpl) esc).getLiteralValue();
if (!v.getValue(Type.STRING).equals("\\")) {
throw getSyntaxError("only ESCAPE '\' is supported");
}
}
}
} else if (readIf("IN")) {
read("(");
ArrayList<StaticOperandImpl> list = new ArrayList<StaticOperandImpl>();
do {
StaticOperandImpl x = parseStaticOperand();
list.add(x);
} while (readIf(","));
read(")");
c = factory.in(left, list);
} else if (readIf("IS")) {
boolean not = readIf("NOT");
read("NULL");
if (!(left instanceof PropertyValueImpl)) {
throw getSyntaxError("propertyName (NOT NULL is only supported for properties)");
}
PropertyValueImpl p = (PropertyValueImpl) left;
if (not) {
c = getPropertyExistence(p);
} else {
c = getPropertyInexistence(p);
}
} else if (readIf("NOT")) {
if (readIf("IS")) {
read("NULL");
if (!(left instanceof PropertyValueImpl)) {
throw new ParseException("Only property values can be tested for NOT IS NULL; got: " + left.getClass().getName(), parseIndex);
}
PropertyValueImpl pv = (PropertyValueImpl) left;
c = getPropertyExistence(pv);
} else {
read("LIKE");
c = factory.comparison(left, Operator.LIKE, parseStaticOperand());
c = factory.not(c);
}
} else {
throw getSyntaxError();
}
return c;
}
use of org.apache.jackrabbit.oak.query.ast.ConstraintImpl in project jackrabbit-oak by apache.
the class QueryCostOverheadTest method getCostOverhead.
@Test
public void getCostOverhead() {
QueryImpl query;
UnionQueryImpl union;
ConstraintImpl c, c1, c2, c3, c4, c5;
c1 = new ComparisonImpl(null, null, null);
c2 = new FullTextSearchImpl(null, null, null);
union = new UnionQueryImpl(false, new QueryImpl(null, null, c1, null, null, null), new QueryImpl(null, null, c2, null, null, null), null);
assertFalse("we always expect false from a `UnionQueryImpl`", union.containsUnfilteredFullTextCondition());
c1 = new ComparisonImpl(null, null, null);
c2 = new FullTextSearchImpl(null, null, null);
c = new OrImpl(c1, c2);
query = new QueryImpl(null, null, c, null, null, null);
assertTrue(query.containsUnfilteredFullTextCondition());
c1 = new ComparisonImpl(null, null, null);
c2 = new FullTextSearchImpl(null, null, null);
c3 = new FullTextSearchImpl(null, null, null);
c = new OrImpl(of(c1, c2, c3));
query = new QueryImpl(null, null, c, null, null, null);
assertTrue(query.containsUnfilteredFullTextCondition());
c2 = new FullTextSearchImpl(null, null, null);
c3 = new FullTextSearchImpl(null, null, null);
c4 = new ComparisonImpl(null, null, null);
c1 = new OrImpl(of(c2, c3, c4));
c5 = mock(DescendantNodeImpl.class);
c = new AndImpl(c1, c5);
query = new QueryImpl(null, null, c, null, null, null);
assertTrue(query.containsUnfilteredFullTextCondition());
c = new FullTextSearchImpl(null, null, null);
query = new QueryImpl(null, null, c, null, null, null);
assertFalse(query.containsUnfilteredFullTextCondition());
c1 = new FullTextSearchImpl(null, null, null);
c2 = new FullTextSearchImpl(null, null, null);
c3 = new FullTextSearchImpl(null, null, null);
c = new OrImpl(of(c1, c2, c3));
query = new QueryImpl(null, null, c, null, null, null);
assertFalse(query.containsUnfilteredFullTextCondition());
c1 = new ComparisonImpl(null, null, null);
c2 = new FullTextSearchImpl(null, null, null);
c3 = new FullTextSearchImpl(null, null, null);
c = new AndImpl(of(c1, c2, c3));
query = new QueryImpl(null, null, c, null, null, null);
assertFalse(query.containsUnfilteredFullTextCondition());
c1 = new ComparisonImpl(null, null, null);
c2 = new ComparisonImpl(null, null, null);
c = new AndImpl(of(c1, c2, c3));
query = new QueryImpl(null, null, c, null, null, null);
assertFalse(query.containsUnfilteredFullTextCondition());
}
Aggregations