Search in sources :

Example 6 with PropertyValue

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

the class ResultRowImpl method getValue.

@Override
public PropertyValue getValue(String columnName) {
    int index = query.getColumnIndex(columnName);
    if (index >= 0) {
        return values[index];
    }
    if (JcrConstants.JCR_PATH.equals(columnName)) {
        return PropertyValues.newString(getPath());
    }
    // even though the query doesn't contain that column
    if (columnName.startsWith(QueryImpl.REP_EXCERPT)) {
        int columnIndex = query.getColumnIndex(QueryImpl.REP_EXCERPT);
        PropertyValue indexExcerptValue = null;
        if (columnIndex >= 0) {
            indexExcerptValue = values[columnIndex];
            if (indexExcerptValue != null) {
                if (QueryImpl.REP_EXCERPT.equals(columnName) || SimpleExcerptProvider.REP_EXCERPT_FN.equals(columnName)) {
                    return SimpleExcerptProvider.getExcerpt(indexExcerptValue);
                }
            }
        }
        return getFallbackExcerpt(columnName, indexExcerptValue);
    }
    throw new IllegalArgumentException("Column not found: " + columnName);
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Example 7 with PropertyValue

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

the class ResultRowImpl method getComparator.

public static Comparator<ResultRowImpl> getComparator(final OrderingImpl[] orderings) {
    if (orderings == null) {
        return null;
    }
    return new Comparator<ResultRowImpl>() {

        @Override
        public int compare(ResultRowImpl o1, ResultRowImpl o2) {
            PropertyValue[] orderValues = o1.getOrderValues();
            PropertyValue[] orderValues2 = o2.getOrderValues();
            int comp = 0;
            for (int i = 0, size = orderings.length; i < size; i++) {
                PropertyValue a = orderValues[i];
                PropertyValue b = orderValues2[i];
                if (a == null || b == null) {
                    if (a == b) {
                        comp = 0;
                    } else if (a == null) {
                        // TODO order by: nulls first (it looks like), or
                        // low?
                        comp = -1;
                    } else {
                        comp = 1;
                    }
                } else {
                    comp = a.compareTo(b);
                }
                if (comp != 0) {
                    if (orderings[i].isDescending()) {
                        comp = -comp;
                    }
                    break;
                }
            }
            return comp;
        }
    };
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) Comparator(java.util.Comparator)

Example 8 with PropertyValue

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

the class SQL2Parser method readString.

private PropertyValue readString() throws ParseException {
    if (currentTokenType != VALUE) {
        throw getSyntaxError("string value");
    }
    PropertyValue value = currentValue;
    read();
    return value;
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Example 9 with PropertyValue

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

the class ComparisonImpl method evaluate.

@Override
public boolean evaluate() {
    // JCR 2.0 spec, 6.7.16 Comparison:
    // "operand1 may evaluate to an array of values"
    PropertyValue p1 = operand1.currentProperty();
    if (p1 == null) {
        return false;
    }
    PropertyValue p2 = operand2.currentValue();
    if (p2 == null) {
        // even for "null <> 'x'" (same as in SQL) 
        return false;
    }
    // "the value of operand2 is converted to the
    // property type of the value of operand1" if possible
    p2 = convertValueToType(p2, p1);
    // if not possible, convert to the same type
    if (p1.getType().tag() != p2.getType().tag()) {
        // conversion failed: convert both to binary or string
        int targetType = getCommonType(p1, p2);
        p1 = convertToType(p1, targetType);
        p2 = convertToType(p2, targetType);
    }
    if (p1.isArray()) {
        // JCR 2.0 spec, 6.7.16 Comparison:
        // "... constraint is satisfied as a whole if the comparison
        // against any element of the array is satisfied."
        Type<?> base = p1.getType().getBaseType();
        for (int i = 0; i < p1.count(); i++) {
            PropertyState value = PropertyStates.createProperty("value", p1.getValue(base, i), base);
            if (operator.evaluate(PropertyValues.create(value), p2)) {
                return true;
            }
        }
        return false;
    } else {
        return operator.evaluate(p1, p2);
    }
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 10 with PropertyValue

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

the class SimilarImpl method restrict.

@Override
public void restrict(FilterImpl f) {
    if (f.getSelector().equals(selector)) {
        PropertyValue p = pathExpression.currentValue();
        String path = p.getValue(Type.STRING);
        String query = MORE_LIKE_THIS_PREFIX + path;
        PropertyValue v = PropertyValues.newString(query);
        f.restrictProperty(NativeFunctionImpl.NATIVE_PREFIX + NATIVE_LUCENE_LANGUAGE, Operator.EQUAL, v);
    }
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

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