Search in sources :

Example 1 with DynamicOperand

use of javax.jcr.query.qom.DynamicOperand in project jackrabbit by apache.

the class Parser method parseCondition.

private Constraint parseCondition() throws RepositoryException {
    Constraint a;
    if (readIf("NOT")) {
        a = factory.not(parseConstraint());
    } else if (readIf("(")) {
        a = parseConstraint();
        read(")");
    } else if (currentTokenType == IDENTIFIER) {
        String identifier = readName();
        if (readIf("(")) {
            a = parseConditionFuntionIf(identifier);
            if (a == null) {
                DynamicOperand op = parseExpressionFunction(identifier);
                a = parseCondition(op);
            }
        } else if (readIf(".")) {
            a = parseCondition(factory.propertyValue(identifier, readName()));
        } else {
            a = parseCondition(factory.propertyValue(getOnlySelectorName(identifier), identifier));
        }
    } else if ("[".equals(currentToken)) {
        String name = readName();
        if (readIf(".")) {
            a = parseCondition(factory.propertyValue(name, readName()));
        } else {
            a = parseCondition(factory.propertyValue(getOnlySelectorName(name), name));
        }
    } else {
        throw getSyntaxError();
    }
    return a;
}
Also used : Constraint(javax.jcr.query.qom.Constraint) DynamicOperand(javax.jcr.query.qom.DynamicOperand)

Example 2 with DynamicOperand

use of javax.jcr.query.qom.DynamicOperand in project jackrabbit by apache.

the class LuceneQueryFactory method mapConstraintToQueryAndFilter.

protected Predicate mapConstraintToQueryAndFilter(QueryPair query, Constraint constraint, Map<String, NodeType> selectorMap, JackrabbitIndexSearcher searcher, IndexReader reader) throws RepositoryException, IOException {
    Predicate filter = Predicate.TRUE;
    if (constraint instanceof And) {
        And and = (And) constraint;
        filter = mapConstraintToQueryAndFilter(query, and.getConstraint1(), selectorMap, searcher, reader);
        Predicate other = mapConstraintToQueryAndFilter(query, and.getConstraint2(), selectorMap, searcher, reader);
        if (filter == Predicate.TRUE) {
            filter = other;
        } else if (other != Predicate.TRUE) {
            filter = Predicates.and(filter, other);
        }
    } else if (constraint instanceof Comparison) {
        Comparison c = (Comparison) constraint;
        Transform transform = new Transform(c.getOperand1());
        DynamicOperand left = transform.operand;
        final String operator = c.getOperator();
        StaticOperand right = c.getOperand2();
        if (left instanceof Length || left instanceof FullTextSearchScore || (((!JCR_OPERATOR_EQUAL_TO.equals(operator) && !JCR_OPERATOR_LIKE.equals(operator)) || transform.transform != TRANSFORM_NONE) && (left instanceof NodeName || left instanceof NodeLocalName))) {
            try {
                int type = PropertyType.UNDEFINED;
                if (left instanceof Length) {
                    type = PropertyType.LONG;
                } else if (left instanceof FullTextSearchScore) {
                    type = PropertyType.DOUBLE;
                }
                final DynamicOperand operand = c.getOperand1();
                final Value value = evaluator.getValue(right, type);
                filter = new RowPredicate() {

                    @Override
                    protected boolean evaluate(Row row) throws RepositoryException {
                        return new ValueComparator().evaluate(operator, evaluator.getValue(operand, row), value);
                    }
                };
            } catch (ValueFormatException e) {
                throw new InvalidQueryException(e);
            }
        } else {
            Query cq = getComparisonQuery(left, transform.transform, operator, right, selectorMap);
            query.subQuery.add(cq, MUST);
        }
    } else if (constraint instanceof DescendantNode) {
        final DescendantNode descendantNode = (DescendantNode) constraint;
        Query context = getNodeIdQuery(UUID, descendantNode.getAncestorPath());
        query.mainQuery = new DescendantSelfAxisQuery(context, query.subQuery, false);
    } else {
        query.subQuery.add(create(constraint, selectorMap, searcher), MUST);
    }
    return filter;
}
Also used : Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) DynamicOperand(javax.jcr.query.qom.DynamicOperand) StaticOperand(javax.jcr.query.qom.StaticOperand) NodeName(javax.jcr.query.qom.NodeName) ValueComparator(org.apache.jackrabbit.core.query.lucene.join.ValueComparator) Predicate(org.apache.jackrabbit.commons.predicate.Predicate) RowPredicate(org.apache.jackrabbit.commons.predicate.RowPredicate) NodeLocalName(javax.jcr.query.qom.NodeLocalName) RowPredicate(org.apache.jackrabbit.commons.predicate.RowPredicate) Comparison(javax.jcr.query.qom.Comparison) Length(javax.jcr.query.qom.Length) And(javax.jcr.query.qom.And) DescendantNode(javax.jcr.query.qom.DescendantNode) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) ValueFormatException(javax.jcr.ValueFormatException) FullTextSearchScore(javax.jcr.query.qom.FullTextSearchScore) SelectorRow(org.apache.jackrabbit.core.query.lucene.join.SelectorRow) Row(javax.jcr.query.Row) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 3 with DynamicOperand

use of javax.jcr.query.qom.DynamicOperand in project jackrabbit by apache.

the class Parser method parseOrder.

private Ordering[] parseOrder() throws RepositoryException {
    ArrayList<Ordering> orderList = new ArrayList<Ordering>();
    do {
        Ordering ordering;
        DynamicOperand op = parseDynamicOperand();
        if (readIf("DESC")) {
            ordering = factory.descending(op);
        } else {
            readIf("ASC");
            ordering = factory.ascending(op);
        }
        orderList.add(ordering);
    } while (readIf(","));
    Ordering[] orderings = new Ordering[orderList.size()];
    orderList.toArray(orderings);
    return orderings;
}
Also used : DynamicOperand(javax.jcr.query.qom.DynamicOperand) ArrayList(java.util.ArrayList) Ordering(javax.jcr.query.qom.Ordering)

Example 4 with DynamicOperand

use of javax.jcr.query.qom.DynamicOperand in project jackrabbit by apache.

the class Parser method parseExpressionFunction.

private DynamicOperand parseExpressionFunction(String functionName) throws RepositoryException {
    DynamicOperand op;
    if ("LENGTH".equalsIgnoreCase(functionName)) {
        op = factory.length(parsePropertyValue(readName()));
    } else if ("NAME".equalsIgnoreCase(functionName)) {
        if (isToken(")")) {
            op = factory.nodeName(getOnlySelectorName("NAME()"));
        } else {
            op = factory.nodeName(readName());
        }
    } else if ("LOCALNAME".equalsIgnoreCase(functionName)) {
        if (isToken(")")) {
            op = factory.nodeLocalName(getOnlySelectorName("LOCALNAME()"));
        } else {
            op = factory.nodeLocalName(readName());
        }
    } else if ("SCORE".equalsIgnoreCase(functionName)) {
        if (isToken(")")) {
            op = factory.fullTextSearchScore(getOnlySelectorName("SCORE()"));
        } else {
            op = factory.fullTextSearchScore(readName());
        }
    } else if ("LOWER".equalsIgnoreCase(functionName)) {
        op = factory.lowerCase(parseDynamicOperand());
    } else if ("UPPER".equalsIgnoreCase(functionName)) {
        op = factory.upperCase(parseDynamicOperand());
    } else {
        throw getSyntaxError("LENGTH, NAME, LOCALNAME, SCORE, LOWER, UPPER, or CAST");
    }
    read(")");
    return op;
}
Also used : DynamicOperand(javax.jcr.query.qom.DynamicOperand)

Example 5 with DynamicOperand

use of javax.jcr.query.qom.DynamicOperand in project jackrabbit by apache.

the class AbstractOrderByTest method createQOM.

/**
     * @return a basic QOM to test order by queries.
     * @throws RepositoryException if an error occurs.
     */
protected QueryObjectModel createQOM(boolean ascending) throws RepositoryException {
    DynamicOperand op = createOrderingOperand();
    Ordering ordering;
    if (ascending) {
        ordering = qf.ascending(op);
    } else {
        ordering = qf.descending(op);
    }
    return qf.createQuery(qf.selector(testNodeType, "s"), qf.descendantNode("s", testRoot), new Ordering[] { ordering }, null);
}
Also used : DynamicOperand(javax.jcr.query.qom.DynamicOperand) Ordering(javax.jcr.query.qom.Ordering)

Aggregations

DynamicOperand (javax.jcr.query.qom.DynamicOperand)5 Ordering (javax.jcr.query.qom.Ordering)2 ArrayList (java.util.ArrayList)1 Value (javax.jcr.Value)1 ValueFormatException (javax.jcr.ValueFormatException)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1 Row (javax.jcr.query.Row)1 And (javax.jcr.query.qom.And)1 Comparison (javax.jcr.query.qom.Comparison)1 Constraint (javax.jcr.query.qom.Constraint)1 DescendantNode (javax.jcr.query.qom.DescendantNode)1 FullTextSearchScore (javax.jcr.query.qom.FullTextSearchScore)1 Length (javax.jcr.query.qom.Length)1 NodeLocalName (javax.jcr.query.qom.NodeLocalName)1 NodeName (javax.jcr.query.qom.NodeName)1 PropertyValue (javax.jcr.query.qom.PropertyValue)1 StaticOperand (javax.jcr.query.qom.StaticOperand)1 Predicate (org.apache.jackrabbit.commons.predicate.Predicate)1 RowPredicate (org.apache.jackrabbit.commons.predicate.RowPredicate)1 SelectorRow (org.apache.jackrabbit.core.query.lucene.join.SelectorRow)1