Search in sources :

Example 1 with NodeName

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

the class QueryObjectModelFactoryTest method testNodeName.

/**
     * Test case for {@link QueryObjectModelFactory#nodeName(String)}
     */
public void testNodeName() throws RepositoryException {
    NodeName nodeName = qf.nodeName(SELECTOR_NAME1);
    assertEquals("Wrong selector name", SELECTOR_NAME1, nodeName.getSelectorName());
}
Also used : NodeName(javax.jcr.query.qom.NodeName)

Example 2 with NodeName

use of javax.jcr.query.qom.NodeName 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 NodeName

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

the class LuceneQueryFactory method getComparisonQuery.

protected Query getComparisonQuery(DynamicOperand left, int transform, String operator, StaticOperand rigth, Map<String, NodeType> selectorMap) throws RepositoryException {
    if (left instanceof PropertyValue) {
        PropertyValue pv = (PropertyValue) left;
        String field = npResolver.getJCRName(session.getQName(pv.getPropertyName()));
        int type = PropertyType.UNDEFINED;
        NodeType nt = selectorMap.get(pv.getSelectorName());
        if (nt != null) {
            for (PropertyDefinition pd : nt.getPropertyDefinitions()) {
                if (pd.getName().equals(pv.getPropertyName())) {
                    type = pd.getRequiredType();
                    break;
                }
            }
        }
        return getPropertyValueQuery(field, operator, evaluator.getValue(rigth), type, transform);
    } else if (left instanceof NodeName) {
        return getNodeNameQuery(transform, operator, rigth);
    } else if (left instanceof NodeLocalName) {
        return getNodeLocalNameQuery(transform, operator, rigth);
    } else {
        throw new UnsupportedRepositoryOperationException(// FIXME
        "Unknown operand type: " + left);
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NodeName(javax.jcr.query.qom.NodeName) NodeType(javax.jcr.nodetype.NodeType) PropertyValue(javax.jcr.query.qom.PropertyValue) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) Constraint(javax.jcr.query.qom.Constraint) NodeLocalName(javax.jcr.query.qom.NodeLocalName)

Example 4 with NodeName

use of javax.jcr.query.qom.NodeName in project jackrabbit-oak by apache.

the class QomTest method nodeName.

@Test
public void nodeName() throws RepositoryException {
    NodeName n = f.nodeName("selectorName");
    assertEquals("selectorName", n.getSelectorName());
    assertEquals("NAME([selectorName])", n.toString());
    assertEquals("NAME()", f.nodeName(null).toString());
}
Also used : NodeName(javax.jcr.query.qom.NodeName) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 5 with NodeName

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

the class OperandEvaluator method getValues.

/**
     * Evaluates the given operand in the context of the given row.
     *
     * @param operand operand to be evaluated
     * @param row query result row
     * @return values of the operand at the given row
     * @throws RepositoryException if the operand can't be evaluated
     */
public Value[] getValues(Operand operand, Row row) throws RepositoryException {
    if (operand instanceof StaticOperand) {
        StaticOperand so = (StaticOperand) operand;
        return new Value[] { getValue(so) };
    } else if (operand instanceof FullTextSearchScore) {
        FullTextSearchScore ftss = (FullTextSearchScore) operand;
        double score = row.getScore(ftss.getSelectorName());
        return new Value[] { factory.createValue(score) };
    } else if (operand instanceof NodeName) {
        NodeName nn = (NodeName) operand;
        String name = row.getNode(nn.getSelectorName()).getName();
        // root node
        if ("".equals(name)) {
            return new Value[] { factory.createValue(name, PropertyType.STRING) };
        }
        return new Value[] { factory.createValue(name, PropertyType.NAME) };
    } else if (operand instanceof Length) {
        return getLengthValues((Length) operand, row);
    } else if (operand instanceof LowerCase) {
        return getLowerCaseValues((LowerCase) operand, row);
    } else if (operand instanceof UpperCase) {
        return getUpperCaseValues((UpperCase) operand, row);
    } else if (operand instanceof NodeLocalName) {
        return getNodeLocalNameValues((NodeLocalName) operand, row);
    } else if (operand instanceof PropertyValue) {
        return getPropertyValues((PropertyValue) operand, row);
    } else {
        throw new UnsupportedRepositoryOperationException("Unknown operand type: " + operand);
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) UpperCase(javax.jcr.query.qom.UpperCase) StaticOperand(javax.jcr.query.qom.StaticOperand) NodeName(javax.jcr.query.qom.NodeName) Length(javax.jcr.query.qom.Length) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) BindVariableValue(javax.jcr.query.qom.BindVariableValue) LowerCase(javax.jcr.query.qom.LowerCase) PropertyValue(javax.jcr.query.qom.PropertyValue) FullTextSearchScore(javax.jcr.query.qom.FullTextSearchScore) NodeLocalName(javax.jcr.query.qom.NodeLocalName)

Aggregations

NodeName (javax.jcr.query.qom.NodeName)6 NodeLocalName (javax.jcr.query.qom.NodeLocalName)3 PropertyValue (javax.jcr.query.qom.PropertyValue)3 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)2 Value (javax.jcr.Value)2 FullTextSearchScore (javax.jcr.query.qom.FullTextSearchScore)2 Length (javax.jcr.query.qom.Length)2 StaticOperand (javax.jcr.query.qom.StaticOperand)2 ValueFormatException (javax.jcr.ValueFormatException)1 NodeType (javax.jcr.nodetype.NodeType)1 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1 Row (javax.jcr.query.Row)1 And (javax.jcr.query.qom.And)1 BindVariableValue (javax.jcr.query.qom.BindVariableValue)1 Comparison (javax.jcr.query.qom.Comparison)1 Constraint (javax.jcr.query.qom.Constraint)1 DescendantNode (javax.jcr.query.qom.DescendantNode)1 DynamicOperand (javax.jcr.query.qom.DynamicOperand)1 LowerCase (javax.jcr.query.qom.LowerCase)1