Search in sources :

Example 51 with PropertyValue

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

the class FullTextSearchImpl method evaluate.

@Override
public boolean evaluate() {
    // such as index aggregation
    if (selector.getIndex() instanceof FulltextQueryIndex) {
        // aggregation bits
        if (relativePath == null && propertyName != null) {
            return enforcePropertyExistence(propertyName, selector);
        }
        return true;
    }
    // OAK-2050
    if (!query.getSettings().getFullTextComparisonWithoutIndex()) {
        return false;
    }
    StringBuilder buff = new StringBuilder();
    if (relativePath == null && propertyName != null) {
        PropertyValue p = selector.currentProperty(propertyName);
        if (p == null) {
            return false;
        }
        appendString(buff, p);
    } else {
        String path = selector.currentPath();
        if (!PathUtils.denotesRoot(path)) {
            appendString(buff, PropertyValues.newString(PathUtils.getName(path)));
        }
        if (relativePath != null) {
            String rp = normalizePath(relativePath);
            path = PathUtils.concat(path, rp);
        }
        Tree tree = selector.getTree(path);
        if (tree == null || !tree.exists()) {
            return false;
        }
        if (propertyName != null) {
            String pn = normalizePropertyName(propertyName);
            PropertyState p = tree.getProperty(pn);
            if (p == null) {
                return false;
            }
            appendString(buff, PropertyValues.create(p));
        } else {
            for (PropertyState p : tree.getProperties()) {
                appendString(buff, PropertyValues.create(p));
            }
        }
    }
    return getFullTextConstraint(selector).evaluate(buff.toString());
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) Tree(org.apache.jackrabbit.oak.api.Tree) FulltextQueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex.FulltextQueryIndex) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 52 with PropertyValue

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

the class InImpl 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;
    }
    for (StaticOperandImpl s : operand2) {
        PropertyValue p2 = s.currentValue();
        if (p2 == null) {
            // if the property doesn't exist, the result is false
            continue;
        }
        // "the value of operand2 is converted to the
        // property type of the value of operand1"
        p2 = convertValueToType(p2, p1);
        if (PropertyValues.match(p1, p2)) {
            return true;
        }
    }
    return false;
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Example 53 with PropertyValue

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

the class ResultRowImpl method hashCodeOfValues.

private int hashCodeOfValues() {
    int result = 1;
    for (int i = 0; i < values.length; i++) {
        if (distinctValues == null || distinctValues[i]) {
            PropertyValue v = values[i];
            result = 31 * result + (v == null ? 0 : v.hashCode());
        }
    }
    return result;
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Example 54 with PropertyValue

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

the class SQL2Parser method parseCastAs.

private PropertyValue parseCastAs(PropertyValue value) throws ParseException {
    if (currentTokenQuoted) {
        throw getSyntaxError("data type (STRING|BINARY|...)");
    }
    int propertyType = getPropertyTypeFromName(currentToken);
    read();
    PropertyValue v = PropertyValues.convert(value, propertyType, null);
    if (v == null) {
        throw getSyntaxError("data type (STRING|BINARY|...)");
    }
    return v;
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Example 55 with PropertyValue

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

the class SQL2Parser method parseCondition.

private ConstraintImpl parseCondition(DynamicOperandImpl left) throws ParseException {
    ConstraintImpl c;
    if (readIf("=")) {
        c = factory.comparison(left, Operator.EQUAL, parseStaticOperand());
    } else if (readIf("<>")) {
        c = factory.comparison(left, Operator.NOT_EQUAL, parseStaticOperand());
    } else if (readIf("<")) {
        c = factory.comparison(left, Operator.LESS_THAN, parseStaticOperand());
    } else if (readIf(">")) {
        c = factory.comparison(left, Operator.GREATER_THAN, parseStaticOperand());
    } else if (readIf("<=")) {
        c = factory.comparison(left, Operator.LESS_OR_EQUAL, parseStaticOperand());
    } else if (readIf(">=")) {
        c = factory.comparison(left, Operator.GREATER_OR_EQUAL, parseStaticOperand());
    } else if (readIf("LIKE")) {
        c = factory.comparison(left, Operator.LIKE, parseStaticOperand());
        if (supportSQL1) {
            if (readIf("ESCAPE")) {
                StaticOperandImpl esc = parseStaticOperand();
                if (!(esc instanceof LiteralImpl)) {
                    throw getSyntaxError("only ESCAPE '\' is supported");
                }
                PropertyValue v = ((LiteralImpl) esc).getLiteralValue();
                if (!v.getValue(Type.STRING).equals("\\")) {
                    throw getSyntaxError("only ESCAPE '\' is supported");
                }
            }
        }
    } else if (readIf("IN")) {
        read("(");
        ArrayList<StaticOperandImpl> list = new ArrayList<StaticOperandImpl>();
        do {
            StaticOperandImpl x = parseStaticOperand();
            list.add(x);
        } while (readIf(","));
        read(")");
        c = factory.in(left, list);
    } else if (readIf("IS")) {
        boolean not = readIf("NOT");
        read("NULL");
        if (!(left instanceof PropertyValueImpl)) {
            throw getSyntaxError("propertyName (NOT NULL is only supported for properties)");
        }
        PropertyValueImpl p = (PropertyValueImpl) left;
        if (not) {
            c = getPropertyExistence(p);
        } else {
            c = getPropertyInexistence(p);
        }
    } else if (readIf("NOT")) {
        if (readIf("IS")) {
            read("NULL");
            if (!(left instanceof PropertyValueImpl)) {
                throw new ParseException("Only property values can be tested for NOT IS NULL; got: " + left.getClass().getName(), parseIndex);
            }
            PropertyValueImpl pv = (PropertyValueImpl) left;
            c = getPropertyExistence(pv);
        } else {
            read("LIKE");
            c = factory.comparison(left, Operator.LIKE, parseStaticOperand());
            c = factory.not(c);
        }
    } else {
        throw getSyntaxError();
    }
    return c;
}
Also used : LiteralImpl(org.apache.jackrabbit.oak.query.ast.LiteralImpl) ConstraintImpl(org.apache.jackrabbit.oak.query.ast.ConstraintImpl) StaticOperandImpl(org.apache.jackrabbit.oak.query.ast.StaticOperandImpl) ArrayList(java.util.ArrayList) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) ParseException(java.text.ParseException) PropertyValueImpl(org.apache.jackrabbit.oak.query.ast.PropertyValueImpl)

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