Search in sources :

Example 1 with PropertyValue

use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.

the class FilterTest method propertyRestriction.

@Test
public void propertyRestriction() {
    PropertyValue one = PropertyValues.newString("1");
    PropertyValue two = PropertyValues.newString("2");
    FilterImpl f = FilterImpl.newTestInstance();
    assertTrue(null == f.getPropertyRestriction("x"));
    f.restrictProperty("x", Operator.LESS_OR_EQUAL, two);
    assertEquals("Filter(, path=*, property=[x=[..2]]])", f.toString());
    f.restrictProperty("x", Operator.GREATER_OR_EQUAL, one);
    assertEquals("Filter(, path=*, property=[x=[..2], [1..]])", f.toString());
    // no change, as the same restrictions already were added
    f.restrictProperty("x", Operator.LESS_OR_EQUAL, two);
    assertEquals("Filter(, path=*, property=[x=[..2], [1..]])", f.toString());
    f.restrictProperty("x", Operator.GREATER_OR_EQUAL, one);
    assertEquals("Filter(, path=*, property=[x=[..2], [1..]])", f.toString());
    f.restrictProperty("x", Operator.GREATER_THAN, one);
    assertEquals("Filter(, path=*, property=[x=[..2], [1.., (1..]])", f.toString());
    f.restrictProperty("x", Operator.LESS_THAN, two);
    assertEquals("Filter(, path=*, property=[x=[..2], [1.., (1.., ..2)]])", f.toString());
    // TODO could replace / remove the old range conditions,
    // if there is an overlap
    f.restrictProperty("x", Operator.EQUAL, two);
    assertEquals("Filter(, path=*, property=[x=[..2], [1.., (1.., ..2), 2]])", f.toString());
    f = FilterImpl.newTestInstance();
    f.restrictProperty("x", Operator.EQUAL, one);
    assertEquals("Filter(, path=*, property=[x=[1]])", f.toString());
    f.restrictProperty("x", Operator.EQUAL, one);
    assertEquals("Filter(, path=*, property=[x=[1]])", f.toString());
    // TODO could replace / remove the old range conditions,
    // if there is an overlap
    f.restrictProperty("x", Operator.GREATER_OR_EQUAL, one);
    assertEquals("Filter(, path=*, property=[x=[1, [1..]])", f.toString());
    f.restrictProperty("x", Operator.LESS_OR_EQUAL, one);
    assertEquals("Filter(, path=*, property=[x=[1, [1.., ..1]]])", f.toString());
    // TODO could replace / remove the old range conditions,
    // if there is an overlap
    f.restrictProperty("x", Operator.GREATER_THAN, one);
    assertEquals("Filter(, path=*, property=[x=[1, [1.., ..1], (1..]])", f.toString());
    f = FilterImpl.newTestInstance();
    f.restrictProperty("x", Operator.EQUAL, one);
    assertEquals("Filter(, path=*, property=[x=[1]])", f.toString());
    // TODO could replace / remove the old range conditions,
    // if there is an overlap
    f.restrictProperty("x", Operator.LESS_THAN, one);
    assertEquals("Filter(, path=*, property=[x=[1, ..1)]])", f.toString());
    f = FilterImpl.newTestInstance();
    f.restrictProperty("x", Operator.NOT_EQUAL, null);
    assertEquals("Filter(, path=*, property=[x=[is not null]])", f.toString());
    f.restrictProperty("x", Operator.LESS_THAN, one);
    assertEquals("Filter(, path=*, property=[x=[is not null, ..1)]])", f.toString());
    // this should replace the range with an equality
    // (which is faster, and correct even when using multi-valued properties)
    f.restrictProperty("x", Operator.EQUAL, two);
    assertEquals("Filter(, path=*, property=[x=[is not null, ..1), 2]])", f.toString());
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) Test(org.junit.Test)

Example 2 with PropertyValue

use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.

the class AbstractQueryTest method readRow.

protected static String readRow(ResultRow row, boolean pathOnly) {
    if (pathOnly) {
        return row.getValue(QueryImpl.JCR_PATH).getValue(Type.STRING);
    }
    StringBuilder buff = new StringBuilder();
    PropertyValue[] values = row.getValues();
    for (int i = 0; i < values.length; i++) {
        if (i > 0) {
            buff.append(", ");
        }
        PropertyValue v = values[i];
        if (v == null) {
            buff.append("null");
        } else if (v.isArray()) {
            buff.append('[');
            for (int j = 0; j < v.count(); j++) {
                buff.append(v.getValue(Type.STRING, j));
                if (j > 0) {
                    buff.append(", ");
                }
            }
            buff.append(']');
        } else {
            buff.append(v.getValue(Type.STRING));
        }
    }
    return buff.toString();
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Example 3 with PropertyValue

use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.

the class IdentifierManager method resolveUUID.

private String resolveUUID(PropertyValue uuid) {
    try {
        Map<String, PropertyValue> bindings = Collections.singletonMap("id", uuid);
        Result result = root.getQueryEngine().executeQuery("SELECT * FROM [nt:base] WHERE [jcr:uuid] = $id" + QueryEngine.INTERNAL_SQL2_QUERY, Query.JCR_SQL2, bindings, NO_MAPPINGS);
        String path = null;
        for (ResultRow rr : result.getRows()) {
            if (path != null) {
                log.error("multiple results for identifier lookup: " + path + " vs. " + rr.getPath());
                return null;
            } else {
                path = rr.getPath();
            }
        }
        return path;
    } catch (ParseException ex) {
        log.error("query failed", ex);
        return null;
    }
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) ParseException(java.text.ParseException) Result(org.apache.jackrabbit.oak.api.Result)

Example 4 with PropertyValue

use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.

the class NodeCounterIndexTest method executeXPathQuery.

protected String executeXPathQuery(String statement) throws ParseException {
    Result result = qe.executeQuery(statement, "xpath", null, NO_MAPPINGS);
    StringBuilder buff = new StringBuilder();
    for (ResultRow row : result.getRows()) {
        for (PropertyValue v : row.getValues()) {
            buff.append(v);
        }
    }
    return buff.toString();
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) Result(org.apache.jackrabbit.oak.api.Result)

Example 5 with PropertyValue

use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.

the class QueryImpl method currentRow.

ResultRowImpl currentRow() {
    int selectorCount = selectors.size();
    Tree[] trees = new Tree[selectorCount];
    for (int i = 0; i < selectorCount; i++) {
        SelectorImpl s = selectors.get(i);
        trees[i] = s.currentTree();
    }
    int columnCount = columns.length;
    PropertyValue[] values = new PropertyValue[columnCount];
    for (int i = 0; i < columnCount; i++) {
        ColumnImpl c = columns[i];
        values[i] = c.currentProperty();
    }
    PropertyValue[] orderValues;
    if (orderings == null) {
        orderValues = null;
    } else {
        int size = orderings.length;
        orderValues = new PropertyValue[size];
        for (int i = 0; i < size; i++) {
            orderValues[i] = orderings[i].getOperand().currentProperty();
        }
    }
    return new ResultRowImpl(this, trees, values, distinctColumns, orderValues);
}
Also used : SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) Tree(org.apache.jackrabbit.oak.api.Tree) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) ColumnImpl(org.apache.jackrabbit.oak.query.ast.ColumnImpl)

Aggregations

PropertyValue (org.apache.jackrabbit.oak.api.PropertyValue)57 Test (org.junit.Test)28 ResultRow (org.apache.jackrabbit.oak.api.ResultRow)26 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)24 Tree (org.apache.jackrabbit.oak.api.Tree)5 ParseException (java.text.ParseException)4 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)4 ArrayList (java.util.ArrayList)3 Result (org.apache.jackrabbit.oak.api.Result)3 Date (java.util.Date)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 LiteralImpl (org.apache.jackrabbit.oak.query.ast.LiteralImpl)2 StaticOperandImpl (org.apache.jackrabbit.oak.query.ast.StaticOperandImpl)2 FulltextQueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex.FulltextQueryIndex)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 BigDecimal (java.math.BigDecimal)1 Calendar (java.util.Calendar)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1