Search in sources :

Example 11 with PropertyValue

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

the class QomTest method createQuery.

@Test
public void createQuery() throws RepositoryException {
    Selector s = f.selector("nt:file", "x");
    BindVariableValue b = f.bindVariable("var");
    Constraint c = f.propertyExistence("x", "c");
    PropertyValue p = f.propertyValue("x", "propertyName");
    c = f.and(f.comparison(p, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, b), c);
    Ordering o = f.ascending(p);
    Column col = f.column("x", "propertyName", "columnName");
    Ordering[] ords = new Ordering[] { o };
    Column[] cols = new Column[] { col };
    QueryObjectModel q = f.createQuery(s, c, ords, cols);
    assertEquals(Query.JCR_JQOM, q.getLanguage());
    String[] bv = q.getBindVariableNames();
    assertEquals(1, bv.length);
    assertEquals("var", bv[0]);
    assertEquals(s, q.getSource());
    assertEquals(c, q.getConstraint());
    assertEquals(o, q.getOrderings()[0]);
    assertEquals(col, q.getColumns()[0]);
}
Also used : BindVariableValue(javax.jcr.query.qom.BindVariableValue) Constraint(javax.jcr.query.qom.Constraint) Column(javax.jcr.query.qom.Column) Ordering(javax.jcr.query.qom.Ordering) PropertyValue(javax.jcr.query.qom.PropertyValue) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) Selector(javax.jcr.query.qom.Selector) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 12 with PropertyValue

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

the class QomTest method length.

@Test
public void length() throws RepositoryException {
    PropertyValue p = f.propertyValue("selectorName", "propertyName");
    Length l = f.length(p);
    assertEquals(p, l.getPropertyValue());
    assertEquals("LENGTH([selectorName].[propertyName])", l.toString());
}
Also used : Length(javax.jcr.query.qom.Length) PropertyValue(javax.jcr.query.qom.PropertyValue) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 13 with PropertyValue

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

the class OperandEvaluator method getLengthValues.

/**
     * Returns the values of the given value length operand for the given node.
     *
     * @see #getProperty(PropertyValue, Node)
     * @param operand value length operand
     * @param node node
     * @return values of the operand for the given node
     * @throws RepositoryException if the operand can't be evaluated
     */
private Value[] getLengthValues(Length operand, Node n) throws RepositoryException {
    Property property = getProperty(operand.getPropertyValue(), n);
    if (property == null) {
        return new Value[0];
    }
    if (property.isMultiple()) {
        long[] lengths = property.getLengths();
        Value[] values = new Value[lengths.length];
        for (int i = 0; i < lengths.length; i++) {
            values[i] = factory.createValue(lengths[i]);
        }
        return values;
    }
    long length = property.getLength();
    return new Value[] { factory.createValue(length) };
}
Also used : Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) BindVariableValue(javax.jcr.query.qom.BindVariableValue) Property(javax.jcr.Property)

Example 14 with PropertyValue

use of javax.jcr.query.qom.PropertyValue 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 15 with PropertyValue

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

PropertyValue (javax.jcr.query.qom.PropertyValue)26 Ordering (javax.jcr.query.qom.Ordering)9 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)8 Test (org.junit.Test)8 Length (javax.jcr.query.qom.Length)5 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)5 Selector (javax.jcr.query.qom.Selector)5 BindVariableValue (javax.jcr.query.qom.BindVariableValue)4 Constraint (javax.jcr.query.qom.Constraint)4 PropertyExistence (javax.jcr.query.qom.PropertyExistence)4 NodeType (javax.jcr.nodetype.NodeType)3 Column (javax.jcr.query.qom.Column)3 LowerCase (javax.jcr.query.qom.LowerCase)3 UpperCase (javax.jcr.query.qom.UpperCase)3 RepositoryException (javax.jcr.RepositoryException)2 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)2 Value (javax.jcr.Value)2 Comparison (javax.jcr.query.qom.Comparison)2 NodeLocalName (javax.jcr.query.qom.NodeLocalName)2 NodeName (javax.jcr.query.qom.NodeName)2